fix : application.yml 설정 변경 #16
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: Build and Deploy to EC2 | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| env: | |
| GCP_PROJECT_ID: "lessonplatform-495307" | |
| GCP_REGION: "asia-northeast3" | |
| ARTIFACT_REGISTRY_REPO: "notification-server-repo" # GCP에 만들 이미지 저장소 이름 | |
| IMAGE_NAME: "spring-app" | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write # GCP Workload Identity와 통신하기 위한 OIDC 토큰 발행 권한 | |
| steps: | |
| - name: Code Checkout | |
| uses: actions/checkout@v4 | |
| # 2. JDK 설정 및 자바 스프링 빌드 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| cache: gradle | |
| - name: Build Spring Boot Application | |
| run: ./gradlew build -x test | |
| # 3. GCP 인증 (Workload Identity) | |
| - name: Authenticate to Google Cloud | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} | |
| service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} | |
| # 4. 도커 이미지 빌드 및 GCP Artifact Registry로 Push | |
| - name: Configure Docker for GCP | |
| run: gcloud auth configure-docker asia-northeast3-docker.pkg.dev | |
| - name: Build and Push Docker Image | |
| run: | | |
| docker build -t asia-northeast3-docker.pkg.dev/$GCP_PROJECT_ID/$ARTIFACT_REGISTRY_REPO/$IMAGE_NAME:latest . | |
| docker push asia-northeast3-docker.pkg.dev/$GCP_PROJECT_ID/$ARTIFACT_REGISTRY_REPO/$IMAGE_NAME:latest | |
| # 5. CP VM의 컨테이너 이미지 업데이트 및 재시작 명령 | |
| - name: Deploy to GCP Compute Engine | |
| run: | | |
| gcloud compute instances reset spring-app-vm --zone=asia-northeast3-a | |
| # # 4. EC2 Docker 이미지 pull 및 docker run | |
| # - name: Deploy to EC2 | |
| # uses: appleboy/ssh-action@v1.0.3 | |
| # with: | |
| # host: ${{ secrets.EC2_HOST }} | |
| # username: ec2-user | |
| # key: ${{ secrets.EC2_KEY }} | |
| # script: | | |
| # aws ecr get-login-password --region ap-southeast-2 \ | |
| # | docker login \ | |
| # --username AWS \ | |
| # --password-stdin ${{ steps.login-ecr.outputs.registry }} | |
| # docker pull ${{ steps.login-ecr.outputs.registry }}/lesson-platform/server:${{ github.sha }} | |
| # docker stop lesson-server || true | |
| # docker rm lesson-server || true | |
| # docker run -d -p 8080:8080 \ | |
| # --name lesson-server \ | |
| # -e DB_SERVER= ${{ secrets.DB_HOST }} \ | |
| # -e TOSS_SECRET_KEY= ${{ secrets.PSP_TOSS_SECRET_KEY }} \ | |
| # ${{ steps.login-ecr.outputs.registry }}/lesson-platform/server:${{ github.sha }} | |