Skip to content

Commit 8224e91

Browse files
committed
chore : CI/CD 세팅
1 parent c581ab8 commit 8224e91

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

.github/workflows/CD.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: CD
2+
3+
on:
4+
push:
5+
branches: ["master"]
6+
7+
env:
8+
S3_BUCKET_NAME: problemsolvingqueue
9+
PROJECT_NAME: psq
10+
11+
jobs:
12+
build:
13+
name: CD
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Set up JDK 11
19+
uses: actions/setup-java@v2
20+
with:
21+
java-version: '11'
22+
distribution: 'zulu'
23+
24+
- name: Grant execute permission for gradlew
25+
run: chmod +x ./gradlew
26+
shell: bash
27+
28+
- name: Build with Gradle
29+
run: ./gradlew build
30+
shell: bash
31+
32+
- name: Make zip file
33+
run: zip -r ./$GITHUB_SHA.zip .
34+
shell: bash
35+
36+
- name: Configure AWS credentials
37+
uses: aws-actions/configure-aws-credentials@v1
38+
with:
39+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
40+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
41+
aws-region: ${{ secrets.AWS_REGION }}
42+
43+
- name: Copy script
44+
run: cp ./scripts/*.sh ./deploy
45+
46+
- name: Upload to S3
47+
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$S3_BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip

backend/appspec.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: 0.0
2+
os: linux
3+
4+
files:
5+
- source: /
6+
destination: /home/ubuntu/app
7+
overwrite: yes
8+
9+
permissions:
10+
- object: /
11+
pattern: "**"
12+
owner: ubuntu
13+
group: ubuntu
14+
15+
hooks:
16+
AfterInstall:
17+
- location: scripts/stop.sh
18+
timeout: 60
19+
runas: ubuntu
20+
ApplicationStart:
21+
- location: scripts/start.sh
22+
timeout: 60
23+
runas: ubuntu

backend/deploy.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
BUILD_JAR=$(ls /home/ubuntu/app/build/libs/*.jar)
3+
JAR_NAME=$(basename $BUILD_JAR)
4+
echo "> build 파일명: $JAR_NAME" >> /home/ubuntu/app/deploy.log
5+
6+
echo "> build 파일 복사" >> /home/ubuntu/app/deploy.log
7+
DEPLOY_PATH=/home/ubuntu/app/action/
8+
cp $BUILD_JAR $DEPLOY_PATH
9+
10+
echo "> 현재 실행중인 애플리케이션 pid 확인" >> /home/ubuntu/app/deploy.log
11+
CURRENT_PID=$(pgrep -f $JAR_NAME)
12+
13+
if [ -z $CURRENT_PID ]
14+
then
15+
echo "> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." >> /home/ubuntu/app/deploy.log
16+
else
17+
echo "> kill -15 $CURRENT_PID"
18+
kill -15 $CURRENT_PID
19+
sleep 5
20+
fi
21+
22+
DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME
23+
echo "> DEPLOY_JAR 배포" >> /home/ubuntu/app/deploy.log
24+
nohup java -jar $DEPLOY_JAR >> /home/ubuntu/deploy.log 2>/home/ubuntu/app/deploy_err.log &

0 commit comments

Comments
 (0)