Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: temp build
Browse files Browse the repository at this point in the history
dragontaek-lee committed Jun 1, 2024
1 parent 1182813 commit fb8a652
Showing 4 changed files with 85 additions and 139 deletions.
152 changes: 76 additions & 76 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ name: Gam-dev-server CD
# 해당 workflow가 언제 실행될 것인지에 대한 트리거를 지정
on:
push:
branches: [ develop ]
branches: [ develop ]

env:
S3_BUCKET_NAME: gam-dev-deploy
@@ -17,80 +17,80 @@ jobs:
runs-on: ubuntu-latest

steps:

# 1) 워크플로우 실행 전 기본적으로 체크아웃 필요
- name: checkout
uses: actions/checkout@v3

# 2) JDK 11버전 설치, 다른 JDK 버전을 사용하다면 수정
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

# 3) 환경변수 파일 생성
- name: make application.properties 파일 생성
run: |
## create application.yml
cd ./src/main/resources
# application.yml 파일 생성
touch ./application-dev.yml
# GitHub-Actions 에서 설정한 값을 application.yml 파일에 쓰기
echo "${{ secrets.GAM_DEV_APPLICATION }}" >> ./application-dev.yml
# application.yml 파일 확인
cat ./application-dev.yml
shell: bash

# 이 워크플로우는 gradle build
- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle # 실제 application build(-x 옵션을 통해 test는 제외)
run: ./gradlew build -x test

# 디렉토리 생성
- name: Make Directory
run: mkdir -p deploy

# Jar 파일 복사
- name: Copy Jar
run: cp ./build/libs/*.jar ./deploy

# appspec.yml 파일 복사
- name: Copy appspec.yml
run: cp appspec.yml ./deploy

# script files 복사
- name: Copy script
run: cp ./scripts/*.sh ./deploy

- name: Make zip file
run: zip -r ./gam-dev-server.zip ./deploy
shell: bash

# 1) 워크플로우 실행 전 기본적으로 체크아웃 필요
- name: checkout
uses: actions/checkout@v3

# 2) JDK 11버전 설치, 다른 JDK 버전을 사용하다면 수정
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

# 3) 환경변수 파일 생성
- name: make application.properties 파일 생성
run: |
## create application.yml
cd ./src/main/resources
# application.yml 파일 생성
touch ./application-dev.yml
# GitHub-Actions 에서 설정한 값을 application.yml 파일에 쓰기
echo "${{ secrets.GAM_DEV_APPLICATION }}" >> ./application-dev.yml
# application.yml 파일 확인
cat ./application-dev.yml
shell: bash

# 이 워크플로우는 gradle build
- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle # 실제 application build(-x 옵션을 통해 test는 제외)
run: ./gradlew build -x test

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

- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./gam-dev-server.zip s3://$S3_BUCKET_NAME/
# 디렉토리 생성
- name: Make Directory
run: mkdir -p deploy

# Deploy
- name: Deploy
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }}
run:
aws deploy create-deployment
--application-name gam-dev-codedeploy
--deployment-group-name gam-dev-server-codedeploy-group
--file-exists-behavior OVERWRITE
--s3-location bucket=gam-dev-deploy,bundleType=zip,key=gam-dev-server.zip
--region ap-northeast-2
# Jar 파일 복사
- name: Copy Jar
run: cp ./build/libs/*.jar ./deploy

# appspec.yml 파일 복사
- name: Copy appspec.yml
run: cp appspec.yml ./deploy

# script files 복사
- name: Copy script
run: cp ./scripts/*.sh ./deploy

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

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

- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://${{ secrets.AWS_S3_BUCKET_NAME }}/dev/$GITHUB_SHA.zip

# Deploy
- name: Deploy
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_CONFIG_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_CONFIG_SECRET_KEY }}
run:
aws deploy create-deployment
--application-name gam-codeDeploy
--deployment-group-name dev
--file-exists-behavior OVERWRITE
--s3-location bucket=${{ secrets.AWS_S3_BUCKET_NAME }},bundleType=zip,key=dev/$GITHUB_SHA.zip
--region ap-northeast-2
3 changes: 0 additions & 3 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -17,6 +17,3 @@ hooks:
- location: deploy.sh
timeout: 60
runas: ubuntu
- location: switch.sh
timeout: 180
runas: ubuntu
35 changes: 9 additions & 26 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -2,35 +2,18 @@
REPOSITORY=/home/ubuntu/app
BUILD_PATH=$(ls /home/ubuntu/app/*SNAPSHOT.jar)
JAR_NAME=$(basename $BUILD_PATH)
echo "> build 파일명: $JAR_NAME"
IDLE_APPLICATION_PATH=/home/ubuntu/app/${JAR_NAME}
CURRENT_PORT=$(cat /etc/nginx/conf.d/service-url.inc | grep -Po '[0-9]+' | tail -1)
TARGET_PORT=0
TARGET_PORT=8080

echo "> Current port of running WAS is ${CURRENT_PORT}."
CURRENT_PID=$(lsof -Fp -i TCP:${CURRENT_PORT} | grep -Po 'p[0-9]+' | grep -Po '[0-9]+')
sudo kill ${CURRENT_PID}

if [ ${CURRENT_PORT} -eq 8081 ]; then
TARGET_PORT=8082
elif [ ${CURRENT_PORT} -eq 8082 ]; then
TARGET_PORT=8081
else
echo "> No WAS is connected to nginx"
if [ "$DEPLOYMENT_GROUP_NAME" == "prod" ]
then
nohup java -jar -Duser.timezone=Asia/Seoul -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=prod $IDLE_APPLICATION_PATH >> /home/ubuntu/app/nohup.out 2>&1 &
fi
echo "> Target port is ${TARGET_PORT}."

TARGET_PID=$(lsof -Fp -i TCP:${TARGET_PORT} | grep -Po 'p[0-9]+' | grep -Po '[0-9]+')
echo "> Target PID is ${TARGET_PID}."

if [ ! -z ${TARGET_PID} ]; then
echo "> Kill WAS running at ${TARGET_PORT}."
sudo kill ${TARGET_PID}
if [ "$DEPLOYMENT_GROUP_NAME" == "dev" ]
then
nohup java -jar -Duser.timezone=Asia/Seoul -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=dev $IDLE_APPLICATION_PATH >> /home/ubuntu/app/nohup.out 2>&1 &
fi

nohup java -jar -Duser.timezone=Asia/Seoul -Dserver.port=${TARGET_PORT} -Dspring.profiles.active=dev $IDLE_APPLICATION_PATH >> /home/ubuntu/app/nohup.out 2>&1 &
echo "> Running port is ${TARGET_PORT}."

echo "> Running PID is"
lsof -i TCP:${TARGET_PORT}


echo "> Now new WAS runs at ${TARGET_PORT}."
34 changes: 0 additions & 34 deletions scripts/switch.sh

This file was deleted.

0 comments on commit fb8a652

Please sign in to comment.