From 65dc3754ec0679ac8c9520e33c94588265dc3c45 Mon Sep 17 00:00:00 2001 From: seo-young Date: Thu, 15 Feb 2024 16:08:04 +0900 Subject: [PATCH] =?UTF-8?q?[chore]=20cd=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd.yml | 45 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 959ad93..7b8b2e6 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,6 +1,9 @@ -name: ci +name: cd -on: [push] +on: + push: + branches: + - main jobs: build: @@ -10,13 +13,13 @@ jobs: - uses: actions/checkout@v4 - name: Set up JDK 17 - uses: actions/Setup-java@v4 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' - name: Gradle Caching - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.gradle/caches @@ -25,8 +28,42 @@ jobs: restore-keys: | ${{ runner.os }}-gradle- + - name: Make application-prod.yml + run: | + cd ./src/main/resources + touch ./application-prod.yml + echo "${{ secrets.APPLICATION_PROD }}" > ./application-prod.yml + shell: bash + - name: Grant Execute Permission For Gradlew run: chmod +x gradlew - name: Build With Gradle run: ./gradlew build + + - name: Docker build & push to docker repo + env: + DOCKER_PATH : .deploy/Dockerfile + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -f $DOCKER_PATH -t ${{ secrets.DOCKER_REPO }}/mookive . + docker push ${{ secrets.DOCKER_REPO }}/mookive + + - name: Deploy to Prob + uses: appleboy/ssh-action@master + id: deploy-prob + env: + DOCKER_COMPOSE : ".deploy/docker-compose.yml" + with: + host: ${{ secrets.EC2_HOST }} + username: ubuntu + key: ${{ secrets.EC2_KEY }} + envs: GITHUB_SHA + script: | + touch ./docker-compose.yml + echo "${{ secrets.DOCKER_COMPOSE }}" > ./docker-compose.yml + docker stop mookive + docker rm mookive + docker pull ${{ secrets.DOCKER_REPO }}/mookive + docker-compose up -d + docker image prune