From 0625622057ad3b4af935555691e210422c83944b Mon Sep 17 00:00:00 2001 From: Lars Velle Date: Thu, 19 Dec 2024 13:35:06 +0000 Subject: [PATCH] Modernise docker compose setup --- .gitignore | 4 +- .env-dist => docker/.env-dist | 5 ++- .../docker-compose.yaml | 39 ++++++++++++------- docker/nginx/conf.d/kcapp.conf | 27 +++++++++++++ 4 files changed, 59 insertions(+), 16 deletions(-) rename .env-dist => docker/.env-dist (86%) rename docker-compose.yaml => docker/docker-compose.yaml (64%) create mode 100644 docker/nginx/conf.d/kcapp.conf diff --git a/.gitignore b/.gitignore index 4c49bd7..e1492fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -.env +*.swp +docker/db/ +docker/.env diff --git a/.env-dist b/docker/.env-dist similarity index 86% rename from .env-dist rename to docker/.env-dist index 6d712e8..b322d2e 100644 --- a/.env-dist +++ b/docker/.env-dist @@ -3,8 +3,8 @@ # or if you just hate defaults # Docker image versions -KCAPP_API_VERSION=1.0.0 -KCAPP_FRONTEND_VERSION=1.0.0 +KCAPP_API_VERSION=v2.8.0 +KCAPP_FRONTEND_VERSION=v2.8.0 # Frontend settings KCAPP_FRONTEND_LISTEN_PORT=3000 @@ -12,6 +12,7 @@ KCAPP_FRONTEND_LISTEN_ADDR=0.0.0.0 # API settings KCAPP_API=http://api:8001 +KCAPP_API_PATH=/api DISK_CACHE=false API_LISTEN_ADDR=0.0.0.0 API_LISTEN_PORT=8001 diff --git a/docker-compose.yaml b/docker/docker-compose.yaml similarity index 64% rename from docker-compose.yaml rename to docker/docker-compose.yaml index 026ad11..29bf0be 100644 --- a/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -1,16 +1,26 @@ version: '3.6' services: + nginx: + container_name: nginx + hostname: nginx + restart: unless-stopped + image: nginx + ports: + - 80:80 + volumes: + - ./nginx/conf.d:/etc/nginx/conf.d:ro db: - image: linuxserver/mariadb:110.4.12mariabionic-ls59 - #command: mysqld --sql_mode="" - restart: always + image: linuxserver/mariadb:${MYSQL_VERSION:-10.11.10} + hostname: db + container_name: db + restart: unless-stopped ports: - "${MYSQL_LISTEN_ADDR}:${MYSQL_LISTEN_PORT}:3306" expose: - ${MYSQL_LISTEN_PORT} volumes: - - db_config:/config - - db:/var/lib/mysql + - ./db/config:/config + - ./db/data:/var/lib/mysql environment: MYSQL_DATABASE: ${MYSQL_DATABASE} MYSQL_USER: ${MYSQL_USER} @@ -18,6 +28,8 @@ services: MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} migration: image: kcapp/api:$KCAPP_API_VERSION + hostname: migration + container_name: migration command: [ "./wait-for-it.sh", "db:3306", "--", "./run_migrations.sh" ] depends_on: - db @@ -27,7 +39,9 @@ services: MYSQL_DATABASE: ${MYSQL_DATABASE} api: image: kcapp/api:$KCAPP_API_VERSION - restart: always + hostname: api + container_name: api + restart: unless-stopped ports: - "${API_LISTEN_ADDR}:${API_LISTEN_PORT}:8001" expose: @@ -36,22 +50,21 @@ services: - migration - db command: [ "./wait-for-it.sh", "db:3306", "--", "/go/bin/api" ] +# command: [ "./wait-for-it.sh", "db:3306", "--", "/go/bin/api statistics recalculate x01 --dry-run=false" ] + frontend: image: kcapp/frontend:$KCAPP_FRONTEND_VERSION - restart: always + hostname: frontend + container_name: frontend + restart: unless-stopped ports: - "${KCAPP_FRONTEND_LISTEN_ADDR}:${KCAPP_FRONTEND_LISTEN_PORT}:3000" expose: - ${KCAPP_FRONTEND_LISTEN_PORT} - volumes: - - frontend_cache:/.cache depends_on: - api environment: - DEBUG=kcapp* - KCAPP_API - DISK_CACHE -volumes: - db: - db_config: - frontend_cache: + - KCAPP_API_PATH diff --git a/docker/nginx/conf.d/kcapp.conf b/docker/nginx/conf.d/kcapp.conf new file mode 100644 index 0000000..a66095f --- /dev/null +++ b/docker/nginx/conf.d/kcapp.conf @@ -0,0 +1,27 @@ +server { + listen 80; + server_name _; + + access_log off; + + location / { + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Server $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Upgrade $http_upgrade; + proxy_pass http://frontend:3000; + } + + location /api/ { + rewrite ^/api(/.*)$ $1 break; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Server $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Upgrade $http_upgrade; + proxy_pass http://api:8001; + } +}