-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#114 - Github Actions CI & CD 프로필별 분리
#114 - Github Actions CI & CD 프로필별 분리
- Loading branch information
Showing
8 changed files
with
295 additions
and
63 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,90 @@ | ||
name: Java CI with Gradle | ||
|
||
on: | ||
push: | ||
branches: [ "deploy/#114" ] | ||
|
||
env: | ||
S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME_DEV }} | ||
CODE_DEPLOY_APPLICATION_NAME: dodal-code-deploy | ||
CODE_DEPLOY_DEPLOYMENT_GROUP: deploy | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '11' | ||
distribution: 'temurin' | ||
- name: make application-dev.yml | ||
run: | | ||
cd ./src/main/resources | ||
touch ./application-dev.yml | ||
echo "${{ secrets.APPLICATION_DEV }}" > ./application-dev.yml | ||
touch ./application.yml | ||
echo "${{ secrets.APPLICATION_YML }}" > ./application.yml | ||
cd ../../test/resources | ||
touch ./application.yml | ||
echo "${{ secrets.APPLICATION_YML }}" > ./application.yml | ||
- name: create-json | ||
id: create-json | ||
uses: jsdaniell/[email protected] | ||
with: | ||
name: "dodal-fcm.json" | ||
json: ${{ secrets.FCM_JSON }} | ||
dir: src/main/resources | ||
|
||
- name: Build with Gradle | ||
run: | | ||
./gradlew cleanQuerydslSourceDir | ||
./gradlew build | ||
# 전송할 JAR 파일을 담을 디렉토리 생성 | ||
- name: Make Directory for deliver | ||
run: mkdir ./deploy | ||
|
||
- name: Copy Jar | ||
run: | | ||
chmod +x ./build/libs/*.jar | ||
cp ./build/libs/*.jar ./deploy/ | ||
cp ./appspec-dev.yml ./deploy/appspec.yml | ||
mkdir -p ./deploy/scripts | ||
cp ./scripts/deploy-dev.sh ./deploy/scripts/deploy-dev.sh | ||
# 압축파일 형태로 전달 | ||
- name: Make zip fileㅊ | ||
run: | | ||
cd ./deploy | ||
zip -r ./deploy-dev.zip . | ||
# S3 Bucket으로 copy | ||
- name: Deliver to AWS S3 | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_S3_ACCESS_KEY_DEV }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_S3_SECRET_KEY_DEV }} | ||
run: | | ||
aws s3 cp \ | ||
--region ap-northeast-2 \ | ||
--acl private ./deploy/deploy-dev.zip s3://${{ env.S3_BUCKET_NAME }}/deploy/deploy-dev.zip | ||
# CodeDeploy | ||
- name: Deploy | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_CODE_DEPLOY_ACCESS_KEY_DEV }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_CODE_DEPLOY_SECRET_KEY_DEV }} | ||
run: | | ||
aws deploy create-deployment \ | ||
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \ | ||
--deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP }} \ | ||
--file-exists-behavior OVERWRITE \ | ||
--ignore-application-stop-failures \ | ||
--s3-location bucket=${{ env.S3_BUCKET_NAME }},bundleType=zip,key=deploy/deploy-dev.zip \ | ||
--region ap-northeast-2 |
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,90 @@ | ||
name: Java CI with Gradle | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
|
||
env: | ||
S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME_PRD }} | ||
CODE_DEPLOY_APPLICATION_NAME: dodal-code-deploy | ||
CODE_DEPLOY_DEPLOYMENT_GROUP: deploy | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '11' | ||
distribution: 'temurin' | ||
- name: make application-prd.yml | ||
run: | | ||
cd ./src/main/resources | ||
touch ./application-prd.yml | ||
echo "${{ secrets.APPLICATION_PRD }}" > ./application-prd.yml | ||
touch ./application.yml | ||
echo "${{ secrets.APPLICATION_YML }}" > ./application.yml | ||
cd ../../test/resources | ||
touch ./application.yml | ||
echo "${{ secrets.APPLICATION_YML }}" > ./application.yml | ||
- name: create-json | ||
id: create-json | ||
uses: jsdaniell/[email protected] | ||
with: | ||
name: "dodal-fcm.json" | ||
json: ${{ secrets.FCM_JSON }} | ||
dir: src/main/resources | ||
|
||
- name: Build with Gradle | ||
run: | | ||
./gradlew cleanQuerydslSourceDir | ||
./gradlew build | ||
# 전송할 JAR 파일을 담을 디렉토리 생성 | ||
- name: Make Directory for deliver | ||
run: mkdir ./deploy | ||
|
||
- name: Copy Jar | ||
run: | | ||
chmod +x ./build/libs/*.jar | ||
cp ./build/libs/*.jar ./deploy/ | ||
cp ./appspec-prd.yml ./deploy/appspec.yml | ||
mkdir -p ./deploy/scripts | ||
cp ./scripts/deploy-prd.sh ./deploy/scripts/deploy-prd.sh | ||
# 압축파일 형태로 전달 | ||
- name: Make zip file | ||
run: | | ||
cd ./deploy | ||
zip -r ./deploy-prd.zip . | ||
# S3 Bucket으로 copy | ||
- name: Deliver to AWS S3 | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_S3_ACCESS_KEY_PRD }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_S3_SECRET_KEY_PRD }} | ||
run: | | ||
aws s3 cp \ | ||
--region ap-northeast-2 \ | ||
--acl private ./deploy/deploy-prd.zip s3://${{ env.S3_BUCKET_NAME }}/deploy/deploy-prd.zip | ||
# CodeDeploy | ||
- name: Deploy | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_CODE_DEPLOY_ACCESS_KEY_PRD }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_CODE_DEPLOY_SECRET_KEY_PRD }} | ||
run: | | ||
aws deploy create-deployment \ | ||
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \ | ||
--deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP }} \ | ||
--file-exists-behavior OVERWRITE \ | ||
--ignore-application-stop-failures \ | ||
--s3-location bucket=${{ env.S3_BUCKET_NAME }},bundleType=zip,key=deploy/deploy-prd.zip \ | ||
--region ap-northeast-2 |
This file was deleted.
Oops, something went wrong.
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
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,16 @@ | ||
version: 0.0 | ||
os: linux | ||
files: | ||
- source: / | ||
destination: /home/ec2-user/app/deploy | ||
overwrite: yes | ||
permissions: | ||
- object: / | ||
pattern: "**" | ||
owner: ec2-user | ||
group: ec2-user | ||
hooks: | ||
ApplicationStart: | ||
- location: scripts/deploy-dev.sh | ||
timeout: 300 | ||
runas: ec2-user |
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,16 @@ | ||
version: 0.0 | ||
os: linux | ||
files: | ||
- source: / | ||
destination: /home/ec2-user/app/deploy | ||
overwrite: yes | ||
permissions: | ||
- object: / | ||
pattern: "**" | ||
owner: ec2-user | ||
group: ec2-user | ||
hooks: | ||
ApplicationStart: | ||
- location: scripts/deploy-prd.sh | ||
timeout: 300 | ||
runas: ec2-user |
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,41 @@ | ||
#!/bin/bash | ||
|
||
SERVICE_PATH="/home/ec2-user/app/deploy" | ||
|
||
echo ">>> 모든 Docker 컨테이너를 정지하고 삭제합니다." >> $SERVICE_PATH/deploy.log | ||
sudo docker stop $(sudo docker ps -qa) | ||
sudo docker rm $(sudo docker ps -qa) | ||
|
||
echo ">>> 모든 Docker 이미지를 삭제합니다." >> $SERVICE_PATH/deploy.log | ||
sudo docker image prune -a -f | ||
|
||
echo ">>> Redis 이미지를 가져옵니다." >> $SERVICE_PATH/deploy.log | ||
sudo docker pull redis:alpine | ||
|
||
echo ">>> Redis 컨테이너를 실행합니다." >> $SERVICE_PATH/deploy.log | ||
sudo docker run --name redis -d -p 6379:6379 redis:alpine | ||
|
||
BUILD_JAR=$(ls $SERVICE_PATH/*.jar) | ||
JAR_NAME=$(basename $BUILD_JAR) | ||
|
||
echo ">>> build 파일명: $JAR_NAME" >> $SERVICE_PATH/deploy.log | ||
|
||
echo ">>> build 파일 복사" >> $SERVICE_PATH/deploy.log | ||
DEPLOY_PATH=$SERVICE_PATH/ | ||
cp $BUILD_JAR $DEPLOY_PATH | ||
|
||
echo ">>> 현재 실행중인 애플리케이션 pid 확인" >> $SERVICE_PATH/deploy.log | ||
CURRENT_PID=$(pgrep -f $JAR_NAME) | ||
|
||
if [ -z $CURRENT_PID ] | ||
then | ||
echo ">>> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." >> $SERVICE_PATH/deploy.log | ||
else | ||
echo ">>> kill -15 $CURRENT_PID" | ||
kill -15 $CURRENT_PID | ||
sleep 5 | ||
fi | ||
|
||
DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME | ||
echo ">>> DEPLOY_JAR 배포" >> $SERVICE_PATH/deploy.log | ||
nohup java -jar -Dspring.profiles.active=dev $DEPLOY_JAR >> /home/ec2-user/dodal-app.log 2> $SERVICE_PATH/dodal-app.log & |
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,41 @@ | ||
#!/bin/bash | ||
|
||
SERVICE_PATH="/home/ec2-user/app/deploy" | ||
|
||
echo ">>> 모든 Docker 컨테이너를 정지하고 삭제합니다." >> $SERVICE_PATH/deploy.log | ||
sudo docker stop $(sudo docker ps -qa) | ||
sudo docker rm $(sudo docker ps -qa) | ||
|
||
echo ">>> 모든 Docker 이미지를 삭제합니다." >> $SERVICE_PATH/deploy.log | ||
sudo docker image prune -a -f | ||
|
||
echo ">>> Redis 이미지를 가져옵니다." >> $SERVICE_PATH/deploy.log | ||
sudo docker pull redis:alpine | ||
|
||
echo ">>> Redis 컨테이너를 실행합니다." >> $SERVICE_PATH/deploy.log | ||
sudo docker run --name redis -d -p 6379:6379 redis:alpine | ||
|
||
BUILD_JAR=$(ls $SERVICE_PATH/*.jar) | ||
JAR_NAME=$(basename $BUILD_JAR) | ||
|
||
echo ">>> build 파일명: $JAR_NAME" >> $SERVICE_PATH/deploy.log | ||
|
||
echo ">>> build 파일 복사" >> $SERVICE_PATH/deploy.log | ||
DEPLOY_PATH=$SERVICE_PATH/ | ||
cp $BUILD_JAR $DEPLOY_PATH | ||
|
||
echo ">>> 현재 실행중인 애플리케이션 pid 확인" >> $SERVICE_PATH/deploy.log | ||
CURRENT_PID=$(pgrep -f $JAR_NAME) | ||
|
||
if [ -z $CURRENT_PID ] | ||
then | ||
echo ">>> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." >> $SERVICE_PATH/deploy.log | ||
else | ||
echo ">>> kill -15 $CURRENT_PID" | ||
kill -15 $CURRENT_PID | ||
sleep 5 | ||
fi | ||
|
||
DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME | ||
echo ">>> DEPLOY_JAR 배포" >> $SERVICE_PATH/deploy.log | ||
nohup java -jar -Dspring.profiles.active=prd $DEPLOY_JAR >> /home/ec2-user/dodal-app.log 2> $SERVICE_PATH/dodal-app.log & |