feat: 설문조사 구현 #29
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 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Github Repository 파일 불러오기 | |
| uses: actions/checkout@v4 | |
| - name: JDK 21버전 설치 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: 21 | |
| - name: Gradle 캐싱 | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
| restore-keys: | | |
| ${{ runner.os }}-gradle- | |
| - name: 운영용 .properties로 교체 | |
| run: echo "${{ secrets.APPLICATION_PROPERTIES }}" > ./src/main/resources/application.properties | |
| - name: 테스트 환경변수 주입 | |
| run: echo "${{ secrets.APPLICATION_TEST_PROPERTIES }}" > ./src/test/resources/application.properties | |
| - name: 테스트 및 빌드하기 | |
| run: ./gradlew clean build | |
| - 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 --platform linux/amd64 -t music . | |
| - name : Docker tag를 위한 날짜 설정 | |
| run: echo "date=$(date +%Y%m%d-%H%M%S)" >> $GITHUB_ENV | |
| - name: Docker 이미지에 Tag 붙이기 | |
| run: docker tag music ${{ steps.login-ecr.outputs.registry }}/music:${{env.date}} | |
| - name: ECR에 Docker 이미지 Push하기 | |
| run: docker push ${{ steps.login-ecr.outputs.registry }}/music:${{env.date}} | |
| - name: SSH로 EC2에 접속하기 | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USERNAME }} | |
| key: ${{ secrets.EC2_PRIVATE_KEY }} | |
| script_stop: true | |
| script: | | |
| docker pull ${{ steps.login-ecr.outputs.registry }}/music:${{env.date}} | |
| docker stop music || true | |
| docker rm music || true | |
| docker run -d \ | |
| --restart=always \ | |
| -e TZ=Asia/Seoul \ | |
| --name music \ | |
| -p 8080:8080 \ | |
| -v /home/ubuntu/logs:/app/logs \ | |
| ${{ steps.login-ecr.outputs.registry }}/music:${{env.date}} |