-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setting: githubActions와 codeDeploy를 이용한 자동배포 스크립트 작성
- Loading branch information
Showing
3 changed files
with
85 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,55 @@ | ||
name: CD | ||
|
||
on: | ||
push: | ||
branches: [ "main", "feature/deploy" ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
token: ${{secrets.PRIVATE_TOKEN}} | ||
submodules: true | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
- name: Make directory for deliver | ||
run: mkdir deploy | ||
|
||
- name: Build with Gradle | ||
run: ./gradlew clean build | ||
|
||
- name: Copy jar | ||
run: cp ./build/libs/*.jar ./$GITHUB_SHA.jar | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ap-northeast-2 | ||
|
||
- name: Upload to S3 | ||
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.jar s3://team3rdparty-bucket/deploy/$GITHUB_SHA.jar | ||
|
||
- name: Deploy | ||
run: | | ||
aws deploy create-deployment \ | ||
--application-name ticketing \ | ||
--deployment-config-name CodeDeployDefault.AllAtOnce \ | ||
--deployment-group-name ticketing \ | ||
--file-exists-behavior OVERWRITE \ | ||
--s3-location bucket=team3rdparty-bucket,bundleType=zip,key=deploy/$GITHUB_SHA.zip \ | ||
--region ap-northeast-2 \ | ||
--ec2-tag-filter Key=Name,Value=team3-ticket,Type=KEY_AND_VALUE |
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,11 @@ | ||
version: 0.0 | ||
os: linux | ||
files: | ||
- source: /*.jar | ||
destination: /home/ubuntu/deploy/ticketing.jar | ||
|
||
hooks: | ||
ApplicationStart: | ||
- location: scripts/deploy.sh | ||
timeout: 300 | ||
runas: ubuntu |
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,19 @@ | ||
#!/bin/bash | ||
|
||
# 변수 설정 | ||
build_jar=$(ls /home/ubuntu/app/deploy/ticketing.jar) | ||
jar_name=$(basename "$build_jar") | ||
deploy_log=/home/ubuntu/app/deploy/deloy.log | ||
|
||
echo ">>> 현재 실행중인 애플리케이션 pid 확인" >> $deploy_log | ||
CURRENT_PID=$(pgrep -f "$jar_name") | ||
|
||
if [ -z "$CURRENT_PID" ] | ||
then | ||
echo ">>> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." >> $deploy_log | ||
else | ||
kill -9 "$CURRENT_PID" | ||
fi | ||
|
||
echo ">>> DEPLOY_JAR 배포" >> $deploy_log | ||
nohup java -jar "$build_jar" --spring.profiles.active=prod |