chore: docker compose and deploy to edgerealm, learn-atc style
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a40e7e549f
commit
a744631726
|
|
@ -0,0 +1,45 @@
|
||||||
|
# Docker (edgerealm) defaults. deploy.sh copies this to .env on the first deploy and
|
||||||
|
# fills APP_KEY, DB_PASSWORD and PUSHER_APP_SECRET with generated values.
|
||||||
|
APP_NAME="Village Politics"
|
||||||
|
APP_ENV=production
|
||||||
|
APP_KEY=
|
||||||
|
APP_DEBUG=false
|
||||||
|
APP_URL=https://server-village.blax.at
|
||||||
|
|
||||||
|
APP_LOCALE=en
|
||||||
|
APP_FALLBACK_LOCALE=en
|
||||||
|
APP_FAKER_LOCALE=en_US
|
||||||
|
|
||||||
|
BCRYPT_ROUNDS=12
|
||||||
|
|
||||||
|
LOG_CHANNEL=stderr
|
||||||
|
LOG_LEVEL=warning
|
||||||
|
|
||||||
|
DB_CONNECTION=mysql
|
||||||
|
DB_HOST=mysql-village
|
||||||
|
DB_PORT=3306
|
||||||
|
DB_DATABASE=village
|
||||||
|
DB_USERNAME=root
|
||||||
|
DB_PASSWORD=
|
||||||
|
|
||||||
|
# API only: bearer tokens, no sessions or queued jobs.
|
||||||
|
SESSION_DRIVER=array
|
||||||
|
QUEUE_CONNECTION=sync
|
||||||
|
BROADCAST_CONNECTION=log
|
||||||
|
FILESYSTEM_DISK=local
|
||||||
|
|
||||||
|
# Shared between the WS server and the game:events worker (socket → user map).
|
||||||
|
CACHE_STORE=redis
|
||||||
|
REDIS_CLIENT=phpredis
|
||||||
|
REDIS_HOST=redis-village
|
||||||
|
REDIS_PASSWORD=null
|
||||||
|
REDIS_PORT=6379
|
||||||
|
|
||||||
|
MAIL_MAILER=log
|
||||||
|
|
||||||
|
# WS server (blax-software/laravel-websockets). The key is public: the client
|
||||||
|
# connects to wss://ws-server-village.blax.at/app/<PUSHER_APP_KEY>.
|
||||||
|
PUSHER_APP_ID=village
|
||||||
|
PUSHER_APP_KEY=village-politics
|
||||||
|
PUSHER_APP_SECRET=
|
||||||
|
PUSHER_PORT=6001
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Runs on the server: pulls, installs, migrates, and restarts the WS server and worker.
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SELF="$0"
|
||||||
|
APP=(docker compose exec -T app)
|
||||||
|
|
||||||
|
echo "==> Starting deploy script..."
|
||||||
|
|
||||||
|
# Re-run the pulled version of this script so changes to it apply right away.
|
||||||
|
if [ "${1:-}" != "--after-pull" ]; then
|
||||||
|
git pull --rebase --stat
|
||||||
|
exec "$SELF" --after-pull
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f .env ]; then
|
||||||
|
echo "==> .env missing — creating it from .env.example with generated secrets"
|
||||||
|
cp .env.example .env
|
||||||
|
sed -i \
|
||||||
|
-e "s|^DB_PASSWORD=.*|DB_PASSWORD=$(openssl rand -hex 24)|" \
|
||||||
|
-e "s|^PUSHER_APP_SECRET=.*|PUSHER_APP_SECRET=$(openssl rand -hex 24)|" .env
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p docker-data/mysql storage/framework/cache storage/framework/views storage/logs bootstrap/cache
|
||||||
|
|
||||||
|
echo "==> Starting containers..."
|
||||||
|
docker compose up -d
|
||||||
|
|
||||||
|
echo "==> Waiting for MySQL..."
|
||||||
|
for _ in $(seq 1 60); do
|
||||||
|
[ "$(docker inspect -f '{{.State.Health.Status}}' "$(docker compose ps -q mysql)")" = healthy ] && break
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "==> Installing composer dependencies..."
|
||||||
|
"${APP[@]}" bash -c "COMPOSER_HOME=/tmp/composer composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev"
|
||||||
|
|
||||||
|
if ! grep -q '^APP_KEY=base64:' .env; then
|
||||||
|
"${APP[@]}" php artisan key:generate --force
|
||||||
|
# The running container read .env at start; recreate it so it sees the key.
|
||||||
|
docker compose up -d --force-recreate app
|
||||||
|
fi
|
||||||
|
|
||||||
|
"${APP[@]}" chown -R www-data:www-data storage bootstrap/cache
|
||||||
|
|
||||||
|
echo "==> Migrating..."
|
||||||
|
"${APP[@]}" php artisan migrate --force
|
||||||
|
"${APP[@]}" php artisan db:seed --force
|
||||||
|
|
||||||
|
"${APP[@]}" php artisan optimize:clear
|
||||||
|
"${APP[@]}" php artisan optimize
|
||||||
|
|
||||||
|
# Both daemons cache code at boot.
|
||||||
|
echo "==> Restarting WS server and game:events worker..."
|
||||||
|
"${APP[@]}" supervisorctl reread
|
||||||
|
"${APP[@]}" supervisorctl update
|
||||||
|
"${APP[@]}" supervisorctl restart websocket game-events
|
||||||
|
|
||||||
|
echo "==> Deployment complete!"
|
||||||
|
|
@ -0,0 +1,91 @@
|
||||||
|
services:
|
||||||
|
# nginx + php-fpm from the base image, plus the WS server and the game:events
|
||||||
|
# worker as supervisor programs (docker/supervisor/). The repo is bind-mounted.
|
||||||
|
app:
|
||||||
|
image: 'blaxsoftware/laravel:laravel13-php8.4'
|
||||||
|
# Hostnames must be unique on the shared `web` network.
|
||||||
|
hostname: 'village-app'
|
||||||
|
env_file: .env
|
||||||
|
environment:
|
||||||
|
ENABLE_QUEUE: 'false'
|
||||||
|
ENABLE_SCHEDULER: 'false'
|
||||||
|
ENABLE_LARAVEL_PERMS: '1'
|
||||||
|
volumes:
|
||||||
|
- '.:/var/www/html'
|
||||||
|
- './docker/supervisor:/etc/supervisor/custom.d:ro'
|
||||||
|
depends_on:
|
||||||
|
- mysql
|
||||||
|
- redis
|
||||||
|
restart: unless-stopped
|
||||||
|
logging:
|
||||||
|
driver: json-file
|
||||||
|
options:
|
||||||
|
max-size: "10m"
|
||||||
|
max-file: "3"
|
||||||
|
labels:
|
||||||
|
traefik.enable: "true"
|
||||||
|
traefik.docker.network: "web"
|
||||||
|
# nginx on the host terminates TLS with the *.blax.at wildcard cert and
|
||||||
|
# forwards plain HTTP (and WS upgrades) to traefik's `web` entrypoint.
|
||||||
|
traefik.http.routers.village-server.rule: "Host(`server-village.blax.at`) || Host(`server-village.localhost.at`)"
|
||||||
|
traefik.http.routers.village-server.entrypoints: "web"
|
||||||
|
traefik.http.routers.village-server.service: "village-server-http"
|
||||||
|
traefik.http.services.village-server-http.loadbalancer.server.port: "80"
|
||||||
|
traefik.http.routers.village-ws.rule: "Host(`ws-server-village.blax.at`) || Host(`ws-server-village.localhost.at`)"
|
||||||
|
traefik.http.routers.village-ws.entrypoints: "web"
|
||||||
|
traefik.http.routers.village-ws.service: "village-ws"
|
||||||
|
traefik.http.services.village-ws.loadbalancer.server.port: "6001"
|
||||||
|
|
||||||
|
mysql:
|
||||||
|
image: 'mysql:8.4'
|
||||||
|
# DB_HOST in .env must match.
|
||||||
|
hostname: 'mysql-village'
|
||||||
|
command: --max-connections=100
|
||||||
|
volumes:
|
||||||
|
- './docker-data/mysql:/var/lib/mysql'
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
|
||||||
|
MYSQL_DATABASE: '${DB_DATABASE}'
|
||||||
|
MYSQL_ROOT_HOST: '%'
|
||||||
|
restart: unless-stopped
|
||||||
|
logging:
|
||||||
|
driver: json-file
|
||||||
|
options:
|
||||||
|
max-size: "10m"
|
||||||
|
max-file: "3"
|
||||||
|
expose:
|
||||||
|
- '3306'
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
|
||||||
|
interval: 5s
|
||||||
|
retries: 20
|
||||||
|
timeout: 5s
|
||||||
|
|
||||||
|
redis:
|
||||||
|
image: 'redis:alpine'
|
||||||
|
# Cache and the WS server's socket→user map only: bounded, evicting, no persistence
|
||||||
|
# (the same guard learn-atc bakes in, since this host is shared).
|
||||||
|
command:
|
||||||
|
- redis-server
|
||||||
|
- --maxmemory
|
||||||
|
- 64mb
|
||||||
|
- --maxmemory-policy
|
||||||
|
- allkeys-lru
|
||||||
|
- --save
|
||||||
|
- ""
|
||||||
|
- --appendonly
|
||||||
|
- "no"
|
||||||
|
hostname: 'redis-village'
|
||||||
|
restart: unless-stopped
|
||||||
|
expose:
|
||||||
|
- '6379'
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "redis-cli", "ping"]
|
||||||
|
retries: 3
|
||||||
|
timeout: 5s
|
||||||
|
|
||||||
|
networks:
|
||||||
|
default:
|
||||||
|
name: web
|
||||||
|
external: true
|
||||||
|
driver: bridge
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
; The game:events worker. Same container as the WS server, so its pushes reach
|
||||||
|
; the server's local broadcast socket.
|
||||||
|
[program:game-events]
|
||||||
|
command=/usr/local/bin/php -d variables_order=EGPCS /var/www/html/artisan game:events
|
||||||
|
autostart=true
|
||||||
|
autorestart=true
|
||||||
|
user=www-data
|
||||||
|
priority=40
|
||||||
|
startsecs=3
|
||||||
|
startretries=100
|
||||||
|
stopsignal=TERM
|
||||||
|
stopwaitsecs=10
|
||||||
|
stdout_logfile=/proc/1/fd/1
|
||||||
|
stdout_logfile_maxbytes=0
|
||||||
|
stderr_logfile=/proc/1/fd/2
|
||||||
|
stderr_logfile_maxbytes=0
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
[program:websocket]
|
||||||
|
command=/usr/local/bin/php -d variables_order=EGPCS /var/www/html/artisan websockets:serve
|
||||||
|
autostart=true
|
||||||
|
autorestart=true
|
||||||
|
user=www-data
|
||||||
|
priority=30
|
||||||
|
startsecs=5
|
||||||
|
startretries=100
|
||||||
|
stopsignal=TERM
|
||||||
|
stopwaitsecs=15
|
||||||
|
stdout_logfile=/proc/1/fd/1
|
||||||
|
stdout_logfile_maxbytes=0
|
||||||
|
stderr_logfile=/proc/1/fd/2
|
||||||
|
stderr_logfile_maxbytes=0
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# Deploys the pushed master to server-village.blax.at (edgerealm) and checks HTTP and WS.
|
||||||
|
# Touches only the game-village-politics-backend checkout and its containers on that shared host.
|
||||||
|
# On Windows, put the Windows OpenSSH client first: PATH="/c/Windows/System32/OpenSSH:$PATH".
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
HOST=root@static.64.40.140.128.clients.your-server.de
|
||||||
|
DIR=/mnt/HC_Volume_102040804/srv/game-village-politics-backend
|
||||||
|
REPO=ssh://git@git.blax.at:222/blax-software/game-village-politics-backend.git
|
||||||
|
URL=https://server-village.blax.at
|
||||||
|
WS=https://ws-server-village.blax.at/app/village-politics
|
||||||
|
|
||||||
|
cd "$(dirname "$0")/.."
|
||||||
|
if [ -n "$(git status --porcelain)" ]; then
|
||||||
|
echo "Uncommitted changes: commit and push first." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
git fetch -q origin
|
||||||
|
LOCAL=$(git rev-parse HEAD)
|
||||||
|
REMOTE=$(git rev-parse origin/master)
|
||||||
|
if [ "$LOCAL" != "$REMOTE" ]; then
|
||||||
|
echo "HEAD ${LOCAL:0:7} is not origin/master ${REMOTE:0:7}: push (or pull) first." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "==> Deploying ${LOCAL:0:7} to edgerealm"
|
||||||
|
ssh -o BatchMode=yes "$HOST" "[ -d $DIR ] || git clone -q $REPO $DIR"
|
||||||
|
ssh -o BatchMode=yes "$HOST" "cd $DIR && ./deploy.sh 2>&1" | { grep -E '^==>|ERROR|Error|FAIL' || true; }
|
||||||
|
|
||||||
|
DEPLOYED=$(ssh -o BatchMode=yes "$HOST" "cd $DIR && git rev-parse HEAD")
|
||||||
|
if [ "$DEPLOYED" != "$LOCAL" ]; then
|
||||||
|
echo "Server is on ${DEPLOYED:0:7}, expected ${LOCAL:0:7}." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# /up is Laravel's health route; the WS server answers an upgrade with 101.
|
||||||
|
for _ in $(seq 1 20); do
|
||||||
|
UP=$(curl -s -o /dev/null -w '%{http_code}' "$URL/up" || true)
|
||||||
|
WSCODE=$(curl -s -o /dev/null -w '%{http_code}' --http1.1 --max-time 3 \
|
||||||
|
-H 'Connection: Upgrade' -H 'Upgrade: websocket' -H 'Sec-WebSocket-Version: 13' \
|
||||||
|
-H 'Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==' "$WS" || true)
|
||||||
|
if [ "$UP" = 200 ] && [ "$WSCODE" = 101 ]; then
|
||||||
|
echo "Live: $URL at ${LOCAL:0:7}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
sleep 3
|
||||||
|
done
|
||||||
|
echo "Deployed ${LOCAL:0:7}, but $URL/up answers $UP and the WS upgrade $WSCODE." >&2
|
||||||
|
exit 1
|
||||||
Loading…
Reference in New Issue