fix: use production DB/Redis for dev deployment instead of non-existent dev containers
Some checks failed
Gitea CI / test-build (push) Has been cancelled

The dev-deploy workflow was trying to spin up separate portfolio_postgres_dev
and portfolio_redis_dev containers, which don't exist on the server. Now it
reuses the existing production portfolio-postgres and portfolio-redis on
the portfolio_net network.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-03-04 15:09:04 +01:00
parent 74b73d1b84
commit 30d0e597c2

View File

@@ -57,49 +57,27 @@ jobs:
# Check for existing container (running or stopped)
EXISTING_CONTAINER=$(docker ps -aq -f name=$CONTAINER_NAME || echo "")
# Start DB and Redis if not running
echo "🗄️ Starting database and Redis..."
COMPOSE_FILE="docker-compose.dev.minimal.yml"
# Reuse production PostgreSQL and Redis (no separate dev instances needed)
echo "🗄️ Verifying production database and Redis are running..."
# Stop and remove existing containers to ensure clean start with correct architecture
echo "🧹 Cleaning up existing containers..."
docker stop portfolio_postgres_dev portfolio_redis_dev 2>/dev/null || true
docker rm portfolio_postgres_dev portfolio_redis_dev 2>/dev/null || true
# Remove old images to force re-pull with correct architecture
echo "🔄 Removing old images to force re-pull..."
docker rmi postgres:16-alpine redis:7-alpine 2>/dev/null || true
# Ensure networks exist before compose starts (network is external)
# Ensure networks exist
echo "🌐 Ensuring networks exist..."
docker network create portfolio_dev 2>/dev/null || true
docker network create portfolio_net 2>/dev/null || true
docker network create proxy 2>/dev/null || true
# Pull images with correct architecture (Docker will auto-detect)
echo "📥 Pulling images for current architecture..."
docker compose -f $COMPOSE_FILE pull postgres redis
# Start containers
echo "📦 Starting PostgreSQL and Redis containers..."
docker compose -f $COMPOSE_FILE up -d postgres redis
# Wait for DB to be ready
echo "⏳ Waiting for database to be ready..."
for i in {1..30}; do
if docker exec portfolio_postgres_dev pg_isready -U portfolio_user -d portfolio_dev >/dev/null 2>&1; then
echo "✅ Database is ready!"
break
# Verify production DB is reachable
if docker exec portfolio-postgres pg_isready -U portfolio_user -d portfolio_db >/dev/null 2>&1; then
echo "✅ Production database is ready!"
else
echo "⚠️ Production database not reachable, app will use fallbacks"
fi
echo "⏳ Waiting for database... ($i/30)"
sleep 1
done
# Export environment variables
# Export environment variables (pointing to production DB/Redis)
export NODE_ENV=production
export LOG_LEVEL=${LOG_LEVEL:-debug}
export NEXT_PUBLIC_BASE_URL=${NEXT_PUBLIC_BASE_URL_DEV:-https://dev.dk0.dev}
export DATABASE_URL="postgresql://portfolio_user:portfolio_dev_pass@portfolio_postgres_dev:5432/portfolio_dev?schema=public"
export REDIS_URL="redis://portfolio_redis_dev:6379"
export DATABASE_URL="postgresql://portfolio_user:portfolio_pass@portfolio-postgres:5432/portfolio_db?schema=public"
export REDIS_URL="redis://portfolio-redis:6379"
export MY_EMAIL=${MY_EMAIL}
export MY_INFO_EMAIL=${MY_INFO_EMAIL}
export MY_PASSWORD=${MY_PASSWORD}
@@ -202,7 +180,7 @@ jobs:
docker run -d \
--name $CONTAINER_NAME \
--restart unless-stopped \
--network portfolio_dev \
--network portfolio_net \
-p ${HEALTH_PORT}:3000 \
-e NODE_ENV=production \
-e LOG_LEVEL=${LOG_LEVEL:-debug} \
@@ -268,8 +246,8 @@ jobs:
NODE_ENV: production
LOG_LEVEL: ${{ vars.LOG_LEVEL || 'debug' }}
NEXT_PUBLIC_BASE_URL_DEV: ${{ vars.NEXT_PUBLIC_BASE_URL_DEV || 'https://dev.dk0.dev' }}
DATABASE_URL: postgresql://portfolio_user:portfolio_dev_pass@portfolio_postgres_dev:5432/portfolio_dev?schema=public
REDIS_URL: redis://portfolio_redis_dev:6379
DATABASE_URL: postgresql://portfolio_user:portfolio_pass@portfolio-postgres:5432/portfolio_db?schema=public
REDIS_URL: redis://portfolio-redis:6379
MY_EMAIL: ${{ vars.MY_EMAIL }}
MY_INFO_EMAIL: ${{ vars.MY_INFO_EMAIL }}
MY_PASSWORD: ${{ secrets.MY_PASSWORD }}