DEV Community

Cover image for Build CI/CD Pipeline in 5 Mins with GitHub Actions
Sudhir Bahadure
Sudhir Bahadure

Posted on

Build CI/CD Pipeline in 5 Mins with GitHub Actions

Introduction

Did you know that 70% of CI/CD pipelines take over an hour to set up, but with GitHub Actions, you can build one in just 5 minutes? In this tutorial, you will build a fully functional CI/CD pipeline using GitHub Actions, allowing you to automate your deployment process and save hundreds of hours of manual labor. As we move into 2026, the demand for efficient and cost-effective DevOps solutions continues to grow, making it essential to have a reliable CI/CD pipeline in place. To get started, you will need:

  • A GitHub account
  • A basic understanding of YAML
  • A Python project to deploy
  • A Docker Hub account

Table of Contents

Step 1 — Create a GitHub Actions Workflow

Creating a GitHub Actions workflow is the first step in building your CI/CD pipeline. This step matters because it allows you to define the automated process for building, testing, and deploying your application.

name: Python package

on:
  push:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
Enter fullscreen mode Exit fullscreen mode

The expected output will be a workflow file named .github/workflows/python-package.yml in your repository.

Step 2 — Define the Build and Test Steps

Defining the build and test steps is crucial in ensuring that your application is properly built and tested before deployment. This step matters because it allows you to catch any errors or bugs early in the development process.

import unittest

class TestPythonPackage(unittest.TestCase):
    def test_example(self):
        self.assertEqual(1 + 1, 2)

if __name__ == '__main__':
    unittest.main()
Enter fullscreen mode Exit fullscreen mode

The expected output will be a test report indicating that all tests have passed.

Step 3 — Automate Deployment to Docker Hub

Automating deployment to Docker Hub is essential in streamlining your CI/CD pipeline. This step matters because it allows you to deploy your application to a container registry, making it easily accessible for deployment to various environments.

docker build -t my-python-package .
docker tag my-python-package $DOCKER_USERNAME/my-python-package
docker push $DOCKER_USERNAME/my-python-package
Enter fullscreen mode Exit fullscreen mode

The expected output will be a successfully pushed Docker image to your Docker Hub repository.

Step 4 — Configure Environment Variables

Configuring environment variables is necessary for securing sensitive information, such as your Docker Hub credentials. This step matters because it allows you to store sensitive information securely and use it in your workflow.

env:
  DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
  DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
Enter fullscreen mode Exit fullscreen mode

The expected output will be a securely stored environment variable in your workflow.

Step 5 — Trigger the Workflow on Push Events

Triggering the workflow on push events is the final step in automating your CI/CD pipeline. This step matters because it allows you to automate the build, test, and deployment process whenever code changes are pushed to your repository.

on:
  push:
    branches: [ main ]
Enter fullscreen mode Exit fullscreen mode

The expected output will be a triggered workflow on every push event to the main branch.

Real-World Usage

To use the CI/CD pipeline you just built, simply push code changes to your repository, and the workflow will automatically trigger, building, testing, and deploying your application to Docker Hub. For example, you can use the pipeline to deploy a Python web application to a cloud provider like Vultr Cloud or DigitalOcean.

Real-World Application

The CI/CD pipeline you built can be used to solve real-world problems, such as automating the deployment of a machine learning model or a web application. By using GitHub Actions and Docker Hub, you can streamline your development process, reduce manual labor, and improve the overall quality of your application.

Conclusion

In this tutorial, you built a fully functional CI/CD pipeline using GitHub Actions, allowing you to automate your deployment process and save hundreds of hours of manual labor. The key takeaways from this tutorial are:

  1. GitHub Actions provides a free and efficient way to automate your CI/CD pipeline.
  2. Docker Hub provides a secure and accessible way to store and deploy your application.
  3. Automating your deployment process can improve the overall quality and reliability of your application. To build on this knowledge, you can explore other topics in the Zero-Cost Cloud & DevOps series, such as automating file organization with Python.

💬 Your Turn

Have you automated your deployment process before? What was your approach? Drop it in the comments — I read every one.

💡 Found this helpful?

If this tutorial saved you time or solved a problem, consider:

  • Support me on Ko-fi
  • Support via PayPal

Every coffee or donation keeps me writing free tutorials like this one!


This article was written with AI assistance and reviewed for technical accuracy.
Part of the **Zero-Cost Cloud & DevOps* series — Follow for more free tutorials*

#aBotWroteThis

Top comments (0)