Update deployment YAML

This commit is contained in:
Eric Gullickson
2025-12-18 12:07:47 -06:00
parent c6e187e29e
commit 72e23a8ba0

View File

@@ -12,9 +12,7 @@ variables:
DOCKER_COMPOSE_FILE: docker-compose.yml DOCKER_COMPOSE_FILE: docker-compose.yml
DOCKER_COMPOSE_PROD_FILE: docker-compose.prod.yml DOCKER_COMPOSE_PROD_FILE: docker-compose.prod.yml
# ------------------------------------------------------------------------------
# Validate Stage - Check prerequisites # Validate Stage - Check prerequisites
# ------------------------------------------------------------------------------
validate: validate:
stage: validate stage: validate
only: only:
@@ -23,26 +21,20 @@ validate:
- echo "==========================================" - echo "=========================================="
- echo "Validating deployment prerequisites..." - echo "Validating deployment prerequisites..."
- echo "==========================================" - echo "=========================================="
- echo "Checking Docker..." - echo "Checking Docker..."
- docker info > /dev/null 2>&1 || (echo "ERROR: Docker not accessible" && exit 1) - 'docker info > /dev/null 2>&1 || (echo "ERROR: Docker not accessible" && exit 1)'
- echo "OK: Docker is accessible" - echo "OK Docker is accessible"
- echo "Checking Docker Compose..." - echo "Checking Docker Compose..."
- docker compose version > /dev/null 2>&1 || (echo "ERROR: Docker Compose not available" && exit 1) - 'docker compose version > /dev/null 2>&1 || (echo "ERROR: Docker Compose not available" && exit 1)'
- echo "OK: Docker Compose is available" - echo "OK Docker Compose is available"
- echo "Checking deployment path..." - echo "Checking deployment path..."
- test -d "$DEPLOY_PATH" || (echo "ERROR: DEPLOY_PATH ($DEPLOY_PATH) not found" && exit 1) - 'test -d "$DEPLOY_PATH" || (echo "ERROR: DEPLOY_PATH not found" && exit 1)'
- echo "OK: Deployment path exists" - echo "OK Deployment path exists"
- echo "==========================================" - echo "=========================================="
- echo "Validation complete" - echo "Validation complete"
- echo "==========================================" - echo "=========================================="
# ------------------------------------------------------------------------------
# Build Stage - Build Docker images # Build Stage - Build Docker images
# ------------------------------------------------------------------------------
build: build:
stage: build stage: build
only: only:
@@ -51,23 +43,17 @@ build:
- echo "==========================================" - echo "=========================================="
- echo "Building Docker images..." - echo "Building Docker images..."
- echo "==========================================" - echo "=========================================="
- cd "$DEPLOY_PATH" - cd "$DEPLOY_PATH"
- echo "Pulling latest code..." - echo "Pulling latest code..."
- git fetch origin main - git fetch origin main
- git reset --hard origin/main - git reset --hard origin/main
- echo "Building images..." - echo "Building images..."
- docker compose -f $DOCKER_COMPOSE_FILE build --no-cache - docker compose -f $DOCKER_COMPOSE_FILE build --no-cache
- echo "==========================================" - echo "=========================================="
- echo "Build complete" - echo "Build complete"
- echo "==========================================" - echo "=========================================="
# ------------------------------------------------------------------------------
# Deploy Stage - Inject secrets and deploy services # Deploy Stage - Inject secrets and deploy services
# ------------------------------------------------------------------------------
deploy: deploy:
stage: deploy stage: deploy
only: only:
@@ -79,47 +65,29 @@ deploy:
- echo "==========================================" - echo "=========================================="
- echo "Deploying MotoVaultPro..." - echo "Deploying MotoVaultPro..."
- echo "==========================================" - echo "=========================================="
- cd "$DEPLOY_PATH" - cd "$DEPLOY_PATH"
- echo "Step 1/6 Injecting secrets..."
# Inject secrets from GitLab File variables
- echo "Step 1/6: Injecting secrets..."
- chmod +x scripts/inject-secrets.sh - chmod +x scripts/inject-secrets.sh
- ./scripts/inject-secrets.sh - ./scripts/inject-secrets.sh
- echo "Step 2/6 Stopping existing services..."
# Stop existing services gracefully
- echo "Step 2/6: Stopping existing services..."
- docker compose -f $DOCKER_COMPOSE_FILE -f $DOCKER_COMPOSE_PROD_FILE down --timeout 30 || true - docker compose -f $DOCKER_COMPOSE_FILE -f $DOCKER_COMPOSE_PROD_FILE down --timeout 30 || true
- echo "Step 3/6 Pulling base images..."
# Pull latest base images
- echo "Step 3/6: Pulling base images..."
- docker compose -f $DOCKER_COMPOSE_FILE pull - docker compose -f $DOCKER_COMPOSE_FILE pull
- echo "Step 4/6 Starting database services..."
# Start database services first for migrations
- echo "Step 4/6: Starting database services..."
- docker compose -f $DOCKER_COMPOSE_FILE -f $DOCKER_COMPOSE_PROD_FILE up -d mvp-postgres mvp-redis - docker compose -f $DOCKER_COMPOSE_FILE -f $DOCKER_COMPOSE_PROD_FILE up -d mvp-postgres mvp-redis
- echo "Waiting for database to be ready..." - echo "Waiting for database to be ready..."
- sleep 15 - sleep 15
- echo "Step 5/6 Running database migrations..."
# Run database migrations - docker compose -f $DOCKER_COMPOSE_FILE run --rm mvp-backend npm run migrate || echo "Migration skipped"
- echo "Step 5/6: Running database migrations..." - echo "Step 6/6 Starting all services..."
- docker compose -f $DOCKER_COMPOSE_FILE run --rm mvp-backend npm run migrate || echo "Migration command not found or no migrations to run"
# Start all services
- echo "Step 6/6: Starting all services..."
- docker compose -f $DOCKER_COMPOSE_FILE -f $DOCKER_COMPOSE_PROD_FILE up -d - docker compose -f $DOCKER_COMPOSE_FILE -f $DOCKER_COMPOSE_PROD_FILE up -d
# Wait for services to start
- echo "Waiting for services to initialize..." - echo "Waiting for services to initialize..."
- sleep 30 - sleep 30
- echo "==========================================" - echo "=========================================="
- echo "Deployment complete" - echo "Deployment complete"
- echo "==========================================" - echo "=========================================="
# ------------------------------------------------------------------------------
# Verify Stage - Health checks # Verify Stage - Health checks
# ------------------------------------------------------------------------------
verify: verify:
stage: verify stage: verify
only: only:
@@ -128,10 +96,7 @@ verify:
- echo "==========================================" - echo "=========================================="
- echo "Verifying deployment..." - echo "Verifying deployment..."
- echo "==========================================" - echo "=========================================="
- cd "$DEPLOY_PATH" - cd "$DEPLOY_PATH"
# Check all containers are running
- echo "Checking container status..." - echo "Checking container status..."
- | - |
FAILED=0 FAILED=0
@@ -149,8 +114,6 @@ verify:
echo "One or more services failed to start" echo "One or more services failed to start"
exit 1 exit 1
fi fi
# Check backend health endpoint
- echo "Checking backend health..." - echo "Checking backend health..."
- | - |
HEALTH_OK=0 HEALTH_OK=0
@@ -168,8 +131,6 @@ verify:
docker logs mvp-backend --tail 100 docker logs mvp-backend --tail 100
exit 1 exit 1
fi fi
# Check frontend is accessible
- echo "Checking frontend..." - echo "Checking frontend..."
- | - |
if curl -sf http://localhost:3000 > /dev/null 2>&1; then if curl -sf http://localhost:3000 > /dev/null 2>&1; then
@@ -177,8 +138,6 @@ verify:
else else
echo "WARNING: Frontend check failed (might need Traefik routing)" echo "WARNING: Frontend check failed (might need Traefik routing)"
fi fi
- echo "==========================================" - echo "=========================================="
- echo "Deployment verified successfully!" - echo "Deployment verified successfully!"
- echo "==========================================" - echo "=========================================="
- echo "Application URL: https://motovaultpro.com"