chore: Enhance Gitea deployment workflow for database and Redis management
Some checks failed
Dev Deployment (Zero Downtime) / deploy-dev (push) Failing after 6m40s
Some checks failed
Dev Deployment (Zero Downtime) / deploy-dev (push) Failing after 6m40s
- Added logic to start PostgreSQL and Redis containers if they are not already running. - Implemented checks to ensure the existence of necessary Docker networks. - Updated environment variables for database and Redis connections. - Improved feedback messages for better clarity during the deployment process.
This commit is contained in:
@@ -57,10 +57,45 @@ 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
|
||||||
|
echo "🗄️ Starting database and Redis..."
|
||||||
|
COMPOSE_FILE="docker-compose.dev.minimal.yml"
|
||||||
|
|
||||||
|
# Check if DB container exists
|
||||||
|
if ! docker ps -a --format "{{.Names}}" | grep -q "portfolio_postgres_dev"; then
|
||||||
|
echo "📦 Starting PostgreSQL container..."
|
||||||
|
docker compose -f $COMPOSE_FILE up -d postgres
|
||||||
|
else
|
||||||
|
echo "✅ PostgreSQL container exists, ensuring it's running..."
|
||||||
|
docker start portfolio_postgres_dev 2>/dev/null || docker compose -f $COMPOSE_FILE up -d postgres
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if Redis container exists
|
||||||
|
if ! docker ps -a --format "{{.Names}}" | grep -q "portfolio_redis_dev"; then
|
||||||
|
echo "📦 Starting Redis container..."
|
||||||
|
docker compose -f $COMPOSE_FILE up -d redis
|
||||||
|
else
|
||||||
|
echo "✅ Redis container exists, ensuring it's running..."
|
||||||
|
docker start portfolio_redis_dev 2>/dev/null || docker compose -f $COMPOSE_FILE up -d redis
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 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 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 REDIS_URL="redis://portfolio_redis_dev: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}
|
||||||
@@ -158,8 +193,8 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure proxy network exists
|
# Ensure networks exist
|
||||||
echo "🌐 Checking for proxy network..."
|
echo "🌐 Checking for networks..."
|
||||||
if ! docker network inspect proxy >/dev/null 2>&1; then
|
if ! docker network inspect proxy >/dev/null 2>&1; then
|
||||||
echo "⚠️ Proxy network not found, creating it..."
|
echo "⚠️ Proxy network not found, creating it..."
|
||||||
docker network create proxy 2>/dev/null || echo "Network might already exist or creation failed"
|
docker network create proxy 2>/dev/null || echo "Network might already exist or creation failed"
|
||||||
@@ -167,16 +202,28 @@ jobs:
|
|||||||
echo "✅ Proxy network exists"
|
echo "✅ Proxy network exists"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! docker network inspect portfolio_dev >/dev/null 2>&1; then
|
||||||
|
echo "⚠️ Portfolio dev network not found, creating it..."
|
||||||
|
docker network create portfolio_dev 2>/dev/null || echo "Network might already exist or creation failed"
|
||||||
|
else
|
||||||
|
echo "✅ Portfolio dev network exists"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Connect proxy network to portfolio_dev network if needed
|
||||||
|
# (This allows the app to access both proxy and DB/Redis)
|
||||||
|
|
||||||
# Start new container with updated image
|
# Start new container with updated image
|
||||||
echo "🆕 Starting new dev container..."
|
echo "🆕 Starting new dev container..."
|
||||||
docker run -d \
|
docker run -d \
|
||||||
--name $CONTAINER_NAME \
|
--name $CONTAINER_NAME \
|
||||||
--restart unless-stopped \
|
--restart unless-stopped \
|
||||||
--network proxy \
|
--network portfolio_dev \
|
||||||
-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} \
|
||||||
-e NEXT_PUBLIC_BASE_URL=${NEXT_PUBLIC_BASE_URL_DEV:-https://dev.dk0.dev} \
|
-e NEXT_PUBLIC_BASE_URL=${NEXT_PUBLIC_BASE_URL_DEV:-https://dev.dk0.dev} \
|
||||||
|
-e DATABASE_URL=${DATABASE_URL} \
|
||||||
|
-e REDIS_URL=${REDIS_URL} \
|
||||||
-e MY_EMAIL=${MY_EMAIL} \
|
-e MY_EMAIL=${MY_EMAIL} \
|
||||||
-e MY_INFO_EMAIL=${MY_INFO_EMAIL} \
|
-e MY_INFO_EMAIL=${MY_INFO_EMAIL} \
|
||||||
-e MY_PASSWORD=${MY_PASSWORD} \
|
-e MY_PASSWORD=${MY_PASSWORD} \
|
||||||
@@ -187,6 +234,10 @@ jobs:
|
|||||||
-e N8N_SECRET_TOKEN=${N8N_SECRET_TOKEN:-''} \
|
-e N8N_SECRET_TOKEN=${N8N_SECRET_TOKEN:-''} \
|
||||||
$IMAGE_NAME
|
$IMAGE_NAME
|
||||||
|
|
||||||
|
# Connect container to proxy network as well (for external access)
|
||||||
|
echo "🔗 Connecting container to proxy network..."
|
||||||
|
docker network connect proxy $CONTAINER_NAME 2>/dev/null || echo "Container might already be connected to proxy network"
|
||||||
|
|
||||||
# Wait for new container to be healthy
|
# Wait for new container to be healthy
|
||||||
echo "⏳ Waiting for new container to be healthy..."
|
echo "⏳ Waiting for new container to be healthy..."
|
||||||
HEALTH_CHECK_PASSED=false
|
HEALTH_CHECK_PASSED=false
|
||||||
@@ -232,6 +283,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
|
||||||
|
REDIS_URL: redis://portfolio_redis_dev: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