DEV Community

Cover image for Containerizing and Deploying a Microservice App with Docker and CI/CD
anitaalicloud
anitaalicloud

Posted on

Containerizing and Deploying a Microservice App with Docker and CI/CD

Introduction

In this project, I worked on a microservice based application and focused on making it production ready using Docker and CI/CD pipelines.

Instead of just running the application locally, the goal was to:

  • Understand how multiple services interact
  • Package them using Docker
  • Orchestrate them with Docker Compose
  • Automate testing, security checks, and deployment using GitHub Actions

This article explains how to run, test, and deploy the project from scratch.


Project Repository

GitHub Repo: https://github.com/AnitaAliCloud/hng14-stage2-devops


System Architecture

The system consists of four main components:

  • Frontend (Node.js) — user interface for submitting jobs
  • Backend API (FastAPI) — handles job creation and status
  • Worker Service (Python) — processes jobs asynchronously
  • Redis — message broker between services

Flow Diagram:

Frontend → API → Redis Queue → Worker → Redis → API → Frontend
Enter fullscreen mode Exit fullscreen mode

Prerequisites

Before running this project, ensure you have:


How to Run the Project Locally

1. Clone the repository

git clone https://github.com/YOUR_USERNAME/YOUR_REPO.git
cd YOUR_REPO
Enter fullscreen mode Exit fullscreen mode

2. Set up environment variables

Create a .env file:

cp .env.example .env
Enter fullscreen mode Exit fullscreen mode

Update values if needed.


3. Start all services with Docker Compose

docker-compose up --build
Enter fullscreen mode Exit fullscreen mode

4. Access the application


Running Health Checks

Each service includes a health endpoint:

  • /health → API health status
  • Docker health checks ensure services restart automatically if unhealthy

CI/CD Pipeline (GitHub Actions)

The project includes an automated pipeline:

Pipeline stages:

  • Lint (flake8, eslint, hadolint)
  • Test (unit tests with pytest)
  • Build Docker images
  • Security scan (Trivy)
  • Integration tests
  • Deployment

CI/CD Workflow Screenshot:


Running Tests Locally

To run tests manually:

pytest
Enter fullscreen mode Exit fullscreen mode

For coverage report:

pytest --cov=app
Enter fullscreen mode Exit fullscreen mode

Security Checks

The pipeline includes:

  • Docker image scanning with Trivy
  • Failing builds on critical vulnerabilities
  • No secrets stored in images or repository

Troubleshooting

Containers not starting?

Check logs:

docker-compose logs -f
Enter fullscreen mode Exit fullscreen mode

Port already in use?

sudo lsof -i :3000
Enter fullscreen mode Exit fullscreen mode

Key Learnings

This project helped reinforce:

  • How microservices communicate in real systems
  • Why containerization improves reliability
  • Importance of CI/CD automation
  • How infrastructure impacts application behavior

Conclusion

This project demonstrates how a multi-service application can be containerized, tested, and deployed in a structured and repeatable way.

Beyond just writing code, the focus was on building a system that can be reliably shipped and maintained.


Useful Links

Top comments (0)