Skip to main content

Overview

CI/CD stands for:
  • CI: Continuous Integration
  • CD: Continuous Delivery / Continuous Deployment
GitHub Actions automates software development tasks such as:
  • Running tests
  • Building Docker images
  • Checking code
  • Publishing Docker images
  • Deploying applications

Basic CI/CD workflow


1. GitHub Actions

GitHub Actions is a CI/CD automation platform integrated with GitHub repositories. A workflow is defined using a YAML file. The standard location is:
Example project structure:

2. Workflow

A workflow is an automated process containing one or more jobs. Example:
name defines the name displayed in the GitHub Actions interface.

3. Workflow Trigger

This workflow runs when:
  • Code is pushed to main
  • A pull request targets main

Example


4. Permissions

contents: read

Allows the workflow to read repository contents.

packages: write

Allows the workflow to push packages/images to GitHub Container Registry (GHCR).

5. Jobs

A workflow can contain multiple jobs. Example:
Here there are two jobs:

6. Runner

A runner is the machine that executes the workflow. Common runners include:
For Docker-based applications, Ubuntu runners are commonly used.

7. Checkout Code

This downloads the repository code into the GitHub Actions runner. Without this step, the runner does not have access to the repository files.

8. Setup Python

This installs/configures Python 3.11 in the runner. Important:
Correct action name:
Not:

9. Install Dependencies

Because requirements.txt is inside the Day 45 folder:
The path is relative to the repository root. Repository:
File:
Therefore:
is the correct path.

10. Run Unit Tests

This executes the Python unit tests. Example test_app.py:
If the tests pass:
the next job can execute.

11. Job Dependencies

The build job can depend on the test job:
This means:
If the tests fail:
This prevents a broken application from being packaged and pushed.

12. Login to GHCR

GHCR stands for: GitHub Container Registry The workflow can authenticate using the automatically provided GITHUB_TOKEN.

Important values

GitHub Container Registry.
The GitHub user that triggered the workflow.
Automatically provided authentication token for the workflow.

13. Build Docker Image

This action builds and optionally pushes a Docker image. The Docker context is:
This tells Docker where the Dockerfile and application files are located.

14. Push Docker Image

This tells Docker to push the image to the configured registry. Without it:
the image is only built.

15. Docker Image Tag

Example:
The general format is:
Example:
Where:

16. Docker Repository Names Must Be Lowercase

An error occurred with:
Docker returned:
The problem was:
contains uppercase letters. Correct:
Therefore:

Rule

Use lowercase names for Docker image repositories:

17. Complete ci.yml


18. Example app.py


19. Example requirements.txt


20. Example Dockerfile


21. Running the Workflow

After modifying the workflow:
GitHub automatically starts the workflow. Check:

22. Expected GitHub Actions Result

The final Docker image will be available in:

23. Important GitHub Actions Concepts


24. CI/CD Pipeline Summary

Key learning points

  • GitHub Actions automates CI/CD workflows.
  • YAML files define workflows.
  • actions/checkout retrieves repository code.
  • actions/setup-python configures Python.
  • pytest runs automated tests.
  • needs controls job execution order.
  • Docker can be built directly inside GitHub Actions.
  • GHCR can store Docker images.
  • GITHUB_TOKEN can authenticate the workflow.
  • Docker image repository names should use lowercase.
  • CI should run before the Docker image is built and published.