Skip to content

Commit

Permalink
๐Ÿ‘ท github action ๋ฐฐํฌ ์ฝ”๋“œ ์ถ”๊ฐ€ (#9)
Browse files Browse the repository at this point in the history
* ๐Ÿ‘ท Create main.yml

* ๐Ÿ‘ท aws s3 codedeploy ์ถ”๊ฐ€

* ๐Ÿ‘ท create appspec.yml

* ๐Ÿ‘ท Create deploy-before.sh

* ๐Ÿ‘ท ๋ฒ„ํ‚ท๋ช… ๋ณ€๊ฒฝ

* ๐Ÿ‘ท codedeploy ๋ณ€๊ฒฝ

* ๐Ÿ‘ท deploy-before ์‚ฌ์šฉ์ž๋ช… ์ˆ˜์ •

* ๐Ÿ‘ท deploy ์Šคํฌ๋ฆฝํŠธ ์ถ”๊ฐ€

* ๐Ÿ‘ท codedeploy script ์ˆ˜์ •

* ๐Ÿ‘ท Update deploy.sh

* ๐Ÿ‘ท ๋ฐฐํฌ jar ํŒŒ์ผ ์ด๋ฆ„ ๋ช…์‹œ

* ๐Ÿ‘ท port ๋ณ€๊ฒฝ

* ๐Ÿ‘ท appspec ํ•„์š”์—†๋Š” ์ฝ”๋“œ ์‚ญ์ œ

* ๐Ÿ‘ท log ํด๋” ์ƒ์„ฑ

* ๐Ÿ‘ท file_exists_behavior ์„ค์ •

* ๐Ÿ‘ท log ํด๋” ์œ„์น˜ ์ˆ˜์ •

* ๐Ÿ‘ท log ํด๋” mkdir

* ๐Ÿ‘ท add test code

* ๐Ÿ‘ท deploy jar log ์ˆ˜์ •

* ๐Ÿ‘ท ์‚ด์ง ์ˆ˜์ •

* ๐Ÿ‘ท test2

* Update MemberController.java

* ๐Ÿ‘ท project_name ๋ณ€๊ฒฝ

* ๐Ÿ‘ท destination ๊ฒฝ๋กœ ๋ณ€๊ฒฝ

* ๐Ÿ‘ท ํŒŒ์ผ destination ๋ณ€๊ฒฝ

* ํ…Œ์ŠคํŠธ
  • Loading branch information
soyeon207 authored Nov 13, 2023
1 parent f0b5ee6 commit cfcb2ea
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 11 deletions.
29 changes: 19 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ name: CI CD

on:
push:
branches: ['main']
pull_request:
branches: ['main']
branches: ['lightsail']

env:
LIGHTSAIL_SSH_KEY: ${{ secrets.LIGHTSAIL_SSH_KEY }}
Expand All @@ -17,20 +15,31 @@ jobs:
runs-on: ubuntu-latest

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

# AWS ์ธ์ฆ์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.
- name: compress
run: tar cvfz ./$GITHUB_SHA.tar.gz *
shell: bash

# AWS ์ธ์ฆ์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.
- name: AWS ์ธ์ฆํ•˜๊ธฐ
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: ${{ env.AWS_REGION }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

# AWS ์ธ์ฆ์ด ์™„๋ฃŒ๋˜์—ˆ๋Š”์ง€ ํ…Œ์ŠคํŠธํ•ฉ๋‹ˆ๋‹ค.
- name: AWS Lightsail ์—ฐ๊ฒฐ ํ™•์ธ
- name: AWS Lightsail์— ์—ฐ๊ฒฐ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ
run: aws configure list

# AWS ๋ชฉ๋ก์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.
- name: AWS ๋ชฉ๋ก ์ถœ๋ ฅ
run: ls

- name: upload to S3
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.tar.gz s3://lightsail-github-action-cicd

- name: deploy with AWS codeDeploy
run: aws deploy create-deployment
--application-name aloha-time
--deployment-config-name CodeDeployDefault.OneAtATime
--deployment-group-name AlohaTimeDeploymentGrouop
--s3-location bucket=lightsail-github-action-cicd,bundleType=tgz,key=$GITHUB_SHA.tar.gz

16 changes: 16 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 0.0
os: linux
files:
- source: /
destination: /home/ubuntu/aloha-spring-backend2/
file_exists_behavior: OVERWRITE
permissions:
- object: /
owner: ubuntu
group: ubuntu
mode: 755

hooks:
ApplicationStart:
- location: scripts/deploy.sh
runas: ubuntu
4 changes: 4 additions & 0 deletions deploy-before.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if [ -d /home/ubuntu/build ]; then
sudo rm -rf /home/ubuntu/build/
fi
sudo mkdir -vp /home/ubuntu/build/
44 changes: 44 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
PROJECT_NAME="aloha-spring-backend2"
JAR_PATH="/home/ubuntu/$PROJECT_NAME/build/libs/aloha-spring-backend-0.0.1-SNAPSHOT.jar"
DEPLOY_PATH=/home/ubuntu/$PROJECT_NAME/
DEPLOY_LOG_DIR_PATH="/home/ubuntu/$PROJECT_NAME/log"
DEPLOY_LOG_PATH="/home/ubuntu/$PROJECT_NAME/log/deploy.log"
DEPLOY_ERR_LOG_PATH="/home/ubuntu/$PROJECT_NAME/log/deploy_err.log"
APPLICATION_LOG_PATH="/home/ubuntu/$PROJECT_NAME/log/application.log"
BUILD_JAR=$(ls $JAR_PATH)
JAR_NAME=$(basename $BUILD_JAR)


echo "===== ๋ฐฐํฌ ์‹œ์ž‘ : $(date +%c) =====" >> $DEPLOY_LOG_PATH

echo "> build ํŒŒ์ผ๋ช…: $JAR_NAME" >> $DEPLOY_LOG_PATH
echo "> build ํŒŒ์ผ ๋ณต์‚ฌ" >> $DEPLOY_LOG_PATH
cp $BUILD_JAR $DEPLOY_PATH

echo "> ํ˜„์žฌ ๋™์ž‘์ค‘์ธ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ pid ์ฒดํฌ" >> $DEPLOY_LOG_PATH
CURRENT_PID=$(pgrep -f $JAR_NAME)

if [ -z $CURRENT_PID ]
then
echo "> ํ˜„์žฌ ๋™์ž‘์ค‘์ธ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์กด์žฌ X" >> $DEPLOY_LOG_PATH
else
echo "> ํ˜„์žฌ ๋™์ž‘์ค‘์ธ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์กด์žฌ O" >> $DEPLOY_LOG_PATH
echo "> ํ˜„์žฌ ๋™์ž‘์ค‘์ธ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐ•์ œ ์ข…๋ฃŒ ์ง„ํ–‰" >> $DEPLOY_LOG_PATH
echo "> kill -9 $CURRENT_PID" >> $DEPLOY_LOG_PATH
kill -9 $CURRENT_PID
fi

cd $DEPLOY_PATH

./gradlew build

DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME
# echo "> DEPLOY_JAR ๋ฐฐํฌ" >> $DEPLOY_JAR
mkdir $DEPLOY_LOG_DIR_PATH

nohup java -jar -Dspring.profiles.active=local $JAR_PATH --server.port=8080 >> $APPLICATION_LOG_PATH 2> $DEPLOY_ERR_LOG_PATH &

sleep 3

# echo "> ๋ฐฐํฌ ์ข…๋ฃŒ : $(date +%c)" >> $DEPLOY_LOG_PATH
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
public class MemberController {
private final MemberService memberService;

@GetMapping("/test")
public String test() {
return "ํ…Œ์ŠคํŠธ๋‹ค์ž„๋งˆ";
}

// ๋กœ๊ทธ์ธ์ด๋‚˜ ์ถœ์„์ •๋ณดAttendanceGetRequest
@PostMapping("/login")
public ApiResponse login(@RequestBody LoginRequest request) {
Expand All @@ -31,4 +36,4 @@ public ApiResponse getQuizzes(String token) {
return memberService.getQuizzes(token);
}

}
}

0 comments on commit cfcb2ea

Please sign in to comment.