Konstantinos Antoniou.

← Projects

Continuous Integration and Continuous Deployment with GitHub Actions

Overview

This project demonstrates my first steps into Continuous Integration and Continuous Deployment (CI/CD) using GitHub Actions.
I built and deployed a very simple Python Flask application, starting from a local development setup and then automating the entire process — from code push to container build and deployment — through GitHub Actions.

The goal of this project was to understand how CI/CD works in practice, learn how workflows are triggered, and automate repetitive deployment tasks. It marks my transition from manual Docker builds to a more streamlined, automated workflow.


Motivation

Before adopting GitHub Actions, every deployment was done manually — pushing images, restarting containers, and applying configurations by hand. As the number of services in my home lab grew, this approach became inefficient. I wanted a solution that would automatically build, test, and deploy applications each time I pushed new code to my repository.


Architecture

  • Version Control: GitHub repository containing application code and workflow definitions.
  • CI/CD Engine: GitHub Actions (using .github/workflows/deploy.yml).
  • Containerization: Docker for image packaging and version tagging.
  • Registry: Docker Hub for image storage.
  • Deployment Target: Kubernetes cluster (on Proxmox) or Docker host, depending on the service.
  • Secret Management: GitHub Secrets for credentials (Docker tokens, SSH keys, API tokens).

Pipeline Workflow

The pipeline triggers automatically when code is pushed to the master branch.

  1. Trigger: on push to master

    • Every time i push new code to master, this workflow starts.
      That keeps my container and cluster automatically synced with my master branch.
  2. Set environment variables

    • Here i preload credentials from my GitHub repository secrets.
      These credentials are used later for Docker Hub authentication.
      The advantage: they never appear in logs or my YAML directly.
  3. Checkout repository

    • This downloads my repository’s code into the self-hosted runner.
      Without this, there’d be no source files to build from (like my Dockerfile).
  4. Set up Docker Buildx

    • Buildx is Docker’s advanced builder that supports caching, multi-platform builds, and parallel layer building.
      This step initializes that environment so later builds are faster and more flexible.
  5. Authenticate to Docker Hub

    • This securely logs the runner into my Docker Hub account so it can push images.
      Without this, i’d hit “unauthorized” errors when trying to push.
  6. Build and push Docker image

    • This is the core build stage:

      • It builds my image using the specified context and Dockerfile.
      • It pushes the image to Docker Hub under two tags:
        • latest → always points to my most recent build.
        • ${{ github.sha }} → a unique tag tied to the commit ID, perfect for version tracking or rollback.

      The @v5 version of this action ensures modern Docker BuildKit features are available.

  7. Deploy to Kubernetes

    • Once the new image is built and published, this stage handles live deployment.
      • This is the sequence:

        1. Create namespace (if missing):
          Ensures the flask-demo namespace exists.
        2. Apply manifests:
          Deploys or updates Kubernetes objects (e.g., Deployment, Service, Ingress).
        3. Update the container image:
          Rolls out the new version of my app using the image tagged with the commit SHA.

        This gives me automated, versioned, rolling updates directly into my cluster — zero manual kubectl intervention.


Workflow File

name: CI/CD Pipeline

on:
  push:
    branches: [ "master" ]

env:
  DOCKER_USER: ${{ secrets.DOCKERHUB_USER }}
  DOCKER_PASS: ${{ secrets.DOCKERHUB_PASS }}

jobs:
  build-and-deploy:
    runs-on: [self-hosted]
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Log in to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USER }}
          password: ${{ secrets.DOCKERHUB_PASS }}

      - name: Build and push Docker image
        uses: docker/build-push-action@v5
        with:
          context: ./portfolio_app
          file: ./portfolio_app/Dockerfile
          push: true
          tags: |
            funmicra/flask-demo:${{ github.sha }}
            funmicra/flask-demo:latest

      - name: Deploy to Kubernetes
        run: |
          kubectl create namespase flask-demo || \
          kubectl set image deployment/flask-demo flask-demo=funmicra/flask-demo:${{ github.sha }} --namespace=flask-demo || \
          kubectl apply -f manifests/

Screenshot 1: Workflow File

Screenshot 2: Workflow File

Screenshot 3: Workflow File

Screenshot 4: Workflow File

Screenshot 5: Workflow File

Screenshot 6: Workflow File

Screenshot 7: Workflow File

On my browser:

http://192.0.2.71/

Screenshot 8: Workflow File

Screenshot 9: Workflow File


Key Benefits

  • Speed: Automatic deployment on each commit reduces release time to minutes.
  • Reliability: Eliminates manual errors during builds or deployments.
  • Traceability: Every deployment is tied to a Git commit and action log.
  • Scalability: Easily extendable to multiple applications or environments.

Challenges

  • Learning how GitHub Actions works:
    Understanding the structure of .yml workflow files and how jobs, steps, and triggers connect took some trial and error. I spent time testing small examples before building the full pipeline.
  • Docker image builds and permissions:
    At first, my builds failed because I hadn’t set up Docker authentication correctly in GitHub Secrets. I learned how to store credentials securely so my workflow could push images automatically.
  • Pipeline debugging:
    When something failed, the error logs from GitHub Actions weren’t always easy to understand. I learned to use set -x and echo inside scripts to print useful debug info.

Future Improvements

  • Add simple tests before deployment:
    Start by running basic checks — like docker build without errors or a simple script that prints “app started successfully.” This will help catch mistakes early.
  • Improve folder structure and workflow clarity:
    Organize my files better (Dockerfile, .github/workflows, src/) and use comments in the YAML file so it’s easier to understand what each step does.
  • Add notifications:
    Set up email or GitHub notifications so i will know when a build succeeds or fails. Later, this could evolve into Telegram alerts.
  • Deploy automatically to a test environment:
    Instead of deploying changes straight to production, I plan to create a dedicated dev branch that automatically deploys to my local test Docker host. This will let me safely experiment, test builds, and validate everything before merging into the main branch. Once the workflow runs smoothly and the app behaves as expected, I’ll extend the automation to handle production deployments with confidence.
  • Learn about GitHub Actions reusability:
    i will experiment with reusable workflows to avoid rewriting the same steps for every project. This will make my automation cleaner and more consistent.

Conclusion

Building this CI/CD pipeline taught me the basics of automating builds and deployments. I learned how GitHub Actions workflows are structured, how to trigger builds on code changes, and how to deploy a simple Flask application to a Docker host automatically.

Monitoring the pipeline helped me understand debugging workflows, handling errors, and using GitHub Secrets securely. This project gave me hands-on experience with CI/CD concepts in a safe, beginner-friendly environment.

The project is still in progress, and I plan to improve it by adding tests, enhancing deployment strategies, and eventually automating production updates. This pipeline represents an ongoing learning journey in DevOps automation.