[Fix] 초기화 후 재배포 진행 #41
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 HHPlus to EC2 | |
| on: | |
| push: | |
| branches: [ main ] | |
| permissions: | |
| contents: read | |
| id-token: write | |
| jobs: | |
| build_and_push: | |
| name: 🚀 Build & Push to ECR | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: 17 | |
| - name: Generate Spring & Redisson config | |
| run: | | |
| echo "${{ secrets.APPLICATION_YML }}" > src/main/resources/application.yml | |
| echo "${{ secrets.APPLICATION_DOCKER_YML }}" > src/main/resources/application-docker.yml | |
| echo "${{ secrets.REDISSON_DOCKER_YML }}" > src/main/resources/redisson-docker.yml | |
| - name: Build jar and Docker image | |
| run: | | |
| chmod +x ./gradlew | |
| ./gradlew clean build -x test | |
| docker build -t hhplus-server . | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-region: us-east-1 | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| - name: Login to Amazon ECR | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| - name: Tag and push Docker image | |
| run: | | |
| docker tag hhplus-server:latest \ | |
| 116981801268.dkr.ecr.us-east-1.amazonaws.com/hhplus-server:latest | |
| docker push 116981801268.dkr.ecr.us-east-1.amazonaws.com/hhplus-server:latest | |
| deploy: | |
| name: 🐳 Deploy via Docker Compose | |
| needs: build_and_push | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 0️⃣ Repository checkout (없으면 docker-compose.yml 이 workspace에 없습니다) | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| # 1️⃣ docker-compose.yml 파일을 EC2로 복사 | |
| - name: Copy docker-compose.yml to EC2 | |
| uses: appleboy/scp-action@master | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USERNAME }} | |
| key: ${{ secrets.EC2_PRIVATE_KEY }} | |
| source: "docker-compose.yml" | |
| target: "/home/ubuntu/hhplus-server-java/" # ← 디렉터리로 지정 (끝에 슬래시!) | |
| # 2️⃣ SSH로 접속해 실제로 pull & up | |
| - name: SSH to EC2 and deploy | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USERNAME }} | |
| key: ${{ secrets.EC2_PRIVATE_KEY }} | |
| script_stop: true | |
| script: | | |
| set -eux | |
| # 배포 디렉토리 보장 | |
| mkdir -p /home/ubuntu/hhplus-server-java | |
| cd /home/ubuntu/hhplus-server-java | |
| export COMPOSE_HTTP_TIMEOUT=200 | |
| # 이미지 pull & 컨테이너 up | |
| docker compose pull | |
| docker compose up -d | |
| docker compose ps |