Refactor CI/CD workflows and configuration files
- Removed unused network configurations from docker-compose.yml. - Added production-specific Jest configuration in jest.config.production.ts for better test management. - Updated jest.config.ts to include production build fixes and module resolution improvements. - Enhanced jest.setup.ts to mock React's act function for production builds. - Introduced new CI/CD workflows for Gitea, focusing on reliability and zero downtime deployments. - Added scripts for debugging Gitea Actions and verifying environment variables. These changes streamline the CI/CD process and improve testing capabilities.
This commit is contained in:
165
scripts/debug-gitea-actions.sh
Executable file
165
scripts/debug-gitea-actions.sh
Executable file
@@ -0,0 +1,165 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Debug script for Gitea Actions
|
||||
# Helps identify issues with Gitea Actions deployment
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Logging function
|
||||
log() {
|
||||
echo -e "${BLUE}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $1"
|
||||
}
|
||||
|
||||
error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
log "🔍 Debugging Gitea Actions deployment..."
|
||||
|
||||
# Check if we're in the right directory
|
||||
if [ ! -f "package.json" ] || [ ! -f "Dockerfile" ]; then
|
||||
error "Please run this script from the project root directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check Docker
|
||||
log "🐳 Checking Docker..."
|
||||
if ! docker info > /dev/null 2>&1; then
|
||||
error "Docker is not running"
|
||||
exit 1
|
||||
fi
|
||||
success "Docker is running"
|
||||
|
||||
# Check Docker Compose
|
||||
log "🐳 Checking Docker Compose..."
|
||||
if ! docker compose version > /dev/null 2>&1; then
|
||||
error "Docker Compose is not available"
|
||||
exit 1
|
||||
fi
|
||||
success "Docker Compose is available"
|
||||
|
||||
# Check environment variables
|
||||
log "📝 Checking environment variables..."
|
||||
if [ -z "$NEXT_PUBLIC_BASE_URL" ]; then
|
||||
warning "NEXT_PUBLIC_BASE_URL is not set, using default"
|
||||
export NEXT_PUBLIC_BASE_URL="https://dk0.dev"
|
||||
fi
|
||||
|
||||
if [ -z "$MY_EMAIL" ]; then
|
||||
warning "MY_EMAIL is not set, using default"
|
||||
export MY_EMAIL="contact@dk0.dev"
|
||||
fi
|
||||
|
||||
if [ -z "$MY_INFO_EMAIL" ]; then
|
||||
warning "MY_INFO_EMAIL is not set, using default"
|
||||
export MY_INFO_EMAIL="info@dk0.dev"
|
||||
fi
|
||||
|
||||
if [ -z "$MY_PASSWORD" ]; then
|
||||
warning "MY_PASSWORD is not set, using default"
|
||||
export MY_PASSWORD="your-email-password"
|
||||
fi
|
||||
|
||||
if [ -z "$MY_INFO_PASSWORD" ]; then
|
||||
warning "MY_INFO_PASSWORD is not set, using default"
|
||||
export MY_INFO_PASSWORD="your-info-email-password"
|
||||
fi
|
||||
|
||||
if [ -z "$ADMIN_BASIC_AUTH" ]; then
|
||||
warning "ADMIN_BASIC_AUTH is not set, using default"
|
||||
export ADMIN_BASIC_AUTH="admin:your_secure_password_here"
|
||||
fi
|
||||
|
||||
success "Environment variables configured"
|
||||
|
||||
# Check if .env file exists
|
||||
if [ ! -f ".env" ]; then
|
||||
warning ".env file not found, creating from template..."
|
||||
cp env.example .env
|
||||
success ".env file created"
|
||||
fi
|
||||
|
||||
# Test Docker Compose configuration
|
||||
log "🔧 Testing Docker Compose configuration..."
|
||||
if docker compose config > /dev/null 2>&1; then
|
||||
success "Docker Compose configuration is valid"
|
||||
else
|
||||
error "Docker Compose configuration is invalid"
|
||||
docker compose config
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Test build
|
||||
log "🏗️ Testing Docker build..."
|
||||
if docker build -t portfolio-app:test . > /dev/null 2>&1; then
|
||||
success "Docker build successful"
|
||||
docker rmi portfolio-app:test > /dev/null 2>&1
|
||||
else
|
||||
error "Docker build failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Test container startup
|
||||
log "🚀 Testing container startup..."
|
||||
docker compose down --remove-orphans > /dev/null 2>&1 || true
|
||||
if docker compose up -d > /dev/null 2>&1; then
|
||||
success "Containers started successfully"
|
||||
|
||||
# Wait for health check
|
||||
log "⏳ Waiting for health check..."
|
||||
sleep 30
|
||||
|
||||
if docker exec portfolio-app curl -f http://localhost:3000/api/health > /dev/null 2>&1; then
|
||||
success "Health check passed"
|
||||
else
|
||||
error "Health check failed"
|
||||
docker logs portfolio-app --tail=20
|
||||
docker compose down
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Test main page
|
||||
if curl -f http://localhost:3000/ > /dev/null 2>&1; then
|
||||
success "Main page is accessible"
|
||||
else
|
||||
error "Main page is not accessible"
|
||||
docker compose down
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Cleanup
|
||||
docker compose down
|
||||
success "Cleanup completed"
|
||||
else
|
||||
error "Failed to start containers"
|
||||
docker compose logs
|
||||
exit 1
|
||||
fi
|
||||
|
||||
success "🎉 All tests passed! Gitea Actions should work correctly."
|
||||
|
||||
log "📋 Summary:"
|
||||
log " - Docker: ✅"
|
||||
log " - Docker Compose: ✅"
|
||||
log " - Environment variables: ✅"
|
||||
log " - Docker build: ✅"
|
||||
log " - Container startup: ✅"
|
||||
log " - Health check: ✅"
|
||||
log " - Main page: ✅"
|
||||
|
||||
log "🚀 Ready for Gitea Actions deployment!"
|
||||
@@ -69,7 +69,7 @@ npm run lint || {
|
||||
|
||||
# Run tests
|
||||
log "🧪 Running tests..."
|
||||
npm run test || {
|
||||
npm run test:production || {
|
||||
error "Tests failed. Please fix the issues before deploying."
|
||||
exit 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user