DEV Community

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

Posted on

Build CI/CD in 10 Mins with GitHub Actions

Introduction

Did you know that 70% of developers spend more than 2 hours a day on manual deployment tasks, but you can automate it all in just 10 minutes with GitHub Actions? In this article, we will build a Continuous Integration and Continuous Deployment (CI/CD) pipeline using GitHub Actions, allowing you to automate your deployment process and save valuable time. As we move into 2026, automation is becoming increasingly important for developers, and having a solid understanding of CI/CD pipelines is crucial for any development team. To get started, you will need:

  • A GitHub account
  • A basic understanding of Python and YAML
  • A repository set up on GitHub
  • Docker installed on your machine

Table of Contents

  1. Introduction
  2. Step 1 — Create a New Repository
  3. Step 2 — Create a Dockerfile
  4. Step 3 — Create a GitHub Actions Workflow
  5. Step 4 — Configure the Workflow
  6. Step 5 — Test the Workflow
  7. Real-World Usage
  8. Real-World Application
  9. Conclusion
  10. 💬 Your Turn

Step 1 — Create a New Repository

Creating a new repository is the first step in setting up our CI/CD pipeline. This will give us a central location to store our code and track changes.

# Create a new directory for our project
mkdir my-project

# Navigate into the new directory
cd my-project

# Initialize a new Git repository
git init

# Create a new file called README.md
touch README.md

# Add the new file to the repository
git add README.md

# Commit the changes
git commit -m "Initial commit"

# Create a new repository on GitHub and link it to our local repository
git remote add origin https://github.com/your-username/my-project.git

# Push the changes to the remote repository
git push -u origin master
Enter fullscreen mode Exit fullscreen mode

The expected output will be a new repository on GitHub with our initial commit.

Step 2 — Create a Dockerfile

A Dockerfile is a text file that contains instructions for building a Docker image. This image will be used to deploy our application.

# Use the official Python image as a base
FROM python:3.9-slim

# Set the working directory to /app
WORKDIR /app

# Copy the requirements file
COPY requirements.txt .

# Install the dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the application code
COPY . .

# Expose the port
EXPOSE 8000

# Run the command to start the application
CMD ["python", "app.py"]
Enter fullscreen mode Exit fullscreen mode

This Dockerfile will create a new image with our application code and dependencies.

Step 3 — Create a GitHub Actions Workflow

A GitHub Actions workflow is a set of instructions that define the build, test, and deployment process for our application.

# Name of the workflow
name: Build and Deploy

# Trigger the workflow on push events to the master branch
on:
  push:
    branches:
      - master

# Define the jobs in the workflow
jobs:
  build-and-deploy:
    # Run the job on an Ubuntu environment
    runs-on: ubuntu-latest

    # Steps in the job
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Login to DockerHub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Build and push image
        uses: docker/build-push-action@v2
        with:
          context: .
          push: true
          tags: ${{ secrets.DOCKER_USERNAME }}/my-project:latest
Enter fullscreen mode Exit fullscreen mode

This workflow will build and push our Docker image to DockerHub.

Step 4 — Configure the Workflow

To configure the workflow, we need to store our DockerHub credentials as secrets in our GitHub repository. We can do this by going to the repository settings and adding the credentials as secrets.

Step 5 — Test the Workflow

To test the workflow, we can push a new commit to the repository and verify that the workflow runs successfully. We can check the workflow run by going to the Actions tab in our repository.

Real-World Usage

Our CI/CD pipeline is now set up and ready to use. We can use it to automate the deployment of our application to a cloud platform like Vultr Cloud or DigitalOcean. We can simply push a new commit to the repository, and the workflow will build and deploy our application automatically.

Real-World Application

This CI/CD pipeline can be used in a variety of real-world applications, such as deploying a web application or a microservice. It can also be used to automate the deployment of machine learning models or data science applications. By using a cloud platform like Vultr Cloud or DigitalOcean, we can easily scale our application and handle large amounts of traffic.

Conclusion

In this article, we built a CI/CD pipeline using GitHub Actions and Docker. The key takeaways from this article are:

  1. We can automate the deployment of our application using a CI/CD pipeline.
  2. GitHub Actions provides a simple and easy-to-use interface for defining workflows.
  3. Docker provides a lightweight and efficient way to deploy our application. To build on this, you can try creating a new workflow that deploys your application to a cloud platform like Vultr Cloud or DigitalOcean. Check out the next article in the Zero-Cost Cloud & DevOps series for more information on automating your deployment process.

💬 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)