name: Deploy to Production on: push: branches: - main jobs: deploy: runs-on: ubuntu-latest env: COMPOSE_PROJECT_NAME: voxblog steps: - name: Checkout code uses: actions/checkout@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - name: Ensure .env file exists run: | if [ ! -f .env ]; then echo ".env file is missing. Add it to the repository or provision it before deployment." exit 1 fi - name: Stop existing containers run: docker-compose down || true - name: Build images run: docker-compose build --no-cache - name: Start containers run: docker-compose up -d - name: Wait for services run: sleep 15 - name: Run database migrations run: docker-compose exec -T api pnpm run drizzle:migrate || echo "Migration skipped" - name: Health check API run: | for i in {1..10}; do if curl -f http://localhost:3301/api/health; then echo "API is healthy" exit 0 fi echo "Waiting for API... ($i/10)" sleep 5 done echo "API health check failed" docker-compose logs api exit 1 - name: Health check Admin run: | if curl -f http://localhost:3300; then echo "Admin is healthy" else echo "Admin health check failed" docker-compose logs admin exit 1 fi - name: Clean up old images run: docker image prune -af --filter "until=24h" - name: Deployment summary run: | echo "✅ Deployment successful!" echo "Services:" docker-compose ps