Merge pull request #36 from BusanHackathon/refactor/#34-cors #31
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: BUSAN-PJ Deploy To EC2 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| Server-Deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Github Repository 파일 불러오기 | |
| uses: actions/checkout@v4 | |
| - name: JDK 17버전 설치 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: 17 | |
| - name: application-dev-oauth.yml 파일 생성하기 | |
| run: | | |
| echo "${{ secrets.APPLICATION_DEV_OAUTH_YML }}" | base64 --decode > ./src/main/resources/application-dev-oauth.yml | |
| - name: application-dev.yml 파일 생성하기 | |
| run: | | |
| echo "${{ secrets.APPLICATION_DEV_YML }}" | base64 --decode > ./src/main/resources/application-dev.yml | |
| - name: 빌드 권한 부여 | |
| run: chmod +x ./gradlew | |
| - name: 테스트 및 빌드하기 | |
| run: ./gradlew clean build -x test | |
| - name: AWS Resource에 접근할 수 있게 AWS credentials 설정 | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-region: ap-northeast-2 | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| - name: ECR에 로그인하기 | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| - name: Docker 이미지 생성 | |
| run: docker build -t busan . | |
| - name: Docker 이미지에 Tag 붙이기 | |
| run: docker tag busan ${{ steps.login-ecr.outputs.registry }}/busan:latest | |
| - name: ECR에 Docker 이미지 Push하기 | |
| run: docker push ${{ steps.login-ecr.outputs.registry }}/busan:latest | |
| - name: SSH로 bastion host 접속 및 실제 서버에 배포하기 | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.BASTION_HOST }} | |
| username: ${{ secrets.BASTION_USERNAME }} | |
| key: ${{ secrets.BASTION_PRIVATE_KEY }} | |
| script_stop: true | |
| script: | | |
| ssh -o StrictHostKeyChecking=no \ | |
| -i ~/.ssh/google_compute_engine \ | |
| yangjunsig@${{ secrets.PRIVATE_EC2_INTERNAL_IP }} << 'EOF' | |
| aws ecr get-login-password --region ap-northeast-2 \ | |
| | docker login --username AWS --password-stdin ${{ steps.login-ecr.outputs.registry }} | |
| docker stop busan || true | |
| docker rm busan || true | |
| docker pull ${{ steps.login-ecr.outputs.registry }}/busan:latest | |
| docker run -d --name busan --restart=unless-stopped \ | |
| -e SPRING_PROFILES_ACTIVE=dev \ | |
| -p 8080:8080 \ | |
| ${{ steps.login-ecr.outputs.registry }}/busan:latest | |
| EOF |