docs,refactor: readme docker-compose

This commit is contained in:
bbh
2025-08-01 10:47:02 +08:00
parent f72111e716
commit 2f6a163021
3 changed files with 217 additions and 207 deletions

View File

@@ -0,0 +1,10 @@
# Front-end Deployment Instructions
Test Environment Deployment Goals:
1. Complete local development ->
1. Push to the repository ->
1. Pull code for testing ->
1. Start the container using `docker compose -f <filename> up `
### according above flow, we can achieve : g
connect to the existing traefik-public network

View File

@@ -5,92 +5,92 @@ services:
# http://dashboard.localhost.tiangolo.com: frontend # http://dashboard.localhost.tiangolo.com: frontend
# etc. To enable it, update .env, set: # etc. To enable it, update .env, set:
# DOMAIN=localhost.tiangolo.com # DOMAIN=localhost.tiangolo.com
proxy: # proxy:
image: traefik:3.0 # image: traefik:3.0
volumes: # volumes:
- /var/run/docker.sock:/var/run/docker.sock # - /var/run/docker.sock:/var/run/docker.sock
ports: # ports:
- "80:80" # - "80:80"
- "8090:8080" # - "8090:8080"
# Duplicate the command from docker-compose.yml to add --api.insecure=true # # Duplicate the command from docker-compose.yml to add --api.insecure=true
command: # command:
# Enable Docker in Traefik, so that it reads labels from Docker services # # Enable Docker in Traefik, so that it reads labels from Docker services
- --providers.docker # - --providers.docker
# Add a constraint to only use services with the label for this stack # # Add a constraint to only use services with the label for this stack
- --providers.docker.constraints=Label(`traefik.constraint-label`, `traefik-public`) # - --providers.docker.constraints=Label(`traefik.constraint-label`, `traefik-public`)
# Do not expose all Docker services, only the ones explicitly exposed # # Do not expose all Docker services, only the ones explicitly exposed
- --providers.docker.exposedbydefault=false # - --providers.docker.exposedbydefault=false
# Create an entrypoint "http" listening on port 80 # # Create an entrypoint "http" listening on port 80
- --entrypoints.http.address=:80 # - --entrypoints.http.address=:80
# Create an entrypoint "https" listening on port 443 # # Create an entrypoint "https" listening on port 443
- --entrypoints.https.address=:443 # - --entrypoints.https.address=:443
# Enable the access log, with HTTP requests # # Enable the access log, with HTTP requests
- --accesslog # - --accesslog
# Enable the Traefik log, for configurations and errors # # Enable the Traefik log, for configurations and errors
- --log # - --log
# Enable debug logging for local development # # Enable debug logging for local development
- --log.level=DEBUG # - --log.level=DEBUG
# Enable the Dashboard and API # # Enable the Dashboard and API
- --api # - --api
# Enable the Dashboard and API in insecure mode for local development # # Enable the Dashboard and API in insecure mode for local development
- --api.insecure=true # - --api.insecure=true
labels: # labels:
# Enable Traefik for this service, to make it available in the public network # # Enable Traefik for this service, to make it available in the public network
- traefik.enable=true # - traefik.enable=true
- traefik.constraint-label=traefik-public # - traefik.constraint-label=traefik-public
# Dummy https-redirect middleware that doesn't really redirect, only to # # Dummy https-redirect middleware that doesn't really redirect, only to
# allow running it locally # # allow running it locally
- traefik.http.middlewares.https-redirect.contenttype.autodetect=false # - traefik.http.middlewares.https-redirect.contenttype.autodetect=false
networks: # networks:
- traefik-public # - traefik-public
- default # - default
db: # db:
restart: "no" # restart: "no"
ports: # ports:
- "5432:5432" # - "5432:5432"
adminer: # adminer:
restart: "no" # restart: "no"
ports: # ports:
- "8080:8080" # - "8080:8080"
backend: # backend:
restart: "no" # restart: "no"
ports: # ports:
- "8000:8000" # - "8000:8000"
build: # build:
context: ./backend # context: ./backend
# command: sleep infinity # Infinite loop to keep container alive doing nothing # # command: sleep infinity # Infinite loop to keep container alive doing nothing
command: # command:
- fastapi # - fastapi
- run # - run
- --reload # - --reload
- "app/main.py" # - "app/main.py"
develop: # develop:
watch: # watch:
- path: ./backend # - path: ./backend
action: sync # action: sync
target: /app # target: /app
ignore: # ignore:
- ./backend/.venv # - ./backend/.venv
- .venv # - .venv
- path: ./backend/pyproject.toml # - path: ./backend/pyproject.toml
action: rebuild # action: rebuild
# TODO: remove once coverage is done locally # # TODO: remove once coverage is done locally
volumes: # volumes:
- ./backend/htmlcov:/app/htmlcov # - ./backend/htmlcov:/app/htmlcov
environment: # environment:
SMTP_HOST: "mailcatcher" # SMTP_HOST: "mailcatcher"
SMTP_PORT: "1025" # SMTP_PORT: "1025"
SMTP_TLS: "false" # SMTP_TLS: "false"
EMAILS_FROM_EMAIL: "noreply@example.com" # EMAILS_FROM_EMAIL: "noreply@example.com"
mailcatcher: # mailcatcher:
image: schickling/mailcatcher # image: schickling/mailcatcher
ports: # ports:
- "1080:1080" # - "1080:1080"
- "1025:1025" # - "1025:1025"
frontend: frontend:
restart: "no" restart: "no"
@@ -130,4 +130,4 @@ services:
networks: networks:
traefik-public: traefik-public:
# For local dev, don't expect an external Traefik network # For local dev, don't expect an external Traefik network
external: false external: true

View File

@@ -1,138 +1,138 @@
services: services:
db: # db:
image: postgres:17 # image: postgres:17
restart: always # restart: always
healthcheck: # healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"] # test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 10s # interval: 10s
retries: 5 # retries: 5
start_period: 30s # start_period: 30s
timeout: 10s # timeout: 10s
volumes: # volumes:
- app-db-data:/var/lib/postgresql/data/pgdata # - app-db-data:/var/lib/postgresql/data/pgdata
env_file: # env_file:
- .env # - .env
environment: # environment:
- PGDATA=/var/lib/postgresql/data/pgdata # - PGDATA=/var/lib/postgresql/data/pgdata
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set} # - POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set}
- POSTGRES_USER=${POSTGRES_USER?Variable not set} # - POSTGRES_USER=${POSTGRES_USER?Variable not set}
- POSTGRES_DB=${POSTGRES_DB?Variable not set} # - POSTGRES_DB=${POSTGRES_DB?Variable not set}
adminer: # adminer:
image: adminer # image: adminer
restart: always # restart: always
networks: # networks:
- traefik-public # - traefik-public
- default # - default
depends_on: # depends_on:
- db # - db
environment: # environment:
- ADMINER_DESIGN=pepa-linha-dark # - ADMINER_DESIGN=pepa-linha-dark
labels: # labels:
- traefik.enable=true # - traefik.enable=true
- traefik.docker.network=traefik-public # - traefik.docker.network=traefik-public
- traefik.constraint-label=traefik-public # - traefik.constraint-label=traefik-public
- traefik.http.routers.${STACK_NAME?Variable not set}-adminer-http.rule=Host(`adminer.${DOMAIN?Variable not set}`) # - traefik.http.routers.${STACK_NAME?Variable not set}-adminer-http.rule=Host(`adminer.${DOMAIN?Variable not set}`)
- traefik.http.routers.${STACK_NAME?Variable not set}-adminer-http.entrypoints=http # - traefik.http.routers.${STACK_NAME?Variable not set}-adminer-http.entrypoints=http
- traefik.http.routers.${STACK_NAME?Variable not set}-adminer-http.middlewares=https-redirect # - traefik.http.routers.${STACK_NAME?Variable not set}-adminer-http.middlewares=https-redirect
- traefik.http.routers.${STACK_NAME?Variable not set}-adminer-https.rule=Host(`adminer.${DOMAIN?Variable not set}`) # - traefik.http.routers.${STACK_NAME?Variable not set}-adminer-https.rule=Host(`adminer.${DOMAIN?Variable not set}`)
- traefik.http.routers.${STACK_NAME?Variable not set}-adminer-https.entrypoints=https # - traefik.http.routers.${STACK_NAME?Variable not set}-adminer-https.entrypoints=https
- traefik.http.routers.${STACK_NAME?Variable not set}-adminer-https.tls=true # - traefik.http.routers.${STACK_NAME?Variable not set}-adminer-https.tls=true
- traefik.http.routers.${STACK_NAME?Variable not set}-adminer-https.tls.certresolver=le # - traefik.http.routers.${STACK_NAME?Variable not set}-adminer-https.tls.certresolver=le
- traefik.http.services.${STACK_NAME?Variable not set}-adminer.loadbalancer.server.port=8080 # - traefik.http.services.${STACK_NAME?Variable not set}-adminer.loadbalancer.server.port=8080
prestart: # prestart:
image: '${DOCKER_IMAGE_BACKEND?Variable not set}:${TAG-latest}' # image: '${DOCKER_IMAGE_BACKEND?Variable not set}:${TAG-latest}'
build: # build:
context: ./backend # context: ./backend
networks: # networks:
- traefik-public # - traefik-public
- default # - default
depends_on: # depends_on:
db: # db:
condition: service_healthy # condition: service_healthy
restart: true # restart: true
command: bash scripts/prestart.sh # command: bash scripts/prestart.sh
env_file: # env_file:
- .env # - .env
environment: # environment:
- DOMAIN=${DOMAIN} # - DOMAIN=${DOMAIN}
- FRONTEND_HOST=${FRONTEND_HOST?Variable not set} # - FRONTEND_HOST=${FRONTEND_HOST?Variable not set}
- ENVIRONMENT=${ENVIRONMENT} # - ENVIRONMENT=${ENVIRONMENT}
- BACKEND_CORS_ORIGINS=${BACKEND_CORS_ORIGINS} # - BACKEND_CORS_ORIGINS=${BACKEND_CORS_ORIGINS}
- SECRET_KEY=${SECRET_KEY?Variable not set} # - SECRET_KEY=${SECRET_KEY?Variable not set}
- FIRST_SUPERUSER=${FIRST_SUPERUSER?Variable not set} # - FIRST_SUPERUSER=${FIRST_SUPERUSER?Variable not set}
- FIRST_SUPERUSER_PASSWORD=${FIRST_SUPERUSER_PASSWORD?Variable not set} # - FIRST_SUPERUSER_PASSWORD=${FIRST_SUPERUSER_PASSWORD?Variable not set}
- SMTP_HOST=${SMTP_HOST} # - SMTP_HOST=${SMTP_HOST}
- SMTP_USER=${SMTP_USER} # - SMTP_USER=${SMTP_USER}
- SMTP_PASSWORD=${SMTP_PASSWORD} # - SMTP_PASSWORD=${SMTP_PASSWORD}
- EMAILS_FROM_EMAIL=${EMAILS_FROM_EMAIL} # - EMAILS_FROM_EMAIL=${EMAILS_FROM_EMAIL}
- POSTGRES_SERVER=db # - POSTGRES_SERVER=db
- POSTGRES_PORT=${POSTGRES_PORT} # - POSTGRES_PORT=${POSTGRES_PORT}
- POSTGRES_DB=${POSTGRES_DB} # - POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER?Variable not set} # - POSTGRES_USER=${POSTGRES_USER?Variable not set}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set} # - POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set}
- SENTRY_DSN=${SENTRY_DSN} # - SENTRY_DSN=${SENTRY_DSN}
backend: # backend:
image: '${DOCKER_IMAGE_BACKEND?Variable not set}:${TAG-latest}' # image: '${DOCKER_IMAGE_BACKEND?Variable not set}:${TAG-latest}'
restart: always # restart: always
networks: # networks:
- traefik-public # - traefik-public
- default # - default
depends_on: # depends_on:
db: # db:
condition: service_healthy # condition: service_healthy
restart: true # restart: true
prestart: # prestart:
condition: service_completed_successfully # condition: service_completed_successfully
env_file: # env_file:
- .env # - .env
environment: # environment:
- DOMAIN=${DOMAIN} # - DOMAIN=${DOMAIN}
- FRONTEND_HOST=${FRONTEND_HOST?Variable not set} # - FRONTEND_HOST=${FRONTEND_HOST?Variable not set}
- ENVIRONMENT=${ENVIRONMENT} # - ENVIRONMENT=${ENVIRONMENT}
- BACKEND_CORS_ORIGINS=${BACKEND_CORS_ORIGINS} # - BACKEND_CORS_ORIGINS=${BACKEND_CORS_ORIGINS}
- SECRET_KEY=${SECRET_KEY?Variable not set} # - SECRET_KEY=${SECRET_KEY?Variable not set}
- FIRST_SUPERUSER=${FIRST_SUPERUSER?Variable not set} # - FIRST_SUPERUSER=${FIRST_SUPERUSER?Variable not set}
- FIRST_SUPERUSER_PASSWORD=${FIRST_SUPERUSER_PASSWORD?Variable not set} # - FIRST_SUPERUSER_PASSWORD=${FIRST_SUPERUSER_PASSWORD?Variable not set}
- SMTP_HOST=${SMTP_HOST} # - SMTP_HOST=${SMTP_HOST}
- SMTP_USER=${SMTP_USER} # - SMTP_USER=${SMTP_USER}
- SMTP_PASSWORD=${SMTP_PASSWORD} # - SMTP_PASSWORD=${SMTP_PASSWORD}
- EMAILS_FROM_EMAIL=${EMAILS_FROM_EMAIL} # - EMAILS_FROM_EMAIL=${EMAILS_FROM_EMAIL}
- POSTGRES_SERVER=db # - POSTGRES_SERVER=db
- POSTGRES_PORT=${POSTGRES_PORT} # - POSTGRES_PORT=${POSTGRES_PORT}
- POSTGRES_DB=${POSTGRES_DB} # - POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER?Variable not set} # - POSTGRES_USER=${POSTGRES_USER?Variable not set}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set} # - POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set}
- SENTRY_DSN=${SENTRY_DSN} # - SENTRY_DSN=${SENTRY_DSN}
healthcheck: # healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/api/v1/utils/health-check/"] # test: ["CMD", "curl", "-f", "http://localhost:8000/api/v1/utils/health-check/"]
interval: 10s # interval: 10s
timeout: 5s # timeout: 5s
retries: 5 # retries: 5
build: # build:
context: ./backend # context: ./backend
labels: # labels:
- traefik.enable=true # - traefik.enable=true
- traefik.docker.network=traefik-public # - traefik.docker.network=traefik-public
- traefik.constraint-label=traefik-public # - traefik.constraint-label=traefik-public
- traefik.http.services.${STACK_NAME?Variable not set}-backend.loadbalancer.server.port=8000 # - traefik.http.services.${STACK_NAME?Variable not set}-backend.loadbalancer.server.port=8000
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.rule=Host(`api.${DOMAIN?Variable not set}`) # - traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.rule=Host(`api.${DOMAIN?Variable not set}`)
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.entrypoints=http # - traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.entrypoints=http
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.rule=Host(`api.${DOMAIN?Variable not set}`) # - traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.rule=Host(`api.${DOMAIN?Variable not set}`)
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.entrypoints=https # - traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.entrypoints=https
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.tls=true # - traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.tls=true
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.tls.certresolver=le # - traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.tls.certresolver=le
# Enable redirection for HTTP and HTTPS # # Enable redirection for HTTP and HTTPS
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.middlewares=https-redirect # - traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.middlewares=https-redirect
frontend: frontend:
image: '${DOCKER_IMAGE_FRONTEND?Variable not set}:${TAG-latest}' image: '${DOCKER_IMAGE_FRONTEND?Variable not set}:${TAG-latest}'