Skip to content

Latest commit

 

History

History
149 lines (107 loc) · 3.04 KB

File metadata and controls

149 lines (107 loc) · 3.04 KB

TaskGenix Backend - Docker Setup

This document explains how to build and deploy the TaskGenix Backend using Docker and the CI/CD pipeline.

🐳 Docker Files

Dockerfile.prod

Production-optimized Dockerfile with:

  • Multi-stage build for smaller image size
  • Non-root user for security
  • Health checks
  • Optimized layer caching

Dockerfile (Development)

Development Dockerfile used for local development and debugging.

🚀 CI/CD Pipeline

Workflow Triggers

  • Push to main branch → Production deployment
  • Push to dev branch → Staging deployment
  • Pull requests to main → Build and test only
  • Manual workflow dispatch

Required Secrets

Add these secrets to your GitHub repository:

# Docker Hub credentials
DOCKER_USERNAME=your-dockerhub-username
DOCKER_PASSWORD=your-dockerhub-password

Image Tags

  • latest - Latest main branch build
  • dev - Latest dev branch build
  • main-<sha> - Specific main branch commit
  • dev-<sha> - Specific dev branch commit
  • pr-<number> - Pull request builds

🛠️ Local Usage

Build Production Image

docker build -f Dockerfile.prod -t taskgenix-be:prod .

Run Production Container

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:prod

Run with Docker Compose

version: "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"

🔧 Environment Variables

Required

  • JWT__SecretKey - JWT signing key
  • JWT__Issuer - JWT issuer
  • JWT__Audience - JWT audience
  • ConnectionStrings__DefaultConnection - Database connection

Optional

  • ASPNETCORE_ENVIRONMENT - Environment (Production/Staging/Development)
  • ASPNETCORE_URLS - Binding URLs (default: http://+:5009)

📊 Health Check

The production image includes a health check endpoint:

curl -f http://localhost:5009/health

🔒 Security Features

  • Non-root user execution
  • Minimal attack surface
  • Security-focused base images
  • Environment variable validation

📈 Monitoring

  • Application logs available via docker logs
  • Health check status via Docker
  • Metrics endpoint (if implemented): /metrics

🚨 Troubleshooting

Build Issues

# Clean build
docker system prune -f
docker build --no-cache -f Dockerfile.prod -t taskgenix-be:prod .

Runtime Issues

# 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