🔧 Implement deployment fixes and enhance Gitea workflows
- Created `DEPLOYMENT-FIXES.md` to document issues and solutions for Gitea Actions.
- Fixed Dockerfile path for standalone build.
- Enhanced `gitea-deploy.sh` with improved environment variable handling and extended health check timeouts.
- Introduced `gitea-deploy-simple.sh` for simplified deployments without database dependencies.
- Updated Next.js configuration to resolve build issues.
- Improved health check logic and error handling across all Gitea workflows.
✅ These changes enhance deployment reliability and provide better debugging information.
This commit is contained in:
@@ -222,12 +222,64 @@ jobs:
|
||||
|
||||
- name: Wait for container to be ready
|
||||
run: |
|
||||
sleep 10
|
||||
timeout 60 bash -c 'until curl -f http://localhost:3000/api/health; do sleep 2; done'
|
||||
echo "⏳ Waiting for container to be ready..."
|
||||
sleep 15
|
||||
|
||||
# Check if container is actually running
|
||||
if ! docker ps --filter "name=portfolio-app" --format "{{.Names}}" | grep -q "portfolio-app"; then
|
||||
echo "❌ Container failed to start"
|
||||
echo "Container logs:"
|
||||
docker logs portfolio-app --tail=50
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Wait for health check with better error handling
|
||||
echo "🏥 Performing health check..."
|
||||
for i in {1..40}; do
|
||||
if curl -f http://localhost:3000/api/health > /dev/null 2>&1; then
|
||||
echo "✅ Application is healthy!"
|
||||
break
|
||||
fi
|
||||
|
||||
# Check if container is still running
|
||||
if ! docker ps --filter "name=portfolio-app" --format "{{.Names}}" | grep -q "portfolio-app"; then
|
||||
echo "❌ Container stopped during health check"
|
||||
echo "Container logs:"
|
||||
docker logs portfolio-app --tail=50
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "⏳ Health check attempt $i/40..."
|
||||
sleep 3
|
||||
done
|
||||
|
||||
# Final health check
|
||||
if ! curl -f http://localhost:3000/api/health > /dev/null 2>&1; then
|
||||
echo "❌ Health check timeout"
|
||||
echo "Container logs:"
|
||||
docker logs portfolio-app --tail=100
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Health check
|
||||
run: |
|
||||
echo "🔍 Final health verification..."
|
||||
|
||||
# Check container status
|
||||
docker ps --filter "name=portfolio-app" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
|
||||
|
||||
# Test health endpoint
|
||||
curl -f http://localhost:3000/api/health
|
||||
echo ""
|
||||
|
||||
# Test main page
|
||||
if curl -f http://localhost:3000/ > /dev/null; then
|
||||
echo "✅ Main page is accessible"
|
||||
else
|
||||
echo "❌ Main page is not accessible"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✅ Deployment successful!"
|
||||
|
||||
- name: Cleanup old images
|
||||
|
||||
143
.gitea/workflows/ci-cd-simple.yml
Normal file
143
.gitea/workflows/ci-cd-simple.yml
Normal file
@@ -0,0 +1,143 @@
|
||||
name: CI/CD Pipeline (Simple & Reliable)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ production ]
|
||||
|
||||
env:
|
||||
NODE_VERSION: '20'
|
||||
DOCKER_IMAGE: portfolio-app
|
||||
CONTAINER_NAME: portfolio-app
|
||||
|
||||
jobs:
|
||||
production:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Run linting
|
||||
run: npm run lint
|
||||
|
||||
- name: Run tests
|
||||
run: npm run test
|
||||
|
||||
- name: Build application
|
||||
run: npm run build
|
||||
|
||||
- name: Run security scan
|
||||
run: |
|
||||
echo "🔍 Running npm audit..."
|
||||
npm audit --audit-level=high || echo "⚠️ Some vulnerabilities found, but continuing..."
|
||||
|
||||
- name: Verify secrets and variables
|
||||
run: |
|
||||
echo "🔍 Verifying secrets and variables..."
|
||||
|
||||
# Check Variables
|
||||
if [ -z "${{ vars.NEXT_PUBLIC_BASE_URL }}" ]; then
|
||||
echo "❌ NEXT_PUBLIC_BASE_URL variable is missing!"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "${{ vars.MY_EMAIL }}" ]; then
|
||||
echo "❌ MY_EMAIL variable is missing!"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "${{ vars.MY_INFO_EMAIL }}" ]; then
|
||||
echo "❌ MY_INFO_EMAIL variable is missing!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check Secrets
|
||||
if [ -z "${{ secrets.MY_PASSWORD }}" ]; then
|
||||
echo "❌ MY_PASSWORD secret is missing!"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "${{ secrets.MY_INFO_PASSWORD }}" ]; then
|
||||
echo "❌ MY_INFO_PASSWORD secret is missing!"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "${{ secrets.ADMIN_BASIC_AUTH }}" ]; then
|
||||
echo "❌ ADMIN_BASIC_AUTH secret is missing!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✅ All required secrets and variables are present"
|
||||
|
||||
- name: Deploy using improved script
|
||||
run: |
|
||||
echo "🚀 Deploying using improved deployment script..."
|
||||
|
||||
# Set environment variables for the deployment script
|
||||
export MY_PASSWORD="${{ secrets.MY_PASSWORD }}"
|
||||
export MY_INFO_PASSWORD="${{ secrets.MY_INFO_PASSWORD }}"
|
||||
export ADMIN_BASIC_AUTH="${{ secrets.ADMIN_BASIC_AUTH }}"
|
||||
|
||||
# Make the script executable
|
||||
chmod +x ./scripts/gitea-deploy.sh
|
||||
|
||||
# Run the deployment script
|
||||
./scripts/gitea-deploy.sh
|
||||
env:
|
||||
NODE_ENV: ${{ vars.NODE_ENV }}
|
||||
LOG_LEVEL: ${{ vars.LOG_LEVEL }}
|
||||
NEXT_PUBLIC_BASE_URL: ${{ vars.NEXT_PUBLIC_BASE_URL }}
|
||||
NEXT_PUBLIC_UMAMI_URL: ${{ vars.NEXT_PUBLIC_UMAMI_URL }}
|
||||
NEXT_PUBLIC_UMAMI_WEBSITE_ID: ${{ vars.NEXT_PUBLIC_UMAMI_WEBSITE_ID }}
|
||||
MY_EMAIL: ${{ vars.MY_EMAIL }}
|
||||
MY_INFO_EMAIL: ${{ vars.MY_INFO_EMAIL }}
|
||||
MY_PASSWORD: ${{ secrets.MY_PASSWORD }}
|
||||
MY_INFO_PASSWORD: ${{ secrets.MY_INFO_PASSWORD }}
|
||||
ADMIN_BASIC_AUTH: ${{ secrets.ADMIN_BASIC_AUTH }}
|
||||
|
||||
- name: Final verification
|
||||
run: |
|
||||
echo "🔍 Final verification..."
|
||||
|
||||
# Wait a bit more to ensure everything is stable
|
||||
sleep 10
|
||||
|
||||
# Check if container is running
|
||||
if docker ps --filter "name=${{ env.CONTAINER_NAME }}" --format "{{.Names}}" | grep -q "${{ env.CONTAINER_NAME }}"; then
|
||||
echo "✅ Container is running"
|
||||
else
|
||||
echo "❌ Container is not running"
|
||||
docker ps -a
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check health endpoint
|
||||
if curl -f http://localhost:3000/api/health; then
|
||||
echo "✅ Health check passed"
|
||||
else
|
||||
echo "❌ Health check failed"
|
||||
echo "Container logs:"
|
||||
docker logs ${{ env.CONTAINER_NAME }} --tail=50
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check main page
|
||||
if curl -f http://localhost:3000/ > /dev/null; then
|
||||
echo "✅ Main page is accessible"
|
||||
else
|
||||
echo "❌ Main page is not accessible"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "🎉 Deployment successful!"
|
||||
|
||||
- name: Cleanup old images
|
||||
run: |
|
||||
echo "🧹 Cleaning up old images..."
|
||||
docker image prune -f
|
||||
docker system prune -f
|
||||
echo "✅ Cleanup completed"
|
||||
@@ -114,38 +114,87 @@ jobs:
|
||||
MY_INFO_PASSWORD: ${{ secrets.MY_INFO_PASSWORD }}
|
||||
ADMIN_BASIC_AUTH: ${{ secrets.ADMIN_BASIC_AUTH }}
|
||||
|
||||
- name: Wait for container to be ready
|
||||
- name: Wait for containers to be ready
|
||||
run: |
|
||||
echo "⏳ Waiting for containers to be ready..."
|
||||
sleep 15
|
||||
sleep 20
|
||||
|
||||
# Check if all containers are running
|
||||
echo "📊 Checking container status..."
|
||||
docker compose -f docker-compose.zero-downtime.yml ps
|
||||
|
||||
# Wait for application containers to be healthy
|
||||
echo "🏥 Waiting for application containers to be healthy..."
|
||||
for i in {1..30}; do
|
||||
# Check if both app containers are healthy
|
||||
if docker exec portfolio-app-1 curl -f http://localhost:3000/api/health > /dev/null 2>&1 && \
|
||||
docker exec portfolio-app-2 curl -f http://localhost:3000/api/health > /dev/null 2>&1; then
|
||||
echo "✅ Both application containers are healthy!"
|
||||
break
|
||||
fi
|
||||
echo "⏳ Waiting for application containers... ($i/30)"
|
||||
sleep 3
|
||||
done
|
||||
|
||||
# Wait for nginx to be healthy
|
||||
for i in {1..30}; do
|
||||
echo "🌐 Waiting for nginx to be healthy..."
|
||||
for i in {1..20}; do
|
||||
if curl -f http://localhost/health > /dev/null 2>&1; then
|
||||
echo "✅ Nginx is healthy!"
|
||||
break
|
||||
fi
|
||||
echo "⏳ Waiting for nginx... ($i/30)"
|
||||
echo "⏳ Waiting for nginx... ($i/20)"
|
||||
sleep 2
|
||||
done
|
||||
|
||||
- name: Health check
|
||||
run: |
|
||||
echo "🔍 Running health checks..."
|
||||
echo "🔍 Running comprehensive health checks..."
|
||||
|
||||
# Check container status
|
||||
echo "📊 Container status:"
|
||||
docker compose -f docker-compose.zero-downtime.yml ps
|
||||
|
||||
# Check individual application containers
|
||||
echo "🏥 Checking individual application containers..."
|
||||
if docker exec portfolio-app-1 curl -f http://localhost:3000/api/health; then
|
||||
echo "✅ portfolio-app-1 health check passed!"
|
||||
else
|
||||
echo "❌ portfolio-app-1 health check failed!"
|
||||
docker logs portfolio-app-1 --tail=20
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if docker exec portfolio-app-2 curl -f http://localhost:3000/api/health; then
|
||||
echo "✅ portfolio-app-2 health check passed!"
|
||||
else
|
||||
echo "❌ portfolio-app-2 health check failed!"
|
||||
docker logs portfolio-app-2 --tail=20
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check nginx health
|
||||
if curl -f http://localhost/health; then
|
||||
echo "✅ Nginx health check passed!"
|
||||
else
|
||||
echo "❌ Nginx health check failed!"
|
||||
docker logs portfolio-nginx --tail=20
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check application health through nginx
|
||||
if curl -f http://localhost/api/health; then
|
||||
echo "✅ Application health check passed!"
|
||||
echo "✅ Application health check through nginx passed!"
|
||||
else
|
||||
echo "❌ Application health check failed!"
|
||||
echo "❌ Application health check through nginx failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check main page through nginx
|
||||
if curl -f http://localhost/ > /dev/null; then
|
||||
echo "✅ Main page is accessible through nginx!"
|
||||
else
|
||||
echo "❌ Main page is not accessible through nginx!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user