Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernise docker compose setup #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.env
*.swp
docker/db/
docker/.env
5 changes: 3 additions & 2 deletions .env-dist → docker/.env-dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
# 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
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
Expand Down
39 changes: 26 additions & 13 deletions docker-compose.yaml → docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
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}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
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
Expand All @@ -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:
Expand All @@ -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
27 changes: 27 additions & 0 deletions docker/nginx/conf.d/kcapp.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}