Files
startover/deploy/deploy.sh
T
Johngreen bd48cafcc9 ci: IDC 서버 자동배포 파이프라인 구축
- Dockerfile: Turborepo 멀티스테이지 빌드 (Next.js standalone)
- docker-compose.prod.yml: PostgreSQL/Redis/Nginx/Web/Admin 프로덕션 스택
- deploy/poll-deploy.sh: cron 기반 자동배포 (매분 Gitea 폴링)
- deploy/nginx/default.conf: 리버스 프록시 설정
- next.config.ts: output standalone 추가
- .env.production.example: 환경변수 템플릿

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 22:28:09 +09:00

73 lines
1.8 KiB
Bash

#!/bin/bash
set -euo pipefail
# ===========================================
# Re:Link Auto Deploy Script
# Triggered by Gitea webhook on push to main
# ===========================================
APP_DIR="$HOME/relink"
LOG_FILE="$APP_DIR/deploy.log"
LOCK_FILE="$APP_DIR/deploy.lock"
GITEA_REPO="http://39.117.244.52:3000/geonhee/Re_Link.git"
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
}
# Prevent concurrent deploys
if [ -f "$LOCK_FILE" ]; then
LOCK_PID=$(cat "$LOCK_FILE" 2>/dev/null)
if kill -0 "$LOCK_PID" 2>/dev/null; then
log "ERROR: Deploy already running (PID: $LOCK_PID). Skipping."
exit 1
fi
rm -f "$LOCK_FILE"
fi
echo $$ > "$LOCK_FILE"
trap 'rm -f "$LOCK_FILE"' EXIT
log "=== Deploy started ==="
# Navigate to app directory
cd "$APP_DIR"
# Clone or pull
if [ ! -d "$APP_DIR/repo/.git" ]; then
log "Cloning repository..."
git clone "$GITEA_REPO" "$APP_DIR/repo"
cd "$APP_DIR/repo"
else
cd "$APP_DIR/repo"
log "Pulling latest changes..."
git fetch origin
git reset --hard origin/main
fi
log "Current commit: $(git log --oneline -1)"
# Copy env file
if [ -f "$APP_DIR/.env.production" ]; then
cp "$APP_DIR/.env.production" "$APP_DIR/repo/.env.production"
fi
# Build and deploy
log "Building and deploying with Docker Compose..."
docker compose -f docker-compose.prod.yml --env-file .env.production up -d --build --remove-orphans 2>&1 | tee -a "$LOG_FILE"
# Wait for services
log "Waiting for services to be healthy..."
sleep 15
# Health check
if curl -sf http://localhost/health > /dev/null 2>&1; then
log "Health check PASSED"
else
log "WARNING: Health check failed - services may still be starting"
fi
# Cleanup old images
docker image prune -f >> "$LOG_FILE" 2>&1
log "=== Deploy completed ==="