-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(workflows): action runner를 이용한 백엔드 CD 파이프라인 구축
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } |