diff --git a/.github/workflows/api-CD-dev.yml b/.github/workflows/api-CD-dev.yml new file mode 100644 index 00000000..1d6c9183 --- /dev/null +++ b/.github/workflows/api-CD-dev.yml @@ -0,0 +1,105 @@ +# 워크플로우의 이름 지정 +name: Umbba API Server CD (Develop) + +# 해당 workflow가 언제 실행될 것인지에 대한 트리거를 지정 +on: + push: + branches: [ "develop" ] + paths: + - umbba-api/** + - umbba-domain/** + - umbba-common/** + - umbba-external/** + - .github/workflows/** + +env: + S3_BUCKET_NAME: umbba-develop-storage + +jobs: + build: + name: Code deployment + + # 실행 환경 + runs-on: ubuntu-latest + + steps: + + # 1) 워크플로우 실행 전 기본적으로 체크아웃 필요 + - name: checkout + uses: actions/checkout@v3 + + # 2) JDK 11버전 설치, 다른 JDK 버전을 사용하다면 수정 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.AWS_DEVELOP_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.AWS_DEVELOP_SECRET_KEY }} + aws-region: ap-northeast-2 + + # 3) AWS Secrets Manger 환경변수 사용 + - name: Read secrets from AWS Secrets Manager into environment variables + uses: abhilash1in/aws-secrets-manager-action@v1.1.0 + with: + aws-access-key-id: ${{ secrets.AWS_DEVELOP_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.AWS_DEVELOP_SECRET_KEY }} + aws-region: ap-northeast-2 + secrets: /secret/umbba-secret + parse-json: false + + # 4) FCM secret key 파일 생성 + - name: FCM secret key 파일 생성 + run: | + cd ./umbba-api/src/main/resources + + mkdir ./firebase + cd ./firebase + + aws s3 cp --region ap-northeast-2 s3://${{ secrets.S3_DEVELOP_BUCKET_NAME }}/json/umbba-fcm-firebase-adminsdk.json . + + shell: bash + + # 이 워크플로우는 gradle build + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle # 실제 application build(-x 옵션을 통해 test는 제외) + run: ./gradlew umbba-api:bootJar -x test + + # 디렉토리 생성 + - name: Make Directory + run: mkdir -p deploy + + # Jar 파일 복사 + - name: Copy Jar + run: cp ./umbba-api/build/libs/*.jar ./deploy + # run: cp -r ./umbba-api/src/main/* ./deploy + + # appspec.yml, script files 파일 복사 + - name: Copy files + run: cp ./scripts/umbba-api-dev/* ./deploy + + - name: Make zip file + run: zip -r ./umbba-api.zip ./deploy + shell: bash + + - name: Upload to S3 + run: aws s3 cp --region ap-northeast-2 ./umbba-api.zip s3://$S3_BUCKET_NAME/ + + # Deploy + - name: Deploy + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_DEVELOP_ACCESS_KEY }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_DEVELOP_SECRET_KEY }} + run: + aws deploy create-deployment + --application-name umbba-develop-server-codedeploy + --deployment-group-name umbba-api-server-codedeploy-group + --file-exists-behavior OVERWRITE + --s3-location bucket=umbba-develop-storage,bundleType=zip,key=umbba-api.zip + --region ap-northeast-2 \ No newline at end of file diff --git a/.github/workflows/api-CD.yml b/.github/workflows/api-CD-prod.yml similarity index 95% rename from .github/workflows/api-CD.yml rename to .github/workflows/api-CD-prod.yml index 358142ad..abc3ea10 100644 --- a/.github/workflows/api-CD.yml +++ b/.github/workflows/api-CD-prod.yml @@ -1,10 +1,10 @@ # 워크플로우의 이름 지정 -name: Umbba API Server CD +name: Umbba API Server CD (Production) # 해당 workflow가 언제 실행될 것인지에 대한 트리거를 지정 on: push: - branches: [ "develop" ] + branches: [ "main" ] paths: - umbba-api/** - umbba-domain/** @@ -82,7 +82,7 @@ jobs: # appspec.yml, script files 파일 복사 - name: Copy files - run: cp ./scripts/umbba-api/* ./deploy + run: cp ./scripts/umbba-api-prod/* ./deploy - name: Make zip file run: zip -r ./umbba-api.zip ./deploy @@ -102,4 +102,4 @@ jobs: --deployment-group-name umbba-api-server-codedeploy-group --file-exists-behavior OVERWRITE --s3-location bucket=umbba-storage,bundleType=zip,key=umbba-api.zip - --region ap-northeast-2 + --region ap-northeast-2 \ No newline at end of file diff --git a/.github/workflows/api-CI-dev.yml b/.github/workflows/api-CI-dev.yml new file mode 100644 index 00000000..e5636bff --- /dev/null +++ b/.github/workflows/api-CI-dev.yml @@ -0,0 +1,55 @@ +name: Umbba API Server CI (Develop) + +on: + push: + branches: [ "develop" ] + paths: + - umbba-api/** + - umbba-domain/** + - umbba-common/** + - umbba-external/** + pull_request: + branches: [ "develop" ] + paths: + - umbba-api/** + - umbba-domain/** + - umbba-common/** + - umbba-external/** + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + + # 1) 워크플로우 실행 전 기본적으로 체크아웃 필요 + - name: checkout + uses: actions/checkout@v3 + + # 2) JDK 11버전 설치, 다른 JDK 버전을 사용하다면 수정 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + + # 3) AWS Secrets Manger 환경변수 사용 + - name: Read secrets from AWS Secrets Manager into environment variables + uses: abhilash1in/aws-secrets-manager-action@v1.1.0 + with: + aws-access-key-id: ${{ secrets.AWS_DEVELOP_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.AWS_DEVELOP_SECRET_KEY }} + aws-region: ap-northeast-2 + secrets: /secret/umbba-secret + parse-json: false + + # 이 워크플로우는 gradle build + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle # 실제 application build(-x 옵션을 통해 test는 제외) + run: ./gradlew umbba-api:bootJar -x test diff --git a/.github/workflows/api-CI.yml b/.github/workflows/api-CI-prod.yml similarity index 55% rename from .github/workflows/api-CI.yml rename to .github/workflows/api-CI-prod.yml index 32a1a18e..b4d51d32 100644 --- a/.github/workflows/api-CI.yml +++ b/.github/workflows/api-CI-prod.yml @@ -1,28 +1,15 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle - -name: Umbba API Server CI +name: Umbba API Server CI (Production) on: push: - branches: [ "develop" ] + branches: [ "main" ] paths: - umbba-api/** - umbba-domain/** - umbba-common/** - umbba-external/** pull_request: - branches: [ "develop" ] + branches: [ "main" ] paths: - umbba-api/** - umbba-domain/** @@ -65,4 +52,4 @@ jobs: run: chmod +x gradlew - name: Build with Gradle # 실제 application build(-x 옵션을 통해 test는 제외) - run: ./gradlew umbba-api:bootJar -x test + run: ./gradlew umbba-api:bootJar -x test \ No newline at end of file diff --git a/.github/workflows/notification-CD-dev.yml b/.github/workflows/notification-CD-dev.yml new file mode 100644 index 00000000..6fe22226 --- /dev/null +++ b/.github/workflows/notification-CD-dev.yml @@ -0,0 +1,105 @@ +# 워크플로우의 이름 지정 +name: Umbba Notification Server CD (Develop) + +# 해당 workflow가 언제 실행될 것인지에 대한 트리거를 지정 +on: + push: + branches: [ "develop" ] + paths: + - umbba-notification/** + - umbba-domain/** + - umbba-common/** + - umbba-external/** + - .github/workflows/** + +env: + S3_BUCKET_NAME: umbba-develop-storage + +jobs: + build: + name: Code deployment + + # 실행 환경 + runs-on: ubuntu-latest + + steps: + + # 1) 워크플로우 실행 전 기본적으로 체크아웃 필요 + - name: checkout + uses: actions/checkout@v3 + + # 2) JDK 11버전 설치, 다른 JDK 버전을 사용하다면 수정 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.AWS_DEVELOP_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.AWS_DEVELOP_SECRET_KEY }} + aws-region: ap-northeast-2 + + # 3) AWS Secrets Manger 환경변수 사용 + - name: Read secrets from AWS Secrets Manager into environment variables + uses: abhilash1in/aws-secrets-manager-action@v1.1.0 + with: + aws-access-key-id: ${{ secrets.AWS_DEVELOP_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.AWS_DEVELOP_SECRET_KEY }} + aws-region: ap-northeast-2 + secrets: /secret/umbba-secret + parse-json: false + + # 4) FCM secret key 파일 생성 + - name: FCM secret key 파일 생성 + run: | + cd ./umbba-notification/src/main/resources + + mkdir ./firebase + cd ./firebase + + aws s3 cp --region ap-northeast-2 s3://${{ secrets.S3_DEVELOP_BUCKET_NAME }}/json/umbba-fcm-firebase-adminsdk.json . + + shell: bash + + # 이 워크플로우는 gradle build + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle # 실제 application build(-x 옵션을 통해 test는 제외) + run: ./gradlew umbba-notification:bootJar -x test + + # 디렉토리 생성 + - name: Make Directory + run: mkdir -p deploy + + # Jar 파일 복사 + - name: Copy Jar + run: cp ./umbba-notification/build/libs/*.jar ./deploy + # run: cp -r src/main/* ./deploy + + # appspec.yml, script files 파일 복사 + - name: Copy files + run: cp ./scripts/umbba-notification-dev/* ./deploy + + - name: Make zip file + run: zip -r ./umbba-notification.zip ./deploy + shell: bash + + - name: Upload to S3 + run: aws s3 cp --region ap-northeast-2 ./umbba-notification.zip s3://$S3_BUCKET_NAME/ + + # Deploy + - name: Deploy + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_DEVELOP_ACCESS_KEY }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_DEVELOP_SECRET_KEY }} + run: + aws deploy create-deployment + --application-name umbba-develop-server-codedeploy + --deployment-group-name umbba-notification-server-codedeploy-group + --file-exists-behavior OVERWRITE + --s3-location bucket=umbba-develop-storage,bundleType=zip,key=umbba-notification.zip + --region ap-northeast-2 diff --git a/.github/workflows/notification-CD.yml b/.github/workflows/notification-CD-prod.yml similarity index 95% rename from .github/workflows/notification-CD.yml rename to .github/workflows/notification-CD-prod.yml index ea8b69c0..cd9fb8c7 100644 --- a/.github/workflows/notification-CD.yml +++ b/.github/workflows/notification-CD-prod.yml @@ -1,10 +1,10 @@ # 워크플로우의 이름 지정 -name: Umbba Notification Server CD +name: Umbba Notification Server CD (Production) # 해당 workflow가 언제 실행될 것인지에 대한 트리거를 지정 on: push: - branches: [ "develop" ] + branches: [ "main" ] paths: - umbba-notification/** - umbba-domain/** @@ -82,7 +82,7 @@ jobs: # appspec.yml, script files 파일 복사 - name: Copy files - run: cp ./scripts/umbba-notification/* ./deploy + run: cp ./scripts/umbba-notification-prod/* ./deploy - name: Make zip file run: zip -r ./umbba-notification.zip ./deploy diff --git a/.github/workflows/notification-CI-dev.yml b/.github/workflows/notification-CI-dev.yml new file mode 100644 index 00000000..cb09fdcd --- /dev/null +++ b/.github/workflows/notification-CI-dev.yml @@ -0,0 +1,55 @@ +name: Umbba Notification Server CI (Develop) + +on: + push: + branches: [ "develop" ] + paths: + - umbba-notification/** + - umbba-domain/** + - umbba-common/** + - umbba-external/** + pull_request: + branches: [ "develop" ] + paths: + - umbba-notification/** + - umbba-domain/** + - umbba-common/** + - umbba-external/** + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + + # 1) 워크플로우 실행 전 기본적으로 체크아웃 필요 + - name: checkout + uses: actions/checkout@v3 + + # 2) JDK 11버전 설치, 다른 JDK 버전을 사용하다면 수정 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + + # 3) AWS Secrets Manger 환경변수 사용 + - name: Read secrets from AWS Secrets Manager into environment variables + uses: abhilash1in/aws-secrets-manager-action@v1.1.0 + with: + aws-access-key-id: ${{ secrets.AWS_DEVELOP_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.AWS_DEVELOP_SECRET_KEY }} + aws-region: ap-northeast-2 + secrets: /secret/umbba-secret + parse-json: false + + # 이 워크플로우는 gradle build + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle # 실제 application build(-x 옵션을 통해 test는 제외) + run: ./gradlew umbba-notification:bootJar -x test diff --git a/.github/workflows/notification-CI.yml b/.github/workflows/notification-CI-prod.yml similarity index 58% rename from .github/workflows/notification-CI.yml rename to .github/workflows/notification-CI-prod.yml index 7e2cf6fd..1b01c8c7 100644 --- a/.github/workflows/notification-CI.yml +++ b/.github/workflows/notification-CI-prod.yml @@ -1,28 +1,15 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle - -name: Umbba Notification Server CI +name: Umbba Notification Server CI (Production) on: push: - branches: [ "develop" ] + branches: [ "main" ] paths: - umbba-notification/** - umbba-domain/** - umbba-common/** - umbba-external/** pull_request: - branches: [ "develop" ] + branches: [ "main" ] paths: - umbba-notification/** - umbba-domain/** diff --git a/scripts/umbba-api/appspec.yml b/scripts/umbba-api-dev/appspec.yml similarity index 100% rename from scripts/umbba-api/appspec.yml rename to scripts/umbba-api-dev/appspec.yml diff --git a/scripts/umbba-api/deploy.sh b/scripts/umbba-api-dev/deploy.sh similarity index 87% rename from scripts/umbba-api/deploy.sh rename to scripts/umbba-api-dev/deploy.sh index 70564ac0..6905ed35 100644 --- a/scripts/umbba-api/deploy.sh +++ b/scripts/umbba-api-dev/deploy.sh @@ -9,23 +9,23 @@ echo "[$NOW_TIME] build 파일 복사" DEPLOY_PATH=/home/ubuntu/api-server/nonstop/jar/ cp $BUILD_PATH $DEPLOY_PATH -echo "[$NOW_TIME] 현재 구동중인 Set 확인" +echo "[$NOW_TIME] 현재 구동중인 Prod 확인" CURRENT_PROFILE=$(curl -s http://localhost/profile) echo "[$NOW_TIME] $CURRENT_PROFILE" -# 쉬고 있는 set 찾기: set1이 사용중이면 set2가 쉬고 있고, 반대면 set1이 쉬고 있음 -if [ $CURRENT_PROFILE == set1 ] +# 쉬고 있는 prod 찾기: dev1이 사용중이면 dev2가 쉬고 있고, 반대면 dev1이 쉬고 있음 +if [ $CURRENT_PROFILE == dev1 ] then - IDLE_PROFILE=set2 + IDLE_PROFILE=dev2 IDLE_PORT=8082 -elif [ $CURRENT_PROFILE == set2 ] +elif [ $CURRENT_PROFILE == dev2 ] then - IDLE_PROFILE=set1 + IDLE_PROFILE=dev1 IDLE_PORT=8081 else echo "[$NOW_TIME] 일치하는 Profile이 없습니다. Profile: $CURRENT_PROFILE" - echo "[$NOW_TIME] set1을 할당합니다. IDLE_PROFILE: set1" - IDLE_PROFILE=set1 + echo "[$NOW_TIME] dev1을 할당합니다. IDLE_PROFILE: dev1" + IDLE_PROFILE=dev1 IDLE_PORT=8081 fi diff --git a/scripts/umbba-api/switch.sh b/scripts/umbba-api-dev/switch.sh similarity index 81% rename from scripts/umbba-api/switch.sh rename to scripts/umbba-api-dev/switch.sh index d2715800..06387f45 100644 --- a/scripts/umbba-api/switch.sh +++ b/scripts/umbba-api-dev/switch.sh @@ -6,11 +6,11 @@ sleep 10 echo "[$NOW_TIME] 현재 구동중인 Port 확인" CURRENT_PROFILE=$(curl -s http://localhost/profile) -# 쉬고 있는 set 찾기: set1이 사용중이면 set2가 쉬고 있고, 반대면 set1이 쉬고 있음 -if [ $CURRENT_PROFILE == set1 ] +# 쉬고 있는 prod 찾기: dev1이 사용중이면 dev2가 쉬고 있고, 반대면 dev1이 쉬고 있음 +if [ $CURRENT_PROFILE == dev1 ] then IDLE_PORT=8082 -elif [ $CURRENT_PROFILE == set2 ] +elif [ $CURRENT_PROFILE == dev2 ] then IDLE_PORT=8081 else diff --git a/scripts/umbba-api-prod/appspec.yml b/scripts/umbba-api-prod/appspec.yml new file mode 100644 index 00000000..0386a216 --- /dev/null +++ b/scripts/umbba-api-prod/appspec.yml @@ -0,0 +1,22 @@ +version: 0.0 +os: linux + +files: + - source: / + destination: /home/ubuntu/api-server + overwrite: yes + +permissions: + - object: / + pattern: "**" + owner: ubuntu + group: ubuntu + +hooks: + AfterInstall: + - location: deploy.sh + timeout: 180 + runas: ubuntu + - location: switch.sh + timeout: 180 + runas: ubuntu \ No newline at end of file diff --git a/scripts/umbba-api-prod/deploy.sh b/scripts/umbba-api-prod/deploy.sh new file mode 100644 index 00000000..d8680401 --- /dev/null +++ b/scripts/umbba-api-prod/deploy.sh @@ -0,0 +1,86 @@ +#!/bin/bash +NOW_TIME="$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)" + +BUILD_PATH=$(ls /home/ubuntu/api-server/umbba-api-0.0.1-SNAPSHOT.jar) +JAR_NAME=$(basename $BUILD_PATH) +echo "[$NOW_TIME] build 파일명: $JAR_NAME" + +echo "[$NOW_TIME] build 파일 복사" +DEPLOY_PATH=/home/ubuntu/api-server/nonstop/jar/ +cp $BUILD_PATH $DEPLOY_PATH + +echo "[$NOW_TIME] 현재 구동중인 Prod 확인" +CURRENT_PROFILE=$(curl -s http://localhost/profile) +echo "[$NOW_TIME] $CURRENT_PROFILE" + +# 쉬고 있는 prod 찾기: prod1이 사용중이면 prod2가 쉬고 있고, 반대면 prod1이 쉬고 있음 +if [ $CURRENT_PROFILE == prod1 ] +then + IDLE_PROFILE=prod2 + IDLE_PORT=8082 +elif [ $CURRENT_PROFILE == prod2 ] +then + IDLE_PROFILE=prod1 + IDLE_PORT=8081 +else + echo "[$NOW_TIME] 일치하는 Profile이 없습니다. Profile: $CURRENT_PROFILE" + echo "[$NOW_TIME] prod1을 할당합니다. IDLE_PROFILE: prod1" + IDLE_PROFILE=prod1 + IDLE_PORT=8081 +fi + +echo "[$NOW_TIME] application.jar 교체" +IDLE_APPLICATION=$IDLE_PROFILE-Umbba-API.jar +IDLE_APPLICATION_PATH=$DEPLOY_PATH$IDLE_APPLICATION + +ln -Tfs $DEPLOY_PATH$JAR_NAME $IDLE_APPLICATION_PATH + +echo "[$NOW_TIME] $IDLE_PROFILE 에서 구동중인 애플리케이션 pid 확인" +IDLE_PID=$(pgrep -f $IDLE_APPLICATION) + +if [ -z $IDLE_PID ] +then + echo "[$NOW_TIME] 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." +else + echo "[$NOW_TIME] kill -15 $IDLE_PID" + kill -15 $IDLE_PID + + while ps -p $IDLE_PID > /dev/null; do + sleep 1 + done + echo "[$NOW_TIME] 애플리케이션이 정상 종료되었습니다." +fi + +echo "[$NOW_TIME] $IDLE_PROFILE 배포" +nohup java -jar -Duser.timezone=Asia/Seoul -Dspring.profiles.active=$IDLE_PROFILE $IDLE_APPLICATION_PATH >> /home/ubuntu/api-server/deploy.log 2>/home/ubuntu/api-server/deploy_err.log & + +################################################################## + +echo "[$NOW_TIME] $IDLE_PROFILE 10초 후 Health check 시작" +echo "[$NOW_TIME] curl -s http://localhost:$IDLE_PORT/health " +sleep 10 + +for retry_count in {1..10} +do + response=$(curl -s http://localhost:$IDLE_PORT/actuator/health) + up_count=$(echo $response | grep 'UP' | wc -l) + + if [ $up_count -ge 1 ] + then # $up_count >= 1 ("UP" 문자열이 있는지 검증) + echo "[$NOW_TIME] Health check 성공" + break + else + echo "[$NOW_TIME] Health check의 응답을 알 수 없거나 혹은 status가 UP이 아닙니다." + echo "[$NOW_TIME] Health check: ${response}" + fi + + if [ $retry_count -eq 10 ] + then + echo "[$NOW_TIME] Health check 실패. " + echo "[$NOW_TIME] Nginx에 연결하지 않고 배포를 종료합니다." + exit 1 + fi + + echo "[$NOW_TIME] Health check 연결 실패. 재시도..." + sleep 10 +done \ No newline at end of file diff --git a/scripts/umbba-api-prod/switch.sh b/scripts/umbba-api-prod/switch.sh new file mode 100644 index 00000000..4efce738 --- /dev/null +++ b/scripts/umbba-api-prod/switch.sh @@ -0,0 +1,30 @@ +#!/bin/bash +NOW_TIME="$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)" + +echo "[$NOW_TIME] 스위칭" +sleep 10 +echo "[$NOW_TIME] 현재 구동중인 Port 확인" +CURRENT_PROFILE=$(curl -s http://localhost/profile) + +# 쉬고 있는 prod 찾기: prod1이 사용중이면 prod2가 쉬고 있고, 반대면 prod1이 쉬고 있음 +if [ $CURRENT_PROFILE == prod1 ] +then + IDLE_PORT=8082 +elif [ $CURRENT_PROFILE == prod2 ] +then + IDLE_PORT=8081 +else + echo "[$NOW_TIME] 일치하는 Profile이 없습니다. Profile: $CURRENT_PROFILE" + echo "[$NOW_TIME] 8081을 할당합니다." + IDLE_PORT=8081 +fi + +echo "[$NOW_TIME] 전환할 Port: $IDLE_PORT" +echo "[$NOW_TIME] Port 전환" +echo "set \$service_url http://127.0.0.1:${IDLE_PORT};" | sudo tee /etc/nginx/conf.d/service-url.inc + +PROXY_PORT=$(curl -s http://localhost/profile) +echo "[$NOW_TIME] Nginx Current Proxy Port: $PROXY_PORT" + +echo "[$NOW_TIME] Nginx Reload" +sudo service nginx reload \ No newline at end of file diff --git a/scripts/umbba-notification/appspec.yml b/scripts/umbba-notification-dev/appspec.yml similarity index 100% rename from scripts/umbba-notification/appspec.yml rename to scripts/umbba-notification-dev/appspec.yml diff --git a/scripts/umbba-notification/deploy.sh b/scripts/umbba-notification-dev/deploy.sh similarity index 100% rename from scripts/umbba-notification/deploy.sh rename to scripts/umbba-notification-dev/deploy.sh diff --git a/scripts/umbba-notification-prod/appspec.yml b/scripts/umbba-notification-prod/appspec.yml new file mode 100644 index 00000000..4a0bf554 --- /dev/null +++ b/scripts/umbba-notification-prod/appspec.yml @@ -0,0 +1,19 @@ +version: 0.0 +os: linux + +files: + - source: / + destination: /home/ubuntu/notification-server + overwrite: yes + +permissions: + - object: / + pattern: "**" + owner: ubuntu + group: ubuntu + +hooks: + AfterInstall: + - location: deploy.sh + timeout: 180 + runas: ubuntu \ No newline at end of file diff --git a/scripts/umbba-notification-prod/deploy.sh b/scripts/umbba-notification-prod/deploy.sh new file mode 100644 index 00000000..1d95de1b --- /dev/null +++ b/scripts/umbba-notification-prod/deploy.sh @@ -0,0 +1,19 @@ +#!/bin/bash +NOW_TIME="$(date +%Y)-$(date +%m)-$(date +%d) $(date +%H):$(date +%M):$(date +%S)" + +BUILD_PATH=/home/ubuntu/notification-server/umbba-notification-0.0.1-SNAPSHOT.jar +TARGET_PORT=8083 +TARGET_PID=$(lsof -Fp -i TCP:${TARGET_PORT} | grep -Po 'p[0-9]+' | grep -Po '[0-9]+') + +if [ ! -z ${TARGET_PID} ]; then + echo "[$NOW_TIME] Kill WAS running at ${TARGET_PORT}." >> /home/ubuntu/notification-server/deploy.log + sudo kill -15 ${TARGET_PID} + while ps -p $TARGET_PID > /dev/null; do + sleep 1 + done + echo "[$NOW_TIME] 애플리케이션이 정상 종료되었습니다." +fi + +nohup java -jar -Duser.timezone=Asia/Seoul -Dspring.profiles.active=prod $BUILD_PATH >> /home/ubuntu/notification-server/deploy.log 2>/home/ubuntu/notification-server/deploy_err.log & +echo "[$NOW_TIME] Now new WAS runs at ${TARGET_PORT}." >> /home/ubuntu/notification-server/deploy.log +exit 0 \ No newline at end of file diff --git a/umbba-api/src/main/resources/application-set1.yml b/umbba-api/src/main/resources/application-dev1.yml similarity index 98% rename from umbba-api/src/main/resources/application-set1.yml rename to umbba-api/src/main/resources/application-dev1.yml index a924c93f..1627e262 100644 --- a/umbba-api/src/main/resources/application-set1.yml +++ b/umbba-api/src/main/resources/application-dev1.yml @@ -1,7 +1,7 @@ spring: config: activate: - on-profile: set1 + on-profile: dev1 datasource: driver-class-name: com.mysql.cj.jdbc.Driver diff --git a/umbba-api/src/main/resources/application-set2.yml b/umbba-api/src/main/resources/application-dev2.yml similarity index 98% rename from umbba-api/src/main/resources/application-set2.yml rename to umbba-api/src/main/resources/application-dev2.yml index 1d537832..e5b79300 100644 --- a/umbba-api/src/main/resources/application-set2.yml +++ b/umbba-api/src/main/resources/application-dev2.yml @@ -1,7 +1,7 @@ spring: config: activate: - on-profile: set2 + on-profile: dev2 datasource: driver-class-name: com.mysql.cj.jdbc.Driver diff --git a/umbba-api/src/main/resources/application-prod1.yml b/umbba-api/src/main/resources/application-prod1.yml new file mode 100644 index 00000000..38b2c3d7 --- /dev/null +++ b/umbba-api/src/main/resources/application-prod1.yml @@ -0,0 +1,54 @@ +spring: + config: + activate: + on-profile: prod1 + + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: ${DB_URL_PROD} + username: ${DB_USER_PROD} + password: ${DB_PWD_PROD} + hikari: + pool-name: Hikari 커넥션 풀 # Pool + connection-timeout: 30000 # 30초(default: 30초) + maximum-pool-size: 10 # default: 10개 + max-lifetime: 600000 # 10분(default: 30분) + leak-detection-threshold: 3500 # default: 0(이용X) + + jpa: + show-sql: false + hibernate: + ddl-auto: update + ejb: + naming_strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy + properties: + hibernate: + format_sql: true + +cloud: + aws: + credentials: + accessKey: ${CLOUD_ACCESS_PROD} + secretKey: ${CLOUD_SECRET_PROD} + region: + static: ${CLOUD_REGION_PROD} + s3: + bucket: ${BUCKET_NAME_PROD} + stack: + auto: false + sqs: + notification: + name: ${SQS_NAME_PROD} + url: ${SQS_URL_PROD} + +server: + port: 8081 + +kakao: + client-id: ${KAKAO_ID} + authorization-grant-type: authorization_code + redirect-uri: ${KAKAO_REDIRECT_PROD} + +slack: + webhook: + url: ${SLACK_URL_PROD} \ No newline at end of file diff --git a/umbba-api/src/main/resources/application-prod2.yml b/umbba-api/src/main/resources/application-prod2.yml new file mode 100644 index 00000000..5d924d7f --- /dev/null +++ b/umbba-api/src/main/resources/application-prod2.yml @@ -0,0 +1,54 @@ +spring: + config: + activate: + on-profile: prod2 + + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: ${DB_URL_PROD} + username: ${DB_USER_PROD} + password: ${DB_PWD_PROD} + hikari: + pool-name: Hikari 커넥션 풀 # Pool + connection-timeout: 30000 # 30초(default: 30초) + maximum-pool-size: 10 # default: 10개 + max-lifetime: 600000 # 10분(default: 30분) + leak-detection-threshold: 3500 # default: 0(이용X) + + jpa: + show-sql: false + hibernate: + ddl-auto: update + ejb: + naming_strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy + properties: + hibernate: + format_sql: true + +cloud: + aws: + credentials: + accessKey: ${CLOUD_ACCESS_PROD} + secretKey: ${CLOUD_SECRET_PROD} + region: + static: ${CLOUD_REGION_PROD} + s3: + bucket: ${BUCKET_NAME_PROD} + stack: + auto: false + sqs: + notification: + name: ${SQS_NAME_PROD} + url: ${SQS_URL_PROD} + +server: + port: 8082 + +kakao: + client-id: ${KAKAO_ID} + authorization-grant-type: authorization_code + redirect-uri: ${KAKAO_REDIRECT_PROD} + +slack: + webhook: + url: ${SLACK_URL_PROD} \ No newline at end of file diff --git a/umbba-notification/src/main/resources/application-prod.yml b/umbba-notification/src/main/resources/application-prod.yml new file mode 100644 index 00000000..1c7a2009 --- /dev/null +++ b/umbba-notification/src/main/resources/application-prod.yml @@ -0,0 +1,54 @@ +spring: + config: + activate: + on-profile: prod + + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: ${DB_URL_PROD} + username: ${DB_USER_PROD} + password: ${DB_PWD_PROD} + hikari: + pool-name: Hikari 커넥션 풀 # Pool + connection-timeout: 30000 # 30초(default: 30초) + maximum-pool-size: 10 # default: 10개 + max-lifetime: 600000 # 10분(default: 30분) + leak-detection-threshold: 3500 # default: 0(이용X) + + jpa: + show-sql: false + hibernate: + ddl-auto: update + ejb: + naming_strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy + properties: + hibernate: + format_sql: true + +cloud: + aws: + credentials: + accessKey: ${CLOUD_ACCESS_PROD} + secretKey: ${CLOUD_SECRET_PROD} + region: + static: ${CLOUD_REGION_PROD} + s3: + bucket: ${BUCKET_NAME_PROD} + stack: + auto: false + sqs: + notification: + name: ${SQS_NAME_PROD} + url: ${SQS_URL_PROD} + +server: + port: 8083 + +kakao: + client-id: ${KAKAO_ID} + authorization-grant-type: authorization_code + redirect-uri: ${KAKAO_REDIRECT_PROD} + +slack: + webhook: + url: ${SLACK_URL_PROD} \ No newline at end of file