This document explains how to build and deploy the TaskGenix Backend using Docker and the CI/CD pipeline.
Production-optimized Dockerfile with:
- Multi-stage build for smaller image size
- Non-root user for security
- Health checks
- Optimized layer caching
Development Dockerfile used for local development and debugging.
- Push to
mainbranch → Production deployment - Push to
devbranch → Staging deployment - Pull requests to
main→ Build and test only - Manual workflow dispatch
Add these secrets to your GitHub repository:
# Docker Hub credentials
DOCKER_USERNAME=your-dockerhub-username
DOCKER_PASSWORD=your-dockerhub-passwordlatest- Latest main branch builddev- Latest dev branch buildmain-<sha>- Specific main branch commitdev-<sha>- Specific dev branch commitpr-<number>- Pull request builds
docker build -f Dockerfile.prod -t taskgenix-be:prod .docker run -d \
--name taskgenix-be \
-p 5009:5009 \
-e ASPNETCORE_ENVIRONMENT=Production \
-e JWT__SecretKey="your-secret-key" \
-e ConnectionStrings__DefaultConnection="your-connection-string" \
taskgenix-be:prodversion: "3.8"
services:
app:
image: taskgenix/taskgenix-be:latest
ports:
- "5009:5009"
environment:
- ASPNETCORE_ENVIRONMENT=Production
- JWT__SecretKey=your-secret-key
- ConnectionStrings__DefaultConnection=your-connection-string
depends_on:
- db
db:
image: postgres:16-alpine
environment:
POSTGRES_DB: TaskGenixDB
POSTGRES_USER: admin
POSTGRES_PASSWORD: admin
ports:
- "5432:5432"JWT__SecretKey- JWT signing keyJWT__Issuer- JWT issuerJWT__Audience- JWT audienceConnectionStrings__DefaultConnection- Database connection
ASPNETCORE_ENVIRONMENT- Environment (Production/Staging/Development)ASPNETCORE_URLS- Binding URLs (default: http://+:5009)
The production image includes a health check endpoint:
curl -f http://localhost:5009/health- Non-root user execution
- Minimal attack surface
- Security-focused base images
- Environment variable validation
- Application logs available via
docker logs - Health check status via Docker
- Metrics endpoint (if implemented):
/metrics
# Clean build
docker system prune -f
docker build --no-cache -f Dockerfile.prod -t taskgenix-be:prod .# Check logs
docker logs taskgenix-be
# Check health
docker exec taskgenix-be curl -f http://localhost:5009/health
# Interactive shell
docker exec -it taskgenix-be /bin/bash