Deploy-Stack für Portainer und Fix für die Migrationen
Die Migration brach im Container nach einer halben Stunde mit "Knex: Timeout acquiring a connection" ab: Ohne Angabe erlaubt Knex zehn Verbindungen, bei einer Migration meldet sich aber jedes der rund 30 Module gleichzeitig. Pool jetzt auf 30 gesetzt. Dazu der Stack für Portainer: Postgres, Redis, ein einmaliger Migrationsdienst, Backend und Frontend. Die Images kommen fertig aus der Gitea-Registry, gebaut wird auf dem Entwicklungsrechner — ein Medusa-Build auf dem Orange Pi dauert eine halbe Stunde. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,13 @@ const smtpEnabled = Boolean(process.env.SMTP_HOST && process.env.MAIL_FROM)
|
|||||||
module.exports = defineConfig({
|
module.exports = defineConfig({
|
||||||
projectConfig: {
|
projectConfig: {
|
||||||
databaseUrl: process.env.DATABASE_URL,
|
databaseUrl: process.env.DATABASE_URL,
|
||||||
|
// Ohne Angabe erlaubt Knex nur 10 Verbindungen. Bei einer Migration
|
||||||
|
// meldet sich aber jedes der rund 30 Module gleichzeitig, und der Lauf
|
||||||
|
// bricht nach einer halben Stunde mit "Timeout acquiring a connection" ab.
|
||||||
|
// Postgres erlaubt standardmäßig 100 Verbindungen, 30 sind also sicher.
|
||||||
|
databaseDriverOptions: {
|
||||||
|
pool: { min: 2, max: 30 },
|
||||||
|
},
|
||||||
redisUrl: process.env.REDIS_URL,
|
redisUrl: process.env.REDIS_URL,
|
||||||
http: {
|
http: {
|
||||||
storeCors: process.env.STORE_CORS!,
|
storeCors: process.env.STORE_CORS!,
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
# Stack für Portainer auf dem Orange Pi.
|
||||||
|
#
|
||||||
|
# Die Images kommen fertig aus der Gitea-Registry, hier wird nichts gebaut —
|
||||||
|
# ein Medusa-Build auf dem Pi dauert eine halbe Stunde, auf dem Mac drei
|
||||||
|
# Minuten. Gebaut und hochgeladen wird mit ./deploy.sh.
|
||||||
|
#
|
||||||
|
# Alles Veränderliche liegt außerhalb der Images:
|
||||||
|
# - Datenbank und Uploads in Volumes
|
||||||
|
# - Zugangsdaten als Variablen des Stacks (in Portainer unter "Environment")
|
||||||
|
#
|
||||||
|
# Pflichtvariablen: IMAGE_TAG, POSTGRES_PASSWORD, JWT_SECRET, COOKIE_SECRET,
|
||||||
|
# MEDUSA_BACKEND_URL, STORE_CORS, ADMIN_CORS, AUTH_CORS
|
||||||
|
|
||||||
|
name: place4bees
|
||||||
|
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres:16-alpine
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: medusa
|
||||||
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||||
|
POSTGRES_DB: medusa
|
||||||
|
volumes:
|
||||||
|
- postgres_data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U medusa"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 10
|
||||||
|
|
||||||
|
redis:
|
||||||
|
image: redis:7-alpine
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- redis_data:/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "redis-cli", "ping"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 10
|
||||||
|
|
||||||
|
# Läuft bei jedem Deploy einmal und beendet sich wieder. Als eigener Dienst,
|
||||||
|
# damit im Portainer sofort zu sehen ist, ob die Migration durchlief — sonst
|
||||||
|
# steckt der Fehler in den Logs des Backends.
|
||||||
|
migrate:
|
||||||
|
image: ${REGISTRY:-git.place4bees.com/place4bees}/backend:${IMAGE_TAG:-latest}
|
||||||
|
restart: "no"
|
||||||
|
command: ["npx", "medusa", "db:migrate"]
|
||||||
|
depends_on:
|
||||||
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
|
environment:
|
||||||
|
DATABASE_URL: postgres://medusa:${POSTGRES_PASSWORD}@postgres:5432/medusa
|
||||||
|
REDIS_URL: redis://redis:6379
|
||||||
|
JWT_SECRET: ${JWT_SECRET}
|
||||||
|
COOKIE_SECRET: ${COOKIE_SECRET}
|
||||||
|
|
||||||
|
backend:
|
||||||
|
image: ${REGISTRY:-git.place4bees.com/place4bees}/backend:${IMAGE_TAG:-latest}
|
||||||
|
restart: unless-stopped
|
||||||
|
depends_on:
|
||||||
|
migrate:
|
||||||
|
condition: service_completed_successfully
|
||||||
|
redis:
|
||||||
|
condition: service_healthy
|
||||||
|
# Das Image migriert sonst beim Start noch einmal — das macht hier der
|
||||||
|
# Dienst oben.
|
||||||
|
command: ["npx", "medusa", "start"]
|
||||||
|
environment:
|
||||||
|
DATABASE_URL: postgres://medusa:${POSTGRES_PASSWORD}@postgres:5432/medusa
|
||||||
|
REDIS_URL: redis://redis:6379
|
||||||
|
JWT_SECRET: ${JWT_SECRET}
|
||||||
|
COOKIE_SECRET: ${COOKIE_SECRET}
|
||||||
|
MEDUSA_BACKEND_URL: ${MEDUSA_BACKEND_URL}
|
||||||
|
STORE_CORS: ${STORE_CORS}
|
||||||
|
ADMIN_CORS: ${ADMIN_CORS}
|
||||||
|
AUTH_CORS: ${AUTH_CORS}
|
||||||
|
# Bleiben leer, solange die Zugänge fehlen. Die Module melden sich dann
|
||||||
|
# gar nicht erst an, statt beim Start zu scheitern.
|
||||||
|
DHL_API_KEY: ${DHL_API_KEY:-}
|
||||||
|
DHL_USERNAME: ${DHL_USERNAME:-}
|
||||||
|
DHL_PASSWORD: ${DHL_PASSWORD:-}
|
||||||
|
DHL_BILLING_NUMBER: ${DHL_BILLING_NUMBER:-}
|
||||||
|
DHL_SHIPPER_NAME: ${DHL_SHIPPER_NAME:-}
|
||||||
|
DHL_SHIPPER_STREET: ${DHL_SHIPPER_STREET:-}
|
||||||
|
DHL_SHIPPER_POSTAL_CODE: ${DHL_SHIPPER_POSTAL_CODE:-}
|
||||||
|
DHL_SHIPPER_CITY: ${DHL_SHIPPER_CITY:-}
|
||||||
|
DHL_SHIPPER_COUNTRY: ${DHL_SHIPPER_COUNTRY:-}
|
||||||
|
MOLLIE_API_KEY: ${MOLLIE_API_KEY:-}
|
||||||
|
SMTP_HOST: ${SMTP_HOST:-}
|
||||||
|
SMTP_PORT: ${SMTP_PORT:-}
|
||||||
|
SMTP_USER: ${SMTP_USER:-}
|
||||||
|
SMTP_PASSWORD: ${SMTP_PASSWORD:-}
|
||||||
|
MAIL_FROM: ${MAIL_FROM:-}
|
||||||
|
volumes:
|
||||||
|
- medusa_uploads:/app/static
|
||||||
|
ports:
|
||||||
|
- "${BACKEND_PORT:-9001}:9001"
|
||||||
|
|
||||||
|
frontend:
|
||||||
|
image: ${REGISTRY:-git.place4bees.com/place4bees}/frontend:${IMAGE_TAG:-latest}
|
||||||
|
restart: unless-stopped
|
||||||
|
depends_on:
|
||||||
|
- backend
|
||||||
|
ports:
|
||||||
|
- "${FRONTEND_PORT:-4321}:4321"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres_data:
|
||||||
|
redis_data:
|
||||||
|
medusa_uploads:
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Baut Backend und Frontend als arm64-Images und lädt sie in die
|
||||||
|
# Gitea-Registry. Auf dem Orange Pi zieht Portainer sie dann nur noch.
|
||||||
|
#
|
||||||
|
# ./deploy.sh → baut und lädt hoch
|
||||||
|
# ./deploy.sh --nur-bauen → baut, lädt nicht hoch
|
||||||
|
#
|
||||||
|
# Vorher einmalig anmelden:
|
||||||
|
# docker login git.place4bees.com -u <benutzer>
|
||||||
|
#
|
||||||
|
# Die Adresse des Backends wird beim Bauen fest ins Frontend geschrieben,
|
||||||
|
# Astro kennt sie zur Laufzeit nicht mehr. Für eine andere Umgebung also
|
||||||
|
# BACKEND_URL setzen und neu bauen.
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
REGISTRY="${REGISTRY:-git.place4bees.com/place4bees}"
|
||||||
|
BACKEND_URL="${BACKEND_URL:-https://test.place4bees.com}"
|
||||||
|
PUBLISHABLE_KEY="${PUBLISHABLE_KEY:-$(grep -h PUBLIC_MEDUSA_PUBLISHABLE_KEY frontend/.env | cut -d= -f2)}"
|
||||||
|
# Solange Änderungen nicht eingecheckt sind, taugt die Commit-Nummer nicht als
|
||||||
|
# Tag — sie würde einen Stand behaupten, der so nirgends liegt.
|
||||||
|
TAG="$(git rev-parse --short HEAD)"
|
||||||
|
if [ -n "$(git status --porcelain)" ]; then
|
||||||
|
TAG="$TAG-dirty-$(date +%Y%m%d-%H%M)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
nur_bauen=false
|
||||||
|
[[ "${1:-}" == "--nur-bauen" ]] && nur_bauen=true
|
||||||
|
|
||||||
|
echo "Registry: $REGISTRY"
|
||||||
|
echo "Tag: $TAG (zusätzlich latest)"
|
||||||
|
echo "Backend-URL: $BACKEND_URL"
|
||||||
|
echo
|
||||||
|
|
||||||
|
bauen() {
|
||||||
|
local name="$1" pfad="$2"; shift 2
|
||||||
|
echo "→ $name"
|
||||||
|
docker buildx build \
|
||||||
|
--platform linux/arm64 \
|
||||||
|
--tag "$REGISTRY/$name:$TAG" \
|
||||||
|
--tag "$REGISTRY/$name:latest" \
|
||||||
|
"$@" \
|
||||||
|
$([ "$nur_bauen" = true ] && echo --load || echo --push) \
|
||||||
|
"$pfad"
|
||||||
|
}
|
||||||
|
|
||||||
|
bauen backend ./backend
|
||||||
|
bauen frontend ./frontend \
|
||||||
|
--build-arg "PUBLIC_MEDUSA_BACKEND_URL=$BACKEND_URL" \
|
||||||
|
--build-arg "PUBLIC_MEDUSA_PUBLISHABLE_KEY=$PUBLISHABLE_KEY"
|
||||||
|
|
||||||
|
echo
|
||||||
|
if [ "$nur_bauen" = true ]; then
|
||||||
|
echo "Fertig, nichts hochgeladen."
|
||||||
|
else
|
||||||
|
echo "Fertig. In Portainer IMAGE_TAG auf $TAG setzen und den Stack neu laden."
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user