Skip to content

Commit

Permalink
feat(workflows): action runner를 이용한 백엔드 CD 파이프라인 구축
Browse files Browse the repository at this point in the history
  • Loading branch information
kyum-q committed Jul 19, 2024
1 parent 2e7c172 commit e99a34e
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/backend_cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Backend CD

on:
push:
branches:
- develop
- main

jobs:
build:
runs-on: ubuntu-latest
env:
build-directory: ./backend
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin

- 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: Build BootJar
run: ./gradlew bootJar
working-directory: ${{ env.build-directory }}

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: code-zap-jar
path: backend/build/libs/*.jar

deploy:
needs: build
runs-on: self-hosted
steps:
- name: Get Artifact Download URL
id: get-artifact-url
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
artifacts=$(curl -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/actions/artifacts)
artifact_id=$(echo "$artifacts" | jq -r '.artifacts[0].id') # 가장 최근 아티팩트의 id를 가져옴
if [[ -z "$artifact_id" || "$artifact_id" == "null" ]]; then
echo "Artifact ID not found or invalid"
exit 1
fi
download_url="https://api.github.com/repos/${{ github.repository }}/actions/artifacts/$artifact_id/zip"
echo "DOWNLOAD_URL=${download_url}" >> $GITHUB_ENV
- name: Download Artifact
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WORK_DIRECTORY: ${{ secrets.WORK_DIRECTORY }}
run: |
curl -L -o ${{ secrets.WORK_DIRECTORY }}/code-zap-jar.zip -H "Authorization: token $GITHUB_TOKEN" ${{ env.DOWNLOAD_URL }}
- name: Run Deploy Script
run: |
cd ${{ secrets.WORK_DIRECTORY }}
unzip -o code-zap-jar.zip
RUNNER_TRACKING_ID="" && ./deploy.sh
- name: Verify Deploy Succeed
run: |
sleep 10 # Ensure there is enough time for the application to start
pgrep -f 'java -jar' || { echo "Deploy Failed" }

0 comments on commit e99a34e

Please sign in to comment.