Dynamic multi-service pipeline with GitLab CI, Docker containerization, and Kubernetes orchestration
This project implements a comprehensive CI/CD pipeline for a microservices architecture, featuring automated building, testing, security scanning, and multi-environment deployments. The pipeline handles multiple Python-based microservices with Docker containerization and Kubernetes orchestration, implementing industry best practices for DevOps automation.
GitLab CI → Docker Build → Test Suite → Security Scan → Container Registry → Kubernetes Deployment
JWT authentication, OAuth integration, session management, and rate limiting
User profile management, CRUD operations, and file upload handling
Stripe integration, transaction processing, and PCI compliance
Email/SMS notifications, webhook handlers, and message queuing
# .gitlab-ci.yml
stages:
- build
- test
- security
- publish
- deploy
- rollback
variables:
DOCKER_REGISTRY: registry.gitlab.com
DOCKER_DRIVER: overlay2
DOCKER_BUILDKIT: 1
KUBE_NAMESPACE: production
# Build stage with caching
build:auth-service:
stage: build
script:
- docker build --cache-from $LATEST_TAG
--tag $IMAGE_TAG
--build-arg BUILDKIT_INLINE_CACHE=1 .
- docker push $IMAGE_TAG
# Comprehensive testing
test:auth-service:
stage: test
script:
- pytest tests/unit -v --cov=app --cov-report=xml
- pytest tests/integration -v
coverage: '/TOTAL.*\s+(\d+%)$/'
# Security scanning
security-scan:
stage: security
script:
- trivy image --severity HIGH,CRITICAL $IMAGE_TAG
- safety check -r requirements.txt
- bandit -r app/ -f json
# Blue-Green Deployment
deploy-production:
stage: deploy
script:
- helm upgrade --install microservices-green charts/
--set global.image.tag=$CI_COMMIT_SHORT_SHA
--wait --timeout 10m
- kubectl patch service microservices
-p '{"spec":{"selector":{"deployment":"green"}}}'
# Optimized Dockerfile for Python microservices
FROM python:3.11-slim as builder
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY requirements.txt .
RUN pip install -r requirements.txt
FROM python:3.11-slim as runtime
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
WORKDIR /app
COPY . .
USER appuser
EXPOSE 8000
CMD ["gunicorn", "app.main:app", "--workers", "4",
"--worker-class", "uvicorn.workers.UvicornWorker"]
Organize microservices in a monorepo with shared configurations and independent service directories
Set up GitLab CI with multi-stage pipeline, environment variables, and secret management
Configure GitLab Container Registry for storing Docker images with proper tagging strategy
Connect GitLab to Kubernetes cluster and configure RBAC for automated deployments
Deploy Prometheus, Grafana, and Jaeger for comprehensive observability
Implement security scanning, SBOM generation, and compliance checks
# Clone the repository
git clone https://github.com/jconover/microservices-cicd
cd microservices-cicd
# Start local development environment
docker-compose up -d
# Run tests locally
./scripts/run-tests.sh
# Deploy to staging
git push origin develop
# Deploy to production (requires manual approval)
git push origin main