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