GitHub + GitLab + Docker + Nginx Blue-Green Deployment
This document describes the CI/CD architecture for a microservices platform where:
This approach is commonly used to reduce pipeline time and infrastructure cost.
*Note
The services name used in this document are dummy service names. Since the document is generic and similar approach can be adapted for other CICD deployments irrespective of inclusion/exclusion of Microservices from the application architecture.
| System | Purpose |
|---|---|
| GitHub | Source code repository |
| GitLab CI | Build & deployment pipelines |
| Docker | Containerization |
| GitLab Registry | Docker image storage |
| Docker Compose | Service orchestration |
| Nginx | Traffic routing |
| Linux Servers | Runtime environments |
The pipeline includes manual approval gates to ensure controlled deployments.
| Environment | Approval Required | Description |
|---|---|---|
| DEV | Code Review | Code merged after peer review |
| TEST | Test Manager | QA validation before testing |
| PROD | UAT + Release Manager | Business validation before production |
Large systems may contain 20–100 microservices.
Instead of rebuilding everything, the pipeline:
If only:
auth-service booking-service
changed, then pipeline creates jobs:
build-auth-service deploy-auth-service build-booking-service deploy-booking-service
Other services are skipped.
This reduces pipeline time drastically.
Each microservice is containerized and pushed to:
GitLab Container Registry
To reduce storage cost:
Keep latest 5 images Delete older images automatically
Example:
auth-service ├── v1 ├── v2 ├── v3 ├── v4 └── v5
Older images are removed automatically.
Production environment contains two identical environments.
| Environment | Role |
|---|---|
| Blue | Currently active |
| Green | New deployment |
Nginx acts as the traffic router.
upstream backend {
server green:8080;
}
Switching traffic:
nginx -s reload
Result:
Zero downtime release
After deployment:
/health /ready /status
are validated.
Switch traffic to Green
Rollback to Blue
Users never experience downtime.
Instead of restarting the entire stack:
docker compose up -d auth-service
Only updated services restart.
Benefits:
Each service maintains separate log directories.
Example:
logs/
auth-service/
auth-service-v1.log
auth-service-v2.log
booking-service/
booking-service-v3.log
Benefits:
Adapted project structure:
platform-root/ services/ │ ├── auth-service/ │ ├── src │ ├── Dockerfile │ └── service.yml │ ├── booking-service/ │ ├── src │ ├── Dockerfile │ └── service.yml │ └── payment-service/ docker/ docker-compose.dev.yml docker-compose.test.yml docker-compose.blue.yml docker-compose.green.yml nginx/ nginx.conf upstream.conf logs/ auth-service/ booking-service/ payment-service/ scripts/ detect-changed-services.sh generate-dynamic-pipeline.sh deploy-service.sh nginx-switch.sh cleanup-old-images.sh .gitlab-ci.yml README.md
Only changed services build.
Old images automatically removed.
Blue-Green strategy with Nginx.
Approval gates prevent accidental releases.
Per-service logging.
Supports 50+ microservices easily.
| Stage | Time |
|---|---|
| Code build | 2–5 min |
| Docker image build | 2 min |
| DEV deployment | 1 min |
| TEST deployment | 2 min |
| Production blue-green | 30 sec |
Typical full release:
~10 minutes