Compare commits
2 Commits
3dbe80edcc
...
cc5009a0d6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc5009a0d6 | ||
|
|
116dac89b3 |
164
.gitea/workflows/ci-cd-zero-downtime-fixed.yml
Normal file
164
.gitea/workflows/ci-cd-zero-downtime-fixed.yml
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
name: CI/CD Pipeline (Zero Downtime - Fixed)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ production ]
|
||||||
|
|
||||||
|
env:
|
||||||
|
NODE_VERSION: '20'
|
||||||
|
DOCKER_IMAGE: portfolio-app
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
production:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
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: Build Docker image
|
||||||
|
run: |
|
||||||
|
docker build -t ${{ env.DOCKER_IMAGE }}:latest .
|
||||||
|
docker tag ${{ env.DOCKER_IMAGE }}:latest ${{ env.DOCKER_IMAGE }}:$(date +%Y%m%d-%H%M%S)
|
||||||
|
|
||||||
|
- name: Verify secrets and variables before deployment
|
||||||
|
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 with zero downtime using docker-compose
|
||||||
|
run: |
|
||||||
|
echo "🚀 Deploying with zero downtime using docker-compose..."
|
||||||
|
|
||||||
|
# Export environment variables for docker compose
|
||||||
|
export NODE_ENV="${{ vars.NODE_ENV }}"
|
||||||
|
export LOG_LEVEL="${{ vars.LOG_LEVEL }}"
|
||||||
|
export NEXT_PUBLIC_BASE_URL="${{ vars.NEXT_PUBLIC_BASE_URL }}"
|
||||||
|
export NEXT_PUBLIC_UMAMI_URL="${{ vars.NEXT_PUBLIC_UMAMI_URL }}"
|
||||||
|
export NEXT_PUBLIC_UMAMI_WEBSITE_ID="${{ vars.NEXT_PUBLIC_UMAMI_WEBSITE_ID }}"
|
||||||
|
export MY_EMAIL="${{ vars.MY_EMAIL }}"
|
||||||
|
export MY_INFO_EMAIL="${{ vars.MY_INFO_EMAIL }}"
|
||||||
|
export MY_PASSWORD="${{ secrets.MY_PASSWORD }}"
|
||||||
|
export MY_INFO_PASSWORD="${{ secrets.MY_INFO_PASSWORD }}"
|
||||||
|
export ADMIN_BASIC_AUTH="${{ secrets.ADMIN_BASIC_AUTH }}"
|
||||||
|
|
||||||
|
# Stop old containers
|
||||||
|
echo "🛑 Stopping old containers..."
|
||||||
|
docker compose -f docker-compose.zero-downtime.yml down || true
|
||||||
|
|
||||||
|
# Start new containers
|
||||||
|
echo "🚀 Starting new containers..."
|
||||||
|
docker compose -f docker-compose.zero-downtime.yml up -d
|
||||||
|
|
||||||
|
echo "✅ Zero downtime deployment completed!"
|
||||||
|
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: Wait for container to be ready
|
||||||
|
run: |
|
||||||
|
echo "⏳ Waiting for containers to be ready..."
|
||||||
|
sleep 15
|
||||||
|
|
||||||
|
# Wait for nginx to be healthy
|
||||||
|
for i in {1..30}; do
|
||||||
|
if curl -f http://localhost/health > /dev/null 2>&1; then
|
||||||
|
echo "✅ Nginx is healthy!"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
echo "⏳ Waiting for nginx... ($i/30)"
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: Health check
|
||||||
|
run: |
|
||||||
|
echo "🔍 Running health checks..."
|
||||||
|
|
||||||
|
# Check nginx health
|
||||||
|
if curl -f http://localhost/health; then
|
||||||
|
echo "✅ Nginx health check passed!"
|
||||||
|
else
|
||||||
|
echo "❌ Nginx health check failed!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check application health through nginx
|
||||||
|
if curl -f http://localhost/api/health; then
|
||||||
|
echo "✅ Application health check passed!"
|
||||||
|
else
|
||||||
|
echo "❌ Application health check failed!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "✅ All health checks passed! Deployment successful!"
|
||||||
|
|
||||||
|
- name: Show container status
|
||||||
|
run: |
|
||||||
|
echo "📊 Container status:"
|
||||||
|
docker compose -f docker-compose.zero-downtime.yml ps
|
||||||
|
|
||||||
|
- name: Cleanup old images
|
||||||
|
run: |
|
||||||
|
echo "🧹 Cleaning up old images..."
|
||||||
|
docker image prune -f
|
||||||
|
docker system prune -f
|
||||||
|
echo "✅ Cleanup completed"
|
||||||
43
logs/gitea-deploy-simple.log
Normal file
43
logs/gitea-deploy-simple.log
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
[0;34m[2025-09-13 23:24:42][0m 🚀 Starting simplified Gitea deployment for portfolio
|
||||||
|
[0;34m[2025-09-13 23:24:42][0m 🔨 Step 1: Building application...
|
||||||
|
[0;34m[2025-09-13 23:24:42][0m 📦 Building Next.js application...
|
||||||
|
[0;32m[SUCCESS][0m ✅ Application built successfully
|
||||||
|
[0;34m[2025-09-13 23:25:04][0m 🐳 Step 2: Docker operations...
|
||||||
|
[0;34m[2025-09-13 23:25:04][0m 🏗️ Building Docker image...
|
||||||
|
[0;31m[ERROR][0m Docker build failed
|
||||||
|
[0;34m[2025-09-13 23:26:50][0m 🚀 Starting simplified Gitea deployment for portfolio
|
||||||
|
[0;34m[2025-09-13 23:26:50][0m 🔨 Step 1: Building application...
|
||||||
|
[0;34m[2025-09-13 23:26:50][0m 📦 Building Next.js application...
|
||||||
|
[0;32m[SUCCESS][0m ✅ Application built successfully
|
||||||
|
[0;34m[2025-09-13 23:27:13][0m 🐳 Step 2: Docker operations...
|
||||||
|
[0;34m[2025-09-13 23:27:13][0m 🏗️ Building Docker image...
|
||||||
|
[0;31m[ERROR][0m Docker build failed
|
||||||
|
[0;34m[2025-09-13 23:28:23][0m 🚀 Starting simplified Gitea deployment for portfolio
|
||||||
|
[0;34m[2025-09-13 23:28:23][0m 🔨 Step 1: Building application...
|
||||||
|
[0;34m[2025-09-13 23:28:23][0m 📦 Building Next.js application...
|
||||||
|
[0;32m[SUCCESS][0m ✅ Application built successfully
|
||||||
|
[0;34m[2025-09-13 23:28:49][0m 🐳 Step 2: Docker operations...
|
||||||
|
[0;34m[2025-09-13 23:28:49][0m 🏗️ Building Docker image...
|
||||||
|
[0;31m[ERROR][0m Docker build failed
|
||||||
|
[0;34m[2025-09-13 23:35:08][0m 🚀 Starting simplified Gitea deployment for portfolio
|
||||||
|
[0;34m[2025-09-13 23:35:08][0m 🔨 Step 1: Building application...
|
||||||
|
[0;34m[2025-09-13 23:35:08][0m 📦 Building Next.js application...
|
||||||
|
[0;32m[SUCCESS][0m ✅ Application built successfully
|
||||||
|
[0;34m[2025-09-13 23:35:31][0m 🐳 Step 2: Docker operations...
|
||||||
|
[0;34m[2025-09-13 23:35:31][0m 🏗️ Building Docker image...
|
||||||
|
[0;32m[SUCCESS][0m ✅ Docker image built successfully
|
||||||
|
[0;34m[2025-09-13 23:36:32][0m 🚀 Step 3: Deploying application...
|
||||||
|
[0;34m[2025-09-13 23:36:33][0m 🚀 Starting new container on port 3000...
|
||||||
|
[0;34m[2025-09-13 23:36:33][0m ⏳ Waiting for container to be ready...
|
||||||
|
[0;34m[2025-09-13 23:36:53][0m 🏥 Performing health check...
|
||||||
|
[0;32m[SUCCESS][0m ✅ Application is healthy!
|
||||||
|
[0;34m[2025-09-13 23:36:53][0m ✅ Step 4: Verifying deployment...
|
||||||
|
[0;32m[SUCCESS][0m ✅ Main page is accessible
|
||||||
|
[0;34m[2025-09-13 23:36:53][0m 📊 Container status:
|
||||||
|
[0;34m[2025-09-13 23:36:53][0m 📈 Resource usage:
|
||||||
|
[0;32m[SUCCESS][0m 🎉 Simplified Gitea deployment completed successfully!
|
||||||
|
[0;34m[2025-09-13 23:36:54][0m 🌐 Application is available at: http://localhost:3000
|
||||||
|
[0;34m[2025-09-13 23:36:54][0m 🏥 Health check endpoint: http://localhost:3000/api/health
|
||||||
|
[0;34m[2025-09-13 23:36:54][0m 📊 Container name: portfolio-app-simple
|
||||||
|
[0;34m[2025-09-13 23:36:54][0m 📝 Logs: docker logs portfolio-app-simple
|
||||||
|
Sat Sep 13 23:36:54 CEST 2025: Simplified Gitea deployment successful - Port: 3000 - Image: portfolio-app:20250913-233632
|
||||||
@@ -10,6 +10,11 @@ const nextConfig: NextConfig = {
|
|||||||
output: 'standalone',
|
output: 'standalone',
|
||||||
outputFileTracingRoot: path.join(__dirname, '../../'),
|
outputFileTracingRoot: path.join(__dirname, '../../'),
|
||||||
|
|
||||||
|
// Ensure proper server configuration
|
||||||
|
serverRuntimeConfig: {
|
||||||
|
// Will only be available on the server side
|
||||||
|
},
|
||||||
|
|
||||||
// Optimize for production
|
// Optimize for production
|
||||||
compress: true,
|
compress: true,
|
||||||
poweredByHeader: false,
|
poweredByHeader: false,
|
||||||
@@ -23,14 +28,6 @@ const nextConfig: NextConfig = {
|
|||||||
env: {
|
env: {
|
||||||
NEXT_PUBLIC_BASE_URL: process.env.NEXT_PUBLIC_BASE_URL
|
NEXT_PUBLIC_BASE_URL: process.env.NEXT_PUBLIC_BASE_URL
|
||||||
},
|
},
|
||||||
serverRuntimeConfig: {
|
|
||||||
GHOST_API_URL: process.env.GHOST_API_URL,
|
|
||||||
GHOST_API_KEY: process.env.GHOST_API_KEY,
|
|
||||||
MY_EMAIL: process.env.MY_EMAIL,
|
|
||||||
MY_INFO_EMAIL: process.env.MY_INFO_EMAIL,
|
|
||||||
MY_PASSWORD: process.env.MY_PASSWORD,
|
|
||||||
MY_INFO_PASSWORD: process.env.MY_INFO_PASSWORD
|
|
||||||
},
|
|
||||||
|
|
||||||
// Performance optimizations
|
// Performance optimizations
|
||||||
experimental: {
|
experimental: {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ ENVIRONMENT=${1:-production}
|
|||||||
REGISTRY="ghcr.io"
|
REGISTRY="ghcr.io"
|
||||||
IMAGE_NAME="dennis-konkol/my_portfolio"
|
IMAGE_NAME="dennis-konkol/my_portfolio"
|
||||||
CONTAINER_NAME="portfolio-app"
|
CONTAINER_NAME="portfolio-app"
|
||||||
COMPOSE_FILE="docker-compose.prod.yml"
|
COMPOSE_FILE="docker-compose.zero-downtime.yml"
|
||||||
|
|
||||||
# Colors for output
|
# Colors for output
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
@@ -79,10 +79,10 @@ echo "$GITHUB_TOKEN" | docker login $REGISTRY -u $GITHUB_ACTOR --password-stdin
|
|||||||
warning "Failed to login to registry. Make sure GITHUB_TOKEN and GITHUB_ACTOR are set."
|
warning "Failed to login to registry. Make sure GITHUB_TOKEN and GITHUB_ACTOR are set."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Pull latest image
|
# Build latest image locally
|
||||||
log "Pulling latest image..."
|
log "Building latest image locally..."
|
||||||
docker pull $FULL_IMAGE_NAME || {
|
docker build -t portfolio-app:latest . || {
|
||||||
error "Failed to pull image $FULL_IMAGE_NAME"
|
error "Failed to build image locally"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ HEALTH_CHECK_INTERVAL=2
|
|||||||
ELAPSED=0
|
ELAPSED=0
|
||||||
|
|
||||||
while [ $ELAPSED -lt $HEALTH_CHECK_TIMEOUT ]; do
|
while [ $ELAPSED -lt $HEALTH_CHECK_TIMEOUT ]; do
|
||||||
if curl -f http://localhost:3000/api/health > /dev/null 2>&1; then
|
if curl -f http://localhost/api/health > /dev/null 2>&1; then
|
||||||
success "Application is healthy!"
|
success "Application is healthy!"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
@@ -131,7 +131,7 @@ fi
|
|||||||
|
|
||||||
# Verify deployment
|
# Verify deployment
|
||||||
log "Verifying deployment..."
|
log "Verifying deployment..."
|
||||||
if curl -f http://localhost:3000/api/health > /dev/null 2>&1; then
|
if curl -f http://localhost/api/health > /dev/null 2>&1; then
|
||||||
success "Deployment successful!"
|
success "Deployment successful!"
|
||||||
|
|
||||||
# Show container status
|
# Show container status
|
||||||
@@ -156,5 +156,5 @@ docker system prune -f --volumes || {
|
|||||||
}
|
}
|
||||||
|
|
||||||
success "Deployment completed successfully!"
|
success "Deployment completed successfully!"
|
||||||
log "Application is available at: http://localhost:3000"
|
log "Application is available at: http://localhost/"
|
||||||
log "Health check endpoint: http://localhost:3000/api/health"
|
log "Health check endpoint: http://localhost/api/health"
|
||||||
|
|||||||
201
scripts/gitea-deploy-simple.sh
Executable file
201
scripts/gitea-deploy-simple.sh
Executable file
@@ -0,0 +1,201 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Simplified Gitea deployment script for testing
|
||||||
|
# This version doesn't require database dependencies
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
PROJECT_NAME="portfolio"
|
||||||
|
CONTAINER_NAME="portfolio-app-simple"
|
||||||
|
IMAGE_NAME="portfolio-app"
|
||||||
|
PORT=3000
|
||||||
|
BACKUP_PORT=3001
|
||||||
|
LOG_FILE="./logs/gitea-deploy-simple.log"
|
||||||
|
|
||||||
|
# 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" | tee -a "$LOG_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
echo -e "${RED}[ERROR]${NC} $1" | tee -a "$LOG_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
success() {
|
||||||
|
echo -e "${GREEN}[SUCCESS]${NC} $1" | tee -a "$LOG_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
warning() {
|
||||||
|
echo -e "${YELLOW}[WARNING]${NC} $1" | tee -a "$LOG_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if running as root
|
||||||
|
if [[ $EUID -eq 0 ]]; then
|
||||||
|
error "This script should not be run as root"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if Docker is running
|
||||||
|
if ! docker info > /dev/null 2>&1; then
|
||||||
|
error "Docker is not running. Please start Docker and try again."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
log "🚀 Starting simplified Gitea deployment for $PROJECT_NAME"
|
||||||
|
|
||||||
|
# Step 1: Build Application
|
||||||
|
log "🔨 Step 1: Building application..."
|
||||||
|
|
||||||
|
# Build Next.js application
|
||||||
|
log "📦 Building Next.js application..."
|
||||||
|
npm run build || {
|
||||||
|
error "Build failed"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
success "✅ Application built successfully"
|
||||||
|
|
||||||
|
# Step 2: Docker Operations
|
||||||
|
log "🐳 Step 2: Docker operations..."
|
||||||
|
|
||||||
|
# Build Docker image
|
||||||
|
log "🏗️ Building Docker image..."
|
||||||
|
docker build -t "$IMAGE_NAME:latest" . || {
|
||||||
|
error "Docker build failed"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Tag with timestamp
|
||||||
|
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
|
||||||
|
docker tag "$IMAGE_NAME:latest" "$IMAGE_NAME:$TIMESTAMP"
|
||||||
|
|
||||||
|
success "✅ Docker image built successfully"
|
||||||
|
|
||||||
|
# Step 3: Deployment
|
||||||
|
log "🚀 Step 3: Deploying application..."
|
||||||
|
|
||||||
|
# Check if container is running
|
||||||
|
if [ "$(docker inspect -f '{{.State.Running}}' "$CONTAINER_NAME" 2>/dev/null)" = "true" ]; then
|
||||||
|
log "📦 Stopping existing container..."
|
||||||
|
docker stop "$CONTAINER_NAME" || true
|
||||||
|
docker rm "$CONTAINER_NAME" || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if port is available
|
||||||
|
if lsof -Pi :$PORT -sTCP:LISTEN -t >/dev/null ; then
|
||||||
|
warning "Port $PORT is in use. Trying backup port $BACKUP_PORT"
|
||||||
|
DEPLOY_PORT=$BACKUP_PORT
|
||||||
|
else
|
||||||
|
DEPLOY_PORT=$PORT
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Start new container with minimal environment variables
|
||||||
|
log "🚀 Starting new container on port $DEPLOY_PORT..."
|
||||||
|
docker run -d \
|
||||||
|
--name "$CONTAINER_NAME" \
|
||||||
|
--restart unless-stopped \
|
||||||
|
-p "$DEPLOY_PORT:3000" \
|
||||||
|
-e NODE_ENV=production \
|
||||||
|
-e NEXT_PUBLIC_BASE_URL=https://dk0.dev \
|
||||||
|
-e MY_EMAIL=contact@dk0.dev \
|
||||||
|
-e MY_INFO_EMAIL=info@dk0.dev \
|
||||||
|
-e MY_PASSWORD=test-password \
|
||||||
|
-e MY_INFO_PASSWORD=test-password \
|
||||||
|
-e ADMIN_BASIC_AUTH=admin:test123 \
|
||||||
|
-e LOG_LEVEL=info \
|
||||||
|
"$IMAGE_NAME:latest" || {
|
||||||
|
error "Failed to start container"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Wait for container to be ready
|
||||||
|
log "⏳ Waiting for container to be ready..."
|
||||||
|
sleep 20
|
||||||
|
|
||||||
|
# Check if container is actually running
|
||||||
|
if [ "$(docker inspect -f '{{.State.Running}}' "$CONTAINER_NAME" 2>/dev/null)" != "true" ]; then
|
||||||
|
error "Container failed to start or crashed"
|
||||||
|
log "Container logs:"
|
||||||
|
docker logs "$CONTAINER_NAME" --tail=50
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Health check
|
||||||
|
log "🏥 Performing health check..."
|
||||||
|
HEALTH_CHECK_TIMEOUT=180
|
||||||
|
HEALTH_CHECK_INTERVAL=5
|
||||||
|
ELAPSED=0
|
||||||
|
|
||||||
|
while [ $ELAPSED -lt $HEALTH_CHECK_TIMEOUT ]; do
|
||||||
|
# Check if container is still running
|
||||||
|
if [ "$(docker inspect -f '{{.State.Running}}' "$CONTAINER_NAME" 2>/dev/null)" != "true" ]; then
|
||||||
|
error "Container stopped during health check"
|
||||||
|
log "Container logs:"
|
||||||
|
docker logs "$CONTAINER_NAME" --tail=50
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Try health check endpoint
|
||||||
|
if curl -f "http://localhost:$DEPLOY_PORT/api/health" > /dev/null 2>&1; then
|
||||||
|
success "✅ Application is healthy!"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep $HEALTH_CHECK_INTERVAL
|
||||||
|
ELAPSED=$((ELAPSED + HEALTH_CHECK_INTERVAL))
|
||||||
|
echo -n "."
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $ELAPSED -ge $HEALTH_CHECK_TIMEOUT ]; then
|
||||||
|
error "Health check timeout. Application may not be running properly."
|
||||||
|
log "Container status:"
|
||||||
|
docker inspect "$CONTAINER_NAME" --format='{{.State.Status}} - {{.State.Health.Status}}'
|
||||||
|
log "Container logs:"
|
||||||
|
docker logs "$CONTAINER_NAME" --tail=100
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Step 4: Verification
|
||||||
|
log "✅ Step 4: Verifying deployment..."
|
||||||
|
|
||||||
|
# Test main page
|
||||||
|
if curl -f "http://localhost:$DEPLOY_PORT/" > /dev/null 2>&1; then
|
||||||
|
success "✅ Main page is accessible"
|
||||||
|
else
|
||||||
|
error "❌ Main page is not accessible"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Show container status
|
||||||
|
log "📊 Container status:"
|
||||||
|
docker ps --filter "name=$CONTAINER_NAME" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
|
||||||
|
|
||||||
|
# Show resource usage
|
||||||
|
log "📈 Resource usage:"
|
||||||
|
docker stats --no-stream --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" "$CONTAINER_NAME"
|
||||||
|
|
||||||
|
# Final success message
|
||||||
|
success "🎉 Simplified Gitea deployment completed successfully!"
|
||||||
|
log "🌐 Application is available at: http://localhost:$DEPLOY_PORT"
|
||||||
|
log "🏥 Health check endpoint: http://localhost:$DEPLOY_PORT/api/health"
|
||||||
|
log "📊 Container name: $CONTAINER_NAME"
|
||||||
|
log "📝 Logs: docker logs $CONTAINER_NAME"
|
||||||
|
|
||||||
|
# Update deployment log
|
||||||
|
echo "$(date): Simplified Gitea deployment successful - Port: $DEPLOY_PORT - Image: $IMAGE_NAME:$TIMESTAMP" >> "$LOG_FILE"
|
||||||
|
|
||||||
|
exit 0
|
||||||
@@ -122,13 +122,20 @@ else
|
|||||||
DEPLOY_PORT=$PORT
|
DEPLOY_PORT=$PORT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start new container
|
# Start new container with environment variables
|
||||||
log "🚀 Starting new container on port $DEPLOY_PORT..."
|
log "🚀 Starting new container on port $DEPLOY_PORT..."
|
||||||
docker run -d \
|
docker run -d \
|
||||||
--name "$CONTAINER_NAME" \
|
--name "$CONTAINER_NAME" \
|
||||||
--restart unless-stopped \
|
--restart unless-stopped \
|
||||||
-p "$DEPLOY_PORT:3000" \
|
-p "$DEPLOY_PORT:3000" \
|
||||||
-e NODE_ENV=production \
|
-e NODE_ENV=production \
|
||||||
|
-e NEXT_PUBLIC_BASE_URL=https://dk0.dev \
|
||||||
|
-e MY_EMAIL=contact@dk0.dev \
|
||||||
|
-e MY_INFO_EMAIL=info@dk0.dev \
|
||||||
|
-e MY_PASSWORD="${MY_PASSWORD:-your-email-password}" \
|
||||||
|
-e MY_INFO_PASSWORD="${MY_INFO_PASSWORD:-your-info-email-password}" \
|
||||||
|
-e ADMIN_BASIC_AUTH="${ADMIN_BASIC_AUTH:-admin:your_secure_password_here}" \
|
||||||
|
-e LOG_LEVEL=info \
|
||||||
"$IMAGE_NAME:latest" || {
|
"$IMAGE_NAME:latest" || {
|
||||||
error "Failed to start container"
|
error "Failed to start container"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -136,15 +143,32 @@ docker run -d \
|
|||||||
|
|
||||||
# Wait for container to be ready
|
# Wait for container to be ready
|
||||||
log "⏳ Waiting for container to be ready..."
|
log "⏳ Waiting for container to be ready..."
|
||||||
sleep 10
|
sleep 15
|
||||||
|
|
||||||
|
# Check if container is actually running
|
||||||
|
if [ "$(docker inspect -f '{{.State.Running}}' "$CONTAINER_NAME" 2>/dev/null)" != "true" ]; then
|
||||||
|
error "Container failed to start or crashed"
|
||||||
|
log "Container logs:"
|
||||||
|
docker logs "$CONTAINER_NAME" --tail=50
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Health check
|
# Health check
|
||||||
log "🏥 Performing health check..."
|
log "🏥 Performing health check..."
|
||||||
HEALTH_CHECK_TIMEOUT=60
|
HEALTH_CHECK_TIMEOUT=120
|
||||||
HEALTH_CHECK_INTERVAL=2
|
HEALTH_CHECK_INTERVAL=3
|
||||||
ELAPSED=0
|
ELAPSED=0
|
||||||
|
|
||||||
while [ $ELAPSED -lt $HEALTH_CHECK_TIMEOUT ]; do
|
while [ $ELAPSED -lt $HEALTH_CHECK_TIMEOUT ]; do
|
||||||
|
# Check if container is still running
|
||||||
|
if [ "$(docker inspect -f '{{.State.Running}}' "$CONTAINER_NAME" 2>/dev/null)" != "true" ]; then
|
||||||
|
error "Container stopped during health check"
|
||||||
|
log "Container logs:"
|
||||||
|
docker logs "$CONTAINER_NAME" --tail=50
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Try health check endpoint
|
||||||
if curl -f "http://localhost:$DEPLOY_PORT/api/health" > /dev/null 2>&1; then
|
if curl -f "http://localhost:$DEPLOY_PORT/api/health" > /dev/null 2>&1; then
|
||||||
success "✅ Application is healthy!"
|
success "✅ Application is healthy!"
|
||||||
break
|
break
|
||||||
@@ -157,8 +181,10 @@ done
|
|||||||
|
|
||||||
if [ $ELAPSED -ge $HEALTH_CHECK_TIMEOUT ]; then
|
if [ $ELAPSED -ge $HEALTH_CHECK_TIMEOUT ]; then
|
||||||
error "Health check timeout. Application may not be running properly."
|
error "Health check timeout. Application may not be running properly."
|
||||||
|
log "Container status:"
|
||||||
|
docker inspect "$CONTAINER_NAME" --format='{{.State.Status}} - {{.State.Health.Status}}'
|
||||||
log "Container logs:"
|
log "Container logs:"
|
||||||
docker logs "$CONTAINER_NAME" --tail=50
|
docker logs "$CONTAINER_NAME" --tail=100
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ warning() {
|
|||||||
check_health() {
|
check_health() {
|
||||||
log "Checking application health..."
|
log "Checking application health..."
|
||||||
|
|
||||||
if curl -f http://localhost:3000/api/health > /dev/null 2>&1; then
|
if curl -f http://localhost/api/health > /dev/null 2>&1; then
|
||||||
success "Application is healthy"
|
success "Application is healthy"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user