Some checks failed
Build and Deploy / build-and-deploy (push) Has been cancelled
Phase 1 - Relations service (internal): owns ContainerRelation, exposes get-children data + attach/detach-child actions. Retargeted events, blog, market callers from cart to relations. Phase 2 - Likes service (internal): unified Like model replaces ProductLike and PostLike with generic target_type/target_slug/target_id. Exposes is-liked, liked-slugs, liked-ids data + toggle action. Phase 3 - PageConfig → blog: moved ownership to blog with direct DB queries, removed proxy endpoints from cart. Phase 4 - Orders service (public): owns Order/OrderItem + SumUp checkout flow. Cart checkout now delegates to orders via create-order action. Webhook/return routes and reconciliation moved to orders. Phase 5 - Infrastructure: docker-compose, deploy.sh, Dockerfiles updated for all 3 new services. Added orders_url helper and factory model imports. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
62 lines
2.0 KiB
Bash
62 lines
2.0 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Optional: wait for Postgres to be reachable
|
|
if [[ -n "${DATABASE_HOST:-}" && -n "${DATABASE_PORT:-}" ]]; then
|
|
echo "Waiting for Postgres at ${DATABASE_HOST}:${DATABASE_PORT}..."
|
|
for i in {1..60}; do
|
|
(echo > /dev/tcp/${DATABASE_HOST}/${DATABASE_PORT}) >/dev/null 2>&1 && break || true
|
|
sleep 1
|
|
done
|
|
fi
|
|
|
|
# Create own database + run own migrations
|
|
if [[ "${RUN_MIGRATIONS:-}" == "true" && -n "${ALEMBIC_DATABASE_URL:-}" ]]; then
|
|
python3 -c "
|
|
import os, re
|
|
url = os.environ['ALEMBIC_DATABASE_URL']
|
|
m = re.match(r'postgresql\+\w+://([^:]+):([^@]+)@([^:]+):(\d+)/(.+)', url)
|
|
if not m:
|
|
print('Could not parse ALEMBIC_DATABASE_URL, skipping DB creation')
|
|
exit(0)
|
|
user, password, host, port, dbname = m.groups()
|
|
|
|
import psycopg
|
|
conn = psycopg.connect(
|
|
f'postgresql://{user}:{password}@{host}:{port}/postgres',
|
|
autocommit=True,
|
|
)
|
|
cur = conn.execute('SELECT 1 FROM pg_database WHERE datname = %s', (dbname,))
|
|
if not cur.fetchone():
|
|
conn.execute(f'CREATE DATABASE {dbname}')
|
|
print(f'Created database {dbname}')
|
|
else:
|
|
print(f'Database {dbname} already exists')
|
|
conn.close()
|
|
" || echo "DB creation failed (non-fatal), continuing..."
|
|
|
|
echo "Running orders Alembic migrations..."
|
|
if [ -d orders ]; then (cd orders && alembic upgrade head); else alembic upgrade head; fi
|
|
fi
|
|
|
|
# Clear Redis page cache on deploy
|
|
if [[ -n "${REDIS_URL:-}" && "${REDIS_URL}" != "no" ]]; then
|
|
echo "Flushing Redis cache..."
|
|
python3 -c "
|
|
import redis, os
|
|
r = redis.from_url(os.environ['REDIS_URL'])
|
|
r.flushdb()
|
|
print('Redis cache cleared.')
|
|
" || echo "Redis flush failed (non-fatal), continuing..."
|
|
fi
|
|
|
|
# Start the app
|
|
RELOAD_FLAG=""
|
|
if [[ "${RELOAD:-}" == "true" ]]; then
|
|
RELOAD_FLAG="--reload"
|
|
echo "Starting Hypercorn (${APP_MODULE:-app:app}) with auto-reload..."
|
|
else
|
|
echo "Starting Hypercorn (${APP_MODULE:-app:app})..."
|
|
fi
|
|
PYTHONUNBUFFERED=1 exec hypercorn "${APP_MODULE:-app:app}" --bind 0.0.0.0:${PORT:-8000} --workers ${WORKERS:-2} --keep-alive 75 ${RELOAD_FLAG}
|