up
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
*
|
||||
!Dockerfile.backend
|
||||
!backend/
|
||||
!backend/evening_detective_server
|
||||
!backend/goose
|
||||
!migrations/
|
||||
!migrations/*.sql
|
||||
@@ -0,0 +1,6 @@
|
||||
.env
|
||||
backend/
|
||||
frontend/dist/
|
||||
migrations/
|
||||
certificates/
|
||||
packages/
|
||||
@@ -0,0 +1,5 @@
|
||||
FROM alpine:3.22
|
||||
COPY backend/evening_detective_server /usr/local/bin/evening_detective_server
|
||||
COPY backend/goose /usr/local/bin/goose
|
||||
COPY migrations /migrations
|
||||
CMD ["/usr/local/bin/evening_detective_server"]
|
||||
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
cd -- "$(dirname -- "${BASH_SOURCE[0]}")"
|
||||
if [[ ! -f .env ]]; then
|
||||
command -v openssl >/dev/null
|
||||
(
|
||||
umask 077
|
||||
cat > .env <<EOF
|
||||
APP_BASE_URL=http://localhost:8088
|
||||
VENUE_BIND_IP=127.0.0.1
|
||||
VENUE_PORT=8088
|
||||
POSTGRES_USER=evening_detective
|
||||
POSTGRES_DB=evening_detective
|
||||
POSTGRES_PASSWORD=$(openssl rand -hex 32)
|
||||
JWT_SECRET=$(openssl rand -hex 32)
|
||||
PARTICIPATION_SECRET=$(openssl rand -hex 32)
|
||||
S3_USER=evening_detective
|
||||
S3_PASSWORD=$(openssl rand -hex 32)
|
||||
S3_BUCKET=evening-detective
|
||||
GAME_TIMEZONE=Asia/Barnaul
|
||||
VENUE_USER_USERNAME=Организатор
|
||||
VENUE_USER_EMAIL=organizer@venue.invalid
|
||||
VENUE_USER_PASSWORD=$(openssl rand -hex 8)
|
||||
EOF
|
||||
)
|
||||
fi
|
||||
|
||||
prepare=false
|
||||
case "${1:-}" in
|
||||
--build) prepare=true ;;
|
||||
'') ;;
|
||||
*) echo 'Используйте make venue или make venue-update' >&2; exit 1 ;;
|
||||
esac
|
||||
for image in evening-detective-venue-app:1 postgres:15 rustfs/rustfs:latest byjg/static-httpserver:latest nginx:alpine; do
|
||||
if ! docker image inspect "$image" >/dev/null 2>&1; then prepare=true; fi
|
||||
done
|
||||
for artifact in backend/evening_detective_server backend/goose backend/dev-user.sql frontend/dist/index.html; do
|
||||
if [[ ! -f "$artifact" ]]; then prepare=true; fi
|
||||
done
|
||||
if [[ ! -d migrations ]]; then prepare=true; fi
|
||||
if [[ "$prepare" == true ]]; then
|
||||
echo 'Подготовка площадки: потребуется интернет.'
|
||||
if ! docker image inspect my-go-builder >/dev/null 2>&1; then
|
||||
make -C ../evening_detective_server build-builder
|
||||
fi
|
||||
if [[ ! -d ../evening_detective_frontend/node_modules ]]; then
|
||||
npm --prefix ../evening_detective_frontend ci
|
||||
fi
|
||||
make -C .. build
|
||||
docker compose pull postgres_evening_detective_server rustfs_evening_detective_server evening_detective_frontend proxy
|
||||
docker pull alpine:3.22
|
||||
docker compose build --pull=false
|
||||
fi
|
||||
for volume in evening-detective-local_postgres_data evening-detective-local_rustfs_data; do
|
||||
docker volume create "$volume" >/dev/null
|
||||
done
|
||||
docker compose up -d --no-build --pull never
|
||||
docker compose --profile setup run --rm bootstrap
|
||||
docker compose ps
|
||||
echo 'Площадка запущена. Адрес и данные входа находятся в venue/.env.'
|
||||
@@ -0,0 +1,143 @@
|
||||
name: evening-detective-venue
|
||||
|
||||
x-app: &app
|
||||
image: evening-detective-venue-app:1
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.backend
|
||||
environment:
|
||||
APP_MODE: venue
|
||||
DATABASE_URL: postgresql://${POSTGRES_USER:?}:${POSTGRES_PASSWORD:?}@postgres_evening_detective_server:5432/${POSTGRES_DB:?}?sslmode=disable
|
||||
APP_BASE_URL: ${APP_BASE_URL:?}
|
||||
FILE_PREFIX_DOMAIN: ${APP_BASE_URL:?}/api/files/
|
||||
GAME_TIMEZONE: ${GAME_TIMEZONE:-Asia/Barnaul}
|
||||
JWT_SECRET: ${JWT_SECRET:?}
|
||||
PARTICIPATION_SECRET: ${PARTICIPATION_SECRET:?}
|
||||
S3_HOST: http://rustfs_evening_detective_server:9000
|
||||
S3_USER: ${S3_USER:?}
|
||||
S3_PASSWORD: ${S3_PASSWORD:?}
|
||||
S3_BUCKET: ${S3_BUCKET:-evening-detective}
|
||||
|
||||
services:
|
||||
postgres_evening_detective_server:
|
||||
image: postgres:15
|
||||
environment:
|
||||
POSTGRES_DB: ${POSTGRES_DB:?}
|
||||
POSTGRES_USER: ${POSTGRES_USER:?}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?}
|
||||
TZ: ${GAME_TIMEZONE:-Asia/Barnaul}
|
||||
PGTZ: ${GAME_TIMEZONE:-Asia/Barnaul}
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: [CMD-SHELL, 'pg_isready -U "$${POSTGRES_USER}" -d "$${POSTGRES_DB}" -h localhost']
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 12
|
||||
|
||||
rustfs_evening_detective_server:
|
||||
image: rustfs/rustfs:latest
|
||||
environment:
|
||||
RUSTFS_ACCESS_KEY: ${S3_USER:?}
|
||||
RUSTFS_SECRET_KEY: ${S3_PASSWORD:?}
|
||||
RUSTFS_CONSOLE_ENABLE: "false"
|
||||
RUSTFS_ADDRESS: 0.0.0.0:9000
|
||||
volumes:
|
||||
- rustfs_data:/data
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: [CMD-SHELL, 'curl -f http://localhost:9000/health']
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 12
|
||||
start_period: 30s
|
||||
|
||||
migrate:
|
||||
<<: *app
|
||||
entrypoint: [/bin/sh, -ec]
|
||||
command: ['exec goose -dir /migrations postgres "$$DATABASE_URL" up']
|
||||
depends_on:
|
||||
postgres_evening_detective_server:
|
||||
condition: service_healthy
|
||||
restart: "no"
|
||||
|
||||
evening_detective_server:
|
||||
<<: *app
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
rustfs_evening_detective_server:
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: [CMD, wget, -q, -T, '2', -O, /dev/null, 'http://127.0.0.1:8090/api/test/ping']
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 12
|
||||
|
||||
bootstrap:
|
||||
image: postgres:15
|
||||
profiles: [setup]
|
||||
environment:
|
||||
PGHOST: postgres_evening_detective_server
|
||||
PGUSER: ${POSTGRES_USER:?}
|
||||
PGPASSWORD: ${POSTGRES_PASSWORD:?}
|
||||
PGDATABASE: ${POSTGRES_DB:?}
|
||||
VENUE_USER_USERNAME: ${VENUE_USER_USERNAME:-Организатор}
|
||||
VENUE_USER_EMAIL: ${VENUE_USER_EMAIL:-organizer@venue.invalid}
|
||||
VENUE_USER_PASSWORD: ${VENUE_USER_PASSWORD:?}
|
||||
volumes:
|
||||
- ./backend/dev-user.sql:/bootstrap.sql:ro
|
||||
entrypoint: [/bin/sh, -ec]
|
||||
command:
|
||||
- >-
|
||||
exec psql -v ON_ERROR_STOP=1
|
||||
-v dev_username="$$VENUE_USER_USERNAME"
|
||||
-v dev_email="$$VENUE_USER_EMAIL"
|
||||
-v dev_password="$$VENUE_USER_PASSWORD"
|
||||
-f /bootstrap.sql
|
||||
depends_on:
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
restart: "no"
|
||||
|
||||
evening_detective_frontend:
|
||||
image: byjg/static-httpserver:latest
|
||||
environment:
|
||||
SPA_MODE: "true"
|
||||
volumes:
|
||||
- ./frontend/dist:/static:ro
|
||||
expose:
|
||||
- "8080"
|
||||
restart: unless-stopped
|
||||
|
||||
proxy:
|
||||
image: nginx:alpine
|
||||
volumes:
|
||||
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
ports:
|
||||
- '${VENUE_BIND_IP:-0.0.0.0}:${VENUE_PORT:-8088}:80'
|
||||
depends_on:
|
||||
evening_detective_server:
|
||||
condition: service_healthy
|
||||
evening_detective_frontend:
|
||||
condition: service_started
|
||||
networks:
|
||||
- default
|
||||
- entrance
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
# Preserve existing data from the former Compose project.
|
||||
postgres_data:
|
||||
name: evening-detective-local_postgres_data
|
||||
external: true
|
||||
rustfs_data:
|
||||
name: evening-detective-local_rustfs_data
|
||||
external: true
|
||||
|
||||
networks:
|
||||
default:
|
||||
internal: true
|
||||
entrance:
|
||||
@@ -0,0 +1,17 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
client_max_body_size 257m;
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://evening_detective_server:8090;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_read_timeout 120s;
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://evening_detective_frontend:8080;
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user