diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index e69de29..1321c71 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -0,0 +1,195 @@ +name: CI/CD Pipeline + +on: + push: + branches: [main, production] + pull_request: + branches: [main, production] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + # Test Job + test: + name: Run Tests + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Create test environment file + run: | + cat > .env < .env < /dev/null 2>&1; then exit 1 fi -# Check if docker-compose is available -if ! command -v docker-compose &> /dev/null; then - error "docker-compose is not installed. Please install docker-compose and try again." +# Check if docker compose is available +if ! docker compose version &> /dev/null; then + error "docker compose is not available. Please ensure Docker is installed and try again." exit 1 fi @@ -88,7 +88,7 @@ docker pull $FULL_IMAGE_NAME || { # Stop and remove old containers log "Stopping old containers..." -docker-compose -f $COMPOSE_FILE down || { +docker compose -f $COMPOSE_FILE down || { warning "No old containers to stop" } @@ -100,7 +100,7 @@ docker images $REGISTRY/$IMAGE_NAME --format "table {{.Tag}}\t{{.ID}}" | tail -n # Start new containers log "Starting new containers..." -docker-compose -f $COMPOSE_FILE up -d || { +docker compose -f $COMPOSE_FILE up -d || { error "Failed to start containers" exit 1 } @@ -125,7 +125,7 @@ done if [ $ELAPSED -ge $HEALTH_CHECK_TIMEOUT ]; then error "Health check timeout. Application may not be running properly." log "Container logs:" - docker-compose -f $COMPOSE_FILE logs --tail=50 + docker compose -f $COMPOSE_FILE logs --tail=50 exit 1 fi @@ -136,7 +136,7 @@ if curl -f http://localhost:3000/api/health > /dev/null 2>&1; then # Show container status log "Container status:" - docker-compose -f $COMPOSE_FILE ps + docker compose -f $COMPOSE_FILE ps # Show resource usage log "Resource usage:" @@ -145,7 +145,7 @@ if curl -f http://localhost:3000/api/health > /dev/null 2>&1; then else error "Deployment verification failed!" log "Container logs:" - docker-compose -f $COMPOSE_FILE logs --tail=50 + docker compose -f $COMPOSE_FILE logs --tail=50 exit 1 fi diff --git a/scripts/monitor.sh b/scripts/monitor.sh index 7377830..215af68 100755 --- a/scripts/monitor.sh +++ b/scripts/monitor.sh @@ -49,7 +49,7 @@ check_health() { # Show container status show_status() { log "Container status:" - docker-compose -f $COMPOSE_FILE ps + docker compose -f $COMPOSE_FILE ps echo "" log "Resource usage:" @@ -57,7 +57,7 @@ show_status() { echo "" log "Container logs (last 20 lines):" - docker-compose -f $COMPOSE_FILE logs --tail=20 + docker compose -f $COMPOSE_FILE logs --tail=20 } # Show detailed metrics @@ -92,7 +92,7 @@ show_metrics() { # Restart container restart_container() { log "Restarting container..." - docker-compose -f $COMPOSE_FILE restart + docker compose -f $COMPOSE_FILE restart # Wait for health check log "Waiting for container to be healthy..." @@ -110,7 +110,7 @@ restart_container() { show_logs() { local lines=${1:-50} log "Showing last $lines lines of logs:" - docker-compose -f $COMPOSE_FILE logs --tail=$lines -f + docker compose -f $COMPOSE_FILE logs --tail=$lines -f } # Cleanup