liveBook · Manning

Workflow definition

As explained in Road to Kubernetes

A GitHub Actions workflow is a YAML-defined automation procedure composed of jobs and steps that GitHub Actions executes in response to configured events.

A GitHub Actions workflow definition is a YAML file that tells GitHub when to run an automation procedure and what to do. Put it in `.github/workflows/`, commit it, and push it with your project. A workflow can start on a push or when you choose Run workflow in GitHub. section 4.1.1

A small workflow has four parts:

  • `name` labels the workflow. section 4.1.1
  • `on` chooses events, such as `push` or `workflow_dispatch` for a manual run. section 4.1.1
  • `jobs` groups the work; `runs-on` selects a machine for a job. section 4.1.1
  • `steps` perform the work. A step can use an existing action, such as checkout, or run a command. section 4.1.1
Listing 4.2 Hello World with GitHub Actions
name: Hello World
on:
  workflow_dispatch:
  push:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Hello World
      run: echo "Hello World"

The Hello World workflow shows all four parts together: it checks out the repository, then runs `echo "Hello World"` on an Ubuntu runner. section 4.1.1

The same structure can handle a deployment task. For a remote server, steps can prepare an SSH key from a GitHub Actions secret and install NGINX over SSH. Keep the key and server address in stored secrets rather than committing their values to the repository. section 4.1.5

For larger tasks, the workflow can set up Python and Ansible, create an inventory, and run an Ansible playbook. The workflow arranges when and where those commands run; the playbook describes the desired state of the remote host. section 4.2.1

From build to production deployment

A container workflow can check out a Python or Node.js application, log in to Docker Hub, build an image tagged `latest` and with the commit SHA, then push both tags. Extend that procedure to prepare a production virtual machine, copy a Compose file and environment file over SSH, pull the updated image, and run `docker compose up -d`. The repeated steps make the workflow reusable; repository secrets supply project-specific credentials. section 6.1.2 section 7.3.3

How Road to Kubernetes covers it

How deep it goes
Builds a complete YAML workflow, then elaborates its jobs, steps, secrets, and deployment commands through successive runnable configurations.
Examples
Uses a Hello World YAML file, remote NGINX installation, an Ansible runner, and container build-and-deploy workflows.
What it assumes
Assumes a GitHub repository and introduces YAML workflow structure before adding SSH keys, secrets, and deployment tools.
What you can do after
Build it from scratch to trigger jobs, run commands, use stored secrets, and automate a container deployment.
How it connects
Links GitHub Actions triggers and secrets with SSH, Ansible playbooks, Docker Hub, and Docker Compose.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Road to Kubernetes. The section links point to the parts of the book it draws on.