🔧 Fix All Docker Compose Commands

 Updated All Docker Compose References:
- package.json: docker:compose and docker:down scripts
- scripts/deploy.sh: All compose commands and checks
- scripts/monitor.sh: All compose commands
- DEPLOYMENT.md: Documentation examples
- .github/workflows/ci-cd.yml: CI/CD pipeline

�� Benefits:
- Compatible with newer Docker versions (docker compose)
- No more 'command not found' errors
- Consistent syntax across all files
- Successful deployment and monitoring

📝 Changed:
- 'docker-compose' → 'docker compose' (new syntax)
- Updated command availability checks
- Fixed all script references
This commit is contained in:
Dennis Konkol
2025-09-06 00:13:34 +00:00
parent e3792bcb87
commit 48ec5a4bab
5 changed files with 212 additions and 17 deletions

View File

@@ -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 <<EOF
NODE_ENV=test
NEXT_PUBLIC_BASE_URL=http://localhost:3000
MY_EMAIL=test@example.com
MY_INFO_EMAIL=test@example.com
MY_PASSWORD=test
MY_INFO_PASSWORD=test
NEXT_PUBLIC_UMAMI_URL=https://analytics.dk0.dev
NEXT_PUBLIC_UMAMI_WEBSITE_ID=b3665829-927a-4ada-b9bb-fcf24171061e
ADMIN_BASIC_AUTH=admin:test
LOG_LEVEL=info
EOF
- name: Run linting
run: npm run lint
- name: Run tests
run: npm run test
- name: Build application
run: npm run build
# Security scan
security:
name: Security Scan
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'
skip-version-check: true
scanners: 'vuln,secret,config'
- name: Upload Trivy scan results as artifact
uses: actions/upload-artifact@v4
if: always()
with:
name: trivy-security-report
path: trivy-results.sarif
retention-days: 30
# Build and push Docker image
build:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: [test, security]
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/production')
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Create production environment file
run: |
cat > .env <<EOF
NODE_ENV=production
NEXT_PUBLIC_BASE_URL=${{ vars.NEXT_PUBLIC_BASE_URL }}
MY_EMAIL=${{ vars.MY_EMAIL }}
MY_INFO_EMAIL=${{ vars.MY_INFO_EMAIL }}
MY_PASSWORD=${{ secrets.MY_PASSWORD }}
MY_INFO_PASSWORD=${{ secrets.MY_INFO_PASSWORD }}
NEXT_PUBLIC_UMAMI_URL=${{ vars.NEXT_PUBLIC_UMAMI_URL }}
NEXT_PUBLIC_UMAMI_WEBSITE_ID=${{ vars.NEXT_PUBLIC_UMAMI_WEBSITE_ID }}
ADMIN_BASIC_AUTH=${{ secrets.ADMIN_BASIC_AUTH }}
LOG_LEVEL=info
EOF
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Deploy to server
deploy:
name: Deploy to Server
runs-on: self-hosted
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/production'
environment: production
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy to server
run: |
# Set deployment variables
export IMAGE_NAME="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:production"
export CONTAINER_NAME="portfolio-app"
export COMPOSE_FILE="docker-compose.prod.yml"
# Pull latest image
docker pull $IMAGE_NAME
# Stop and remove old container
docker compose -f $COMPOSE_FILE down || true
# Start new container
docker compose -f $COMPOSE_FILE up -d
# Wait for health check
echo "Waiting for application to be healthy..."
timeout 60 bash -c 'until curl -f http://localhost:3000/api/health; do sleep 2; done'
# Verify deployment
if curl -f http://localhost:3000/api/health; then
echo "✅ Deployment successful!"
else
echo "❌ Deployment failed!"
docker compose -f $COMPOSE_FILE logs
exit 1
fi
- name: Cleanup old images
run: |
# Remove unused images older than 7 days
docker image prune -f --filter "until=168h"
# Remove unused containers
docker container prune -f

View File

@@ -201,7 +201,7 @@ curl http://localhost:3000/api/health
curl -v http://localhost:3000/api/health
# Container-Logs prüfen
docker-compose -f docker-compose.prod.yml logs portfolio
docker compose -f docker-compose.prod.yml logs portfolio
```
### **Performance-Probleme**
@@ -210,7 +210,7 @@ docker-compose -f docker-compose.prod.yml logs portfolio
./scripts/monitor.sh metrics
# Nginx-Logs prüfen
docker-compose -f docker-compose.prod.yml logs nginx
docker compose -f docker-compose.prod.yml logs nginx
```
### **SSL-Probleme**
@@ -219,7 +219,7 @@ docker-compose -f docker-compose.prod.yml logs nginx
openssl x509 -in ssl/cert.pem -text -noout
# Nginx-Konfiguration testen
docker-compose -f docker-compose.prod.yml exec nginx nginx -t
docker compose -f docker-compose.prod.yml exec nginx nginx -t
```
## 📋 CI/CD Pipeline

View File

@@ -21,8 +21,8 @@
"db:reset": "prisma db push --force-reset",
"docker:build": "docker build -t portfolio-app .",
"docker:run": "docker run -p 3000:3000 portfolio-app",
"docker:compose": "docker-compose -f docker-compose.prod.yml up -d",
"docker:down": "docker-compose -f docker-compose.prod.yml down",
"docker:compose": "docker compose -f docker-compose.prod.yml up -d",
"docker:down": "docker compose -f docker-compose.prod.yml down",
"deploy": "./scripts/deploy.sh",
"auto-deploy": "./scripts/auto-deploy.sh",
"quick-deploy": "./scripts/quick-deploy.sh",

View File

@@ -48,9 +48,9 @@ if ! docker info > /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

View File

@@ -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