Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INIT] CD 설정하기 #29

Merged
merged 15 commits into from
Jan 9, 2024
60 changes: 60 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: deploy

on:
push:
branches: [ develop ]

jobs:
build:
runs-on: ubuntu-22.04

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
cache: gradle

- name: Create application-secret.yml
run: |
pwd
touch src/main/resources/application-secret.yml
echo "${{ secrets.APPLICATION_SECRET_YML }}" >> src/main/resources/application-secret.yml
cat src/main/resources/application-secret.yml

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ secrets.ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.ACCESS_KEY_SECRET }}
aws-region: ap-northeast-2

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash

- name: Build with Gradle
run: ./gradlew build
shell: bash

- name: Make zip file
run: zip -qq -r ./$GITHUB_SHA.zip .
shell: bash

- name: Upload to AWS S3
run: |
aws deploy push \
--application-name sopetit-codedeploy \
--ignore-hidden-files \
--s3-location s3://${{ secrets.AWS_BUCKET_NAME }}/$GITHUB_SHA.zip \
--source .

- name: Code Deploy
run: aws deploy create-deployment --application-name sopetit-codedeploy
--deployment-config-name CodeDeployDefault.AllAtOnce
--deployment-group-name sopetit-group
--s3-location bucket=${{ secrets.AWS_BUCKET_NAME }},bundleType=zip,key=$GITHUB_SHA.zip
19 changes: 19 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 0.0
os: linux

files:
- source: /
destination: /home/ubuntu/build
overwrite: yes

permissions:
- object: /home/ubuntu
pattern: '**'
owner: ubuntu
group: ubuntu

hooks:
AfterInstall:
- location: scripts/deploy.sh
timeout: 1000
runas: ubuntu
20 changes: 20 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
REPOSITORY=/home/ubuntu/build
cd $REPOSITORY

APP_NAME=pearls
JAR_NAME=$(ls $REPOSITORY/build/libs/ | grep '.jar' | tail -n 1)
JAR_PATH=$REPOSITORY/build/libs/$JAR_NAME

CURRENT_PID=$(pgrep -f $APP_NAME)

if [ -z $CURRENT_PID ]
then
echo "> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다."
else
echo "> kill -15 $CURRENT_PID"
sudo kill -15 $CURRENT_PID
sleep 5
fi

echo "> $JAR_PATH 배포"
nohup java -jar -Dspring.profiles.active=dev /home/ubuntu/build/build/libs/server-0.0.1-SNAPSHOT.jar > /dev/null 2> /dev/null < /dev/null &
79 changes: 79 additions & 0 deletions src/main/resources/static/docs/open-api-3.0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,53 @@
}
}
},
"/api/v1/routines/daily/member" : {
"post" : {
"tags" : [ "MEMBER DAILY ROUTINE" ],
"summary" : "회원 데일리 루틴 추가 성공",
"description" : "회원 데일리 루틴 추가 성공",
"operationId" : "post-routine-docs",
"requestBody" : {
"content" : {
"application/json;charset=UTF-8" : {
"schema" : {
"$ref" : "#/components/schemas/api-v1-routines-daily-member1721287602"
},
"examples" : {
"post-routine-docs" : {
"value" : "{\n \"routineId\" : 1\n}"
}
}
}
}
},
"responses" : {
"201" : {
"description" : "201",
"headers" : {
"Location" : {
"description" : "Redirect URI",
"schema" : {
"type" : "string"
}
}
},
"content" : {
"application/json;charset=UTF-8" : {
"schema" : {
"$ref" : "#/components/schemas/api-v1-routines-daily-member1327124516"
},
"examples" : {
"post-routine-docs" : {
"value" : "{\n \"success\" : true,\n \"message\" : \"루틴 추가 성공\",\n \"data\" : {\n \"routineId\" : 1\n }\n}"
}
}
}
}
}
}
}
},
"/api/v1/routines/daily/themes" : {
"get" : {
"tags" : [ "DAILY ROUTINE" ],
Expand Down Expand Up @@ -167,6 +214,15 @@
}
}
},
"api-v1-routines-daily-member1721287602" : {
"type" : "object",
"properties" : {
"routineId" : {
"type" : "number",
"description" : "추가할 루틴 id"
}
}
},
"api-v1-routines-daily-themes1975236624" : {
"type" : "object",
"properties" : {
Expand Down Expand Up @@ -234,6 +290,29 @@
}
}
},
"api-v1-routines-daily-member1327124516" : {
"type" : "object",
"properties" : {
"data" : {
"type" : "object",
"properties" : {
"routineId" : {
"type" : "number",
"description" : "생성한 루틴 id"
}
},
"description" : "응답 데이터"
},
"success" : {
"type" : "boolean",
"description" : "응답 성공 여부"
},
"message" : {
"type" : "string",
"description" : "응답 메시지"
}
}
},
"api-v1-test486549215" : {
"type" : "object"
}
Expand Down