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

chore: cd 작업 설정 #56

Closed
wants to merge 4 commits into from
Closed
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
27 changes: 27 additions & 0 deletions .github/workflows/ci-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ on:
branches:
- main

env:
PROJECT_NAME: feed-project
BUCKET_NAME: feed-cd-bucket
CODE_DEPLOY_APP_NAME: feed_cd
DEPLOYMENT_GROUP_NAME: feed_instance

permissions:
contents: read
checks: write
Expand Down Expand Up @@ -49,3 +55,24 @@ jobs:
with:
webhook-url: ${{ secrets.WEBHOOK_URL }}
content: ":love_letter: 새로운 PR이 날아왔습니다 ~ :love_letter:\n:link: 리뷰하러 가기: ${{ github.event.pull_request.html_url }}"

- name: ZIP 파일 생성
run: zip -qq -r ./$GITHUB_SHA.zip .
shell: bash

- 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_PRIVATE_ACCESS_KEY }}
aws-region: ap-northeast-2

- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip

- name: Code Deploy To EC2 instance
run: aws deploy create-deployment
--application-name $CODE_DEPLOY_APP_NAME
--deployment-config-name CodeDeployDefault.AllAtOnce
--deployment-group-name $DEPLOYMENT_GROUP_NAME
--s3-location bucket=$BUCKET_NAME,bundleType=zip,key=$PROJECT_NAME/$GITHUB_SHA.zip
20 changes: 20 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 0.0
os: linux

# 배포할 파일 및 디렉토리를 정의합니다.
files:
- source: /
destination: /home/ubuntu/feed

# 권한을 정의합니다.
permissions:
- object: /home/ubuntu/feed/
owner: ubuntu
group: ubuntu

# 배포단계에서 진행하는 훅 스크립트를 정의합니다.
hooks:
AfterInstall:
- location: scripts/deploy.sh
timeout: 60
runas: ubuntu
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {

group = 'team05'
version = '0.0.1-SNAPSHOT'
jar.enabled = false

java {
toolchain {
Expand Down
21 changes: 21 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

REPOSITORY=/home/ubuntu/plug
cd $REPOSITORY

APP_NAME=plug
JAR_NAME=$(ls $REPOSITORY/build/libs/ | grep 'SNAPSHOT.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 -9 $CURRENT_PID"
kill -15 $CURRENT_PID
sleep 5
fi

echo "> Deploy - $JAR_PATH "
nohup java -jar $JAR_PATH > /dev/null 2> /dev/null < /dev/null &
Loading