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