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

View File

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