From 89c1884625c714be11f409b2045d10e03c19ace4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=84=B1=EC=9A=B0?= Date: Sun, 24 Sep 2023 13:22:53 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20ci=20cd=20prd=20=EC=84=A4=EC=A0=95=20(?= =?UTF-8?q?#43)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-docker-image-prd.yml | 37 ++++++++++++++++++++ .github/workflows/cd-prd.yml | 32 +++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 .github/workflows/build-docker-image-prd.yml create mode 100644 .github/workflows/cd-prd.yml diff --git a/.github/workflows/build-docker-image-prd.yml b/.github/workflows/build-docker-image-prd.yml new file mode 100644 index 0000000..af482b7 --- /dev/null +++ b/.github/workflows/build-docker-image-prd.yml @@ -0,0 +1,37 @@ +name: Build Backend Image Prd + +on: + workflow_call: + secrets: + DOCKERHUB_USERNAME: + required: true + DOCKERHUB_PASSWORD: + required: true + PRD_DOCKER_AUTHENTICATION_IMAGE_NAME: + required: true + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v1 + with: + java-version: '17' + distribution: 'temurin' + + - name: Login to Docker Hub + uses: docker/login-action@v2.1.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Grant execute permission for gradlew + run: chmod +x ./gradlew + + - name: Build with jib + run: ./gradlew jib --image="${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PRD_DOCKER_AUTHENTICATION_IMAGE_NAME }}" diff --git a/.github/workflows/cd-prd.yml b/.github/workflows/cd-prd.yml new file mode 100644 index 0000000..19a7b32 --- /dev/null +++ b/.github/workflows/cd-prd.yml @@ -0,0 +1,32 @@ +name : cd - prd + +on: + push: + branches: + - main + +jobs: + build-back-docker-img: + uses: ./.github/workflows/build-docker-image-prd.yml + secrets: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} + PRD_DOCKER_AUTHENTICATION_IMAGE_NAME: ${{ secrets.PRD_DOCKER_AUTHENTICATION_IMAGE_NAME }} + + deploy: + needs: build-back-docker-img + runs-on: ubuntu-latest + steps: + - name: executing remote ssh commands using password + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.PRD_HOST }} + username: ${{ secrets.PRD_HOST_USER_NAME }} + key: ${{ secrets.PRD_PRIVATE_KEY }} + script: | + cd ${{ secrets.PRD_DEPLOY_DIRECTORY }} + docker compose stop ${{ secrets.PRD_DOCKER_AUTHENTICATION_CONTAINER_NAME }} + docker compose rm -f ${{ secrets.PRD_DOCKER_AUTHENTICATION_CONTAINER_NAME }} + docker image rm ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PRD_DOCKER_AUTHENTICATION_IMAGE_NAME }} + docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PRD_DOCKER_AUTHENTICATION_IMAGE_NAME }} + docker compose up -d