From 2c76c3c9e5c7796d6a903289799998a38473143f Mon Sep 17 00:00:00 2001 From: SeungChul Chung Date: Wed, 22 Nov 2023 16:15:56 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=EB=A7=88=EC=9D=B4=EA=B7=B8?= =?UTF-8?q?=EB=A0=88=EC=9D=B4=EC=85=98=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=84=9C=EB=B2=84=20=EB=B0=B0=ED=8F=AC=EC=9A=A9=20github=20act?= =?UTF-8?q?ion=20=EC=B6=94=EA=B0=80=20(#320)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test-migrate-deploy.yml | 86 +++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 .github/workflows/test-migrate-deploy.yml diff --git a/.github/workflows/test-migrate-deploy.yml b/.github/workflows/test-migrate-deploy.yml new file mode 100644 index 000000000..f0b5e3d39 --- /dev/null +++ b/.github/workflows/test-migrate-deploy.yml @@ -0,0 +1,86 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle + +name: test-migrate-deploy + +on: + workflow_dispatch: + +env: + DOCKER_USER: ${{ secrets.DOCKER_USER }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + IMAGE_NAME: wken5577/test-migrate-server + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + + - name: Make application ymls + run: | + cd ./src/main/resources + echo "${{ secrets.MIGRATE_APPLICATION_YML }}" | base64 -d > application.yml + shell: bash + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ env.DOCKER_USER }} + password: ${{ env.DOCKER_PASSWORD }} + + - name: Build with Gradle + run: ./gradlew clean build + + - name: build new docker image as latest tag + run: | + docker build -t ${{ env.IMAGE_NAME }}:latest . + docker push ${{ env.IMAGE_NAME }}:latest + + - name: Get Github Actions IP + id: ip + uses: haythem/public-ip@v1.3 + + - name: AWS Credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.AWS_TEST_MIGRATE_SECURITY_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_TEST_MIGRATE_SECURITY_SECRET_KEY }} + aws-region: ap-northeast-2 + + - name: Add Github Actions IP to Security group + run: | + aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_TEST_MIGRATE_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 + + - name: executing docker-compose up on test server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.TEST_MIGRATE_SERVER_HOST }} + username: ${{ secrets.TEST_MIGRATE_SERVER_USERNAME }} + key: ${{ secrets.TEST_MIGRATE_SERVER_PEM }} + script: | + cd ./docker + docker stop tomcat + docker rm tomcat + docker rmi ${{ env.IMAGE_NAME }}:latest + docker-compose up -d + + - name: Remove Github Actions IP From Security Group + run: | + aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_TEST_MIGRATE_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32