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

infra: CD 파이프라인 추가 및 CI 수정 #56

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/prod-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Prod-CD

on:
push:
branches: [ "master" ]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
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: Code Deploy
run: |
aws deploy create-deployment \
--application-name gamsa-codedeploy \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--deployment-group-name gamsa-deploy-group \
--s3-location bucket=gamja-bongsa,bundleType=tgz,key=deploy.tar.gz
12 changes: 10 additions & 2 deletions .github/workflows/prod-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@ jobs:
- name: Build with Gradle Wrapper
run: ./gradlew build

- name: archive build directory
run: |
mkdir deploy
cp scripts/*.sh deploy
cp appspec.yml deploy
cp build/libs/*.jar deploy
tar cvfz deploy.tar.gz deploy

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
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: deploy jar
- name: upload to S3
run: |
aws s3 sync build s3://gamja-bongsa
aws s3 sync deploy.tar.gz s3://gamja-bongsa
18 changes: 18 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 0.0
os: linux
files:
- source: /
destination: /home/ubuntu/deploy
overwrite: yes

permissions:
- object: /
pattern: "**"
owner: ubuntu
group: ubuntu

hooks:
ApplicationStart:
- location: deploy.sh
timeout: 60
runas: ubuntu
29 changes: 29 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

REPOSITORY=/home/ubuntu/deploy
APP_NAME=gamsa

cd $REPOSITORY

echo "> 현재 구동 중인 애플리케이션 pid 확인"
CURRENT_PID=$(pgrep -f ${APP_NAME}-*.jar)

echo "> 현재 구동 중인 애플리케이션 pid: $CURRENT_PID"
if [ -z "$CURRENT_PID" ]; then
echo "> 구동 중인 애플리케이션이 없습니다."
else
echo "> kill -15 $CURRENT_PID"
kill -15 $CURRENT_PID
sleep 5
fi

echo "> 새 애플리케이션 배포"
JAR_NAME=$(ls -tr $REPOSITORY/ | grep jar | tail -n 1)

echo "> JAR Name: $JAR_NAME"

echo "> $JAR_NAME에 실행권한 추가"
chmod +x $JAR_NAME

echo "> $JAR_NAME 실행"
nohup java -jar $REPOSITORY/$JAR_NAME --spring.profiles.active=prod 2>&1 &