diff --git a/.github/workflows/deploy-admin.yml b/.github/workflows/deploy-admin.yml index 809501b7..8e96047b 100644 --- a/.github/workflows/deploy-admin.yml +++ b/.github/workflows/deploy-admin.yml @@ -6,10 +6,11 @@ on: - develop paths: - 'application-admin/**' + - 'application-config/**' - 'common/**' - 'domain-*/**' - - 'application-config/**' - 'security-admin/**' + - 'infra-aws/**' - 'build.gradle' - 'settings.gradle' - 'gradle/**' @@ -41,9 +42,7 @@ jobs: - name: Set YML run: | mkdir -p application-admin/src/main/resources - echo "${{ secrets.APPLICATION_DEV_ADMIN_YML }}" \ - | base64 --decode \ - > application-admin/src/main/resources/application-admin.yml + echo "${{ secrets.APPLICATION_DEV_ADMIN_YML }}" | base64 --decode application-admin/src/main/resources/application-admin.yml find application-admin/src - name: Build Admin JAR diff --git a/.github/workflows/deploy-user.yml b/.github/workflows/deploy-user.yml new file mode 100644 index 00000000..449f6483 --- /dev/null +++ b/.github/workflows/deploy-user.yml @@ -0,0 +1,85 @@ +name: Dev User CI/CD + +on: + push: + branches: + - develop + paths: + - 'application-user/**' + - 'application-config/**' + - 'common/**' + - 'domain-*/**' + - 'security-front/**' + - 'external-oauth/**' + - 'build.gradle' + - 'settings.gradle' + - 'gradle/**' + +env: + PROJECT_NAME: NoWait + DIVISION: user + AWS_REGION: ap-northeast-2 + AWS_S3_BUCKET: nowait-deploy-github-actions + AWS_CODE_DEPLOY_APPLICATION: nowaiting + AWS_CODE_DEPLOY_GROUP: nowaiting-deploy-dev-user + +jobs: + build-with-gradle: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: JDK 17 설치 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'zulu' + + - name: gradlew에 실행 권한 부여 + run: chmod +x ./gradlew + + - name: Set YML + run: | + mkdir -p application-user/src/main/resources + echo "${{ secrets.APPLICATION_DEV_USER_YML }}" | base64 --decode application-user/src/main/resources/application-user.yml + find application-user/src + + - name: Build User JAR + run: ./gradlew clean :application-user:bootJar -x test + + - name: Prepare deployment package + run: | + rm -rf deploy + mkdir -p deploy/scripts + cp scripts/start-admin.sh scripts/stop-admin.sh deploy/scripts/ + cp appspec-admin.yml deploy/appspec.yml + cp application-admin/build/libs/application-admin-*.jar deploy/application-admin.jar + cd deploy + zip -r ../NoWait-admin-${GITHUB_SHA}.zip . + cd .. + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-region: ${{ env.AWS_REGION }} + aws-access-key-id: ${{ secrets.DEVSERVER_CICD_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.DEVSERVER_CICD_SECRET_KEY }} + + - name: Upload to S3 + run: | + aws deploy push \ + --application-name "${{ env.AWS_CODE_DEPLOY_APPLICATION }}" \ + --ignore-hidden-files \ + --s3-location "s3://${{ env.AWS_S3_BUCKET }}/${{ env.PROJECT_NAME }}/${{ env.DIVISION }}/${{ github.sha }}.zip" \ + --source deploy + + - name: Create CodeDeploy deployment + run: | + aws deploy create-deployment \ + --application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }} \ + --deployment-config-name CodeDeployDefault.AllAtOnce \ + --deployment-group-name ${{ env.AWS_CODE_DEPLOY_GROUP }} \ + --s3-location bucket=${{ env.AWS_S3_BUCKET }},key=${{ env.PROJECT_NAME }}/${{ env.DIVISION }}/${{ github.sha }}.zip,bundleType=zip + + diff --git a/application-admin/src/main/java/com/nowait/applicationadmin/ApiAdminApplication.java b/application-admin/src/main/java/com/nowait/applicationadmin/ApiAdminApplication.java index 95f08d3a..14ac1764 100644 --- a/application-admin/src/main/java/com/nowait/applicationadmin/ApiAdminApplication.java +++ b/application-admin/src/main/java/com/nowait/applicationadmin/ApiAdminApplication.java @@ -32,4 +32,3 @@ public static void main(String[] args) { org.springframework.boot.SpringApplication.run(ApiAdminApplication.class, args); } } - diff --git a/appspec-user.yml b/appspec-user.yml new file mode 100644 index 00000000..1edca8d4 --- /dev/null +++ b/appspec-user.yml @@ -0,0 +1,20 @@ +version: 0.0 +os: linux + +files: + - source: / + destination: /home/ubuntu/spring-github-action-user + overwrite: yes + +permissions: + - object: / + owner: ubuntu + group: ubuntu + +hooks: + AfterInstall: + - location: scripts/stop-user.sh + timeout: 60 + ApplicationStart: + - location: scripts/start-user.sh + timeout: 60 diff --git a/scripts/start-user.sh b/scripts/start-user.sh index eb4db17b..ad7dcafd 100644 --- a/scripts/start-user.sh +++ b/scripts/start-user.sh @@ -1,19 +1,19 @@ #!/bin/bash -REPOSITORY="/home/ubuntu/spring-github-action" +REPOSITORY="/home/ubuntu/spring-github-action-user" cd $REPOSITORY -APP_NAME=application-admin -JAR_NAME=$(ls $REPOSITORY/build/libs/ | grep '.jar' | tail -n 1) -JAR_PATH=$REPOSITORY/build/libs/$JAR_NAME +APP_NAME=application-user +JAR_NAME=$(ls $REPOSITORY | grep '.jar' | tail -n 1) +JAR_PATH=$REPOSITORY/$JAR_NAME START_LOG="$REPOSITORY/start.log" ERROR_LOG="$REPOSITORY/error.log" APP_LOG="$REPOSITORY/application.log" $ chmod 666 $START_LOG -$ chmod 666 ERROR_LOG -$ chmod 666 APP_LOG +$ chmod 666 $ERROR_LOG +$ chmod 666 $APP_LOG SERVICE_PID=$(pgrep -f ${APP_NAME}.*.jar) # 실행중인 Spring 서버의 PID NOW=$(date +%c) diff --git a/scripts/stop-user.sh b/scripts/stop-user.sh index 868f77b9..115668ae 100644 --- a/scripts/stop-user.sh +++ b/scripts/stop-user.sh @@ -1,14 +1,14 @@ #!/bin/bash -REPOSITORY=/home/ubuntu/spring-github-action +REPOSITORY="/home/ubuntu/spring-github-action-user" cd $REPOSITORY -APP_NAME=application-admin -JAR_NAME=$(ls $REPOSITORY/build/libs/ | grep '.jar' | tail -n 1) -JAR_PATH=$REPOSITORY/build/libs/$JAR_NAME +APP_NAME=application-user +JAR_NAME=$(ls $REPOSITORY | grep '.jar' | tail -n 1) +JAR_PATH=$REPOSITORY/$JAR_NAME STOP_LOG="$REPOSITORY/stop.log" -$ chmod 666 STOP_LOG +$ chmod 666 "$STOP_LOG" CURRENT_PID=$(pgrep -f ${APP_NAME}.*.jar)