π fix: Next.js 14 νμ€ standalone λ°°ν¬ λ°©μ μ μ© #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to EC2 | |
| on: | |
| pull_request: | |
| types: [closed] | |
| branches: [main, develop] | |
| jobs: | |
| deploy: | |
| if: github.event.pull_request.merged == true | |
| runs-on: self-hosted | |
| timeout-minutes: 10 | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Deploy to EC2 | |
| run: | | |
| set -e | |
| # λ°°ν¬ λ‘κΉ | |
| echo "π Starting deployment..." | |
| echo "π PR: #${{ github.event.pull_request.number }}" | |
| echo "π Commit: ${{ github.sha }}" | |
| # λ©λͺ¨λ¦¬ μ 리 | |
| echo "π§Ή Cleaning up Docker resources..." | |
| docker system prune -f | |
| # λΈλμΉλ³ νκ²½ μ€μ | |
| if [ "${{ github.event.pull_request.base.ref }}" = "main" ]; then | |
| CONTAINER_NAME="app-prod" | |
| ENV_FILE="app-prod.env" | |
| OTHER_CONTAINER="app-dev" | |
| echo "π Deploying to PRODUCTION" | |
| elif [ "${{ github.event.pull_request.base.ref }}" = "develop" ]; then | |
| CONTAINER_NAME="app-dev" | |
| ENV_FILE="app-dev.env" | |
| OTHER_CONTAINER="app-prod" | |
| echo "π§ͺ Deploying to DEVELOPMENT" | |
| fi | |
| # λ°°ν¬ λλ ν 리 μ€μ | |
| DEPLOY_DIR="/home/ubuntu/coplan/app" | |
| # λ©λͺ¨λ¦¬ ν보λ₯Ό μν΄ λ€λ₯Έ 컨ν μ΄λ μ€μ§ | |
| echo "βΈοΈ Stopping other container to free memory..." | |
| docker compose stop ${OTHER_CONTAINER} || true | |
| # rsyncλ‘ νμΌ λκΈ°ν | |
| echo "π Synchronizing files..." | |
| rsync -av \ | |
| --exclude='.git' \ | |
| --exclude='node_modules' \ | |
| --exclude='.next' \ | |
| --exclude='.env*' \ | |
| --exclude='*.log' \ | |
| --delete \ | |
| ./ ${DEPLOY_DIR}/ | |
| # μμ λλ ν 리 μ΄λ | |
| cd /home/ubuntu/coplan | |
| # νκ²½λ³μ νμΌ λ³΅μ¬ (μλ κ²½μ°λ§) | |
| if [ -f "/home/ubuntu/env/${ENV_FILE}" ]; then | |
| echo "π Copying environment variables..." | |
| cp "/home/ubuntu/env/${ENV_FILE}" "${DEPLOY_DIR}/.env.production" | |
| fi | |
| # Docker μ΄λ―Έμ§ λΉλ | |
| echo "π¨ Building Docker image..." | |
| DOCKER_BUILDKIT=1 docker compose build ${CONTAINER_NAME} | |
| # 컨ν μ΄λ κ΅μ²΄ (무μ€λ¨ λ°°ν¬) | |
| echo "π Updating container..." | |
| docker compose up -d --no-deps ${CONTAINER_NAME} | |
| # λ€λ₯Έ 컨ν μ΄λ μ¬μμ | |
| echo "π Restarting other container..." | |
| docker compose up -d ${OTHER_CONTAINER} | |
| # ν¬μ€μ²΄ν¬ | |
| echo "π₯ Health check..." | |
| sleep 10 | |
| if docker ps | grep -q ${CONTAINER_NAME}; then | |
| echo "β Container is running" | |
| docker logs --tail 20 ${CONTAINER_NAME} | |
| else | |
| echo "β Container failed to start" | |
| docker logs ${CONTAINER_NAME} | |
| exit 1 | |
| fi | |
| echo "β Deployment completed successfully!" |