From 5a479c8d528778e42c3dfaad5c8c49dee3103b67 Mon Sep 17 00:00:00 2001 From: "Sunguk Yang (Kelly)" Date: Tue, 23 Jul 2024 21:15:31 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20CD=20=ED=8C=8C=EC=9D=BC=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/be-cd.yml | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .github/workflows/be-cd.yml diff --git a/.github/workflows/be-cd.yml b/.github/workflows/be-cd.yml new file mode 100644 index 000000000..500bf7c45 --- /dev/null +++ b/.github/workflows/be-cd.yml @@ -0,0 +1,65 @@ +name: Coduo Backend CD + +on: + push: + branches: ["BE/main"] + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./backend + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: "17" + distribution: "corretto" + + - name: Make prod application.yml + run: | + rm -rf ./src/main/resources/application.yml + touch ./src/main/resources/application.yml + echo ${{ secrets.BE_PROD_YML }} | base64 --decode > ./src/main/resources/application.yml + shell: bash + + - name: Gradle Caching + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Grant Execute Permission For Gradlew + run: chmod +x gradlew + + - name: Build With Gradle + run: ./gradlew build -x test + + - name: Docker build & Push + run: | + docker login -u ${{ secrets.DOCKER_HUB_ID }} -p ${{ secrets.DOCKER_HUB_PASSWORD }} + docker buildx build --platform=linux/arm64 -t ${{ secrets.DOCKER_HUB_REPO }}/springboot-app . + docker push ${{ secrets.DOCKER_HUB_REPO }}/springboot-app + + - name: Deploy Images with Docker compose + uses: appleboy/ssh-action@master + env: + PROJECT: "coduo" + with: + username: ec2-user + host: ${{ secrets.BE_EC2_HOST }} + key: ${{ secrets.BE_EC2_PRIVATE_KEY }} + envs: PROJECT + script_stop: true + script: | + docker compose -p $PROJECT down + docker pull ${{ secrets.DOCKER_HUB_REPO }}/springboot-app + docker compose -p $PROJECT up -d