diff --git a/.github/workflows/be_cd-production.yml b/.github/workflows/be_cd-production.yml index 717379615..a4af9e37a 100644 --- a/.github/workflows/be_cd-production.yml +++ b/.github/workflows/be_cd-production.yml @@ -40,8 +40,8 @@ jobs: - name: Image build and push run: | - docker build --build-arg PROFILE=prod --build-arg DEPENDENCY=build/dependency -t ${{ secrets.DOCKER_REPO_NAME }}/springboot-app:test-latest --platform linux/arm64 . - docker push ${{ secrets.DOCKER_REPO_NAME }}/springboot-app:test-latest + docker build --build-arg PROFILE=prod --build-arg DEPENDENCY=build/dependency -t ${{ secrets.DOCKER_REPO_NAME }}/springboot-app:latest --platform linux/arm64 . + docker push ${{ secrets.DOCKER_REPO_NAME }}/springboot-app:latest - name: Upload docker-compose yaml script to artifact uses: actions/upload-artifact@v4 @@ -69,13 +69,21 @@ jobs: - name: Extract secrets as .be_app-env file run: | + echo $(pwd) + chmod +x ./deploy.sh # 스크립트에 실행 권한 부여 + echo chmod ok + source ./deploy.sh + echo source ok + echo "BLUE_PORT=$BLUE_PORT" >> $GITHUB_ENV + echo "GREEN_PORT=$GREEN_PORT" >> $GITHUB_ENV + cat < ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env # Docker Hub info from Github Secrets DOCKER_REPO_NAME=${{ secrets.DOCKER_REPO_NAME }} + DOCKER_IMAGE_VERSION=latest # DB Configuration secrets info from Github Secrets - MYSQL_DB_NAME=${{ secrets.MYSQL_DB_NAME }} MYSQL_TIME_ZONE=${{ secrets.MYSQL_TIME_ZONE }} DB_BINDING_PORT=${{ secrets.DB_BINDING_PORT }} DOCKER_DATA_PATH=${{ secrets.DOCKER_DATA_PATH }} @@ -97,21 +105,39 @@ jobs: INSTANCE_NAME=${{ secrets.INSTANCE_A_NAME }} # Server App - SERVER_BINDING_PORT=${{ secrets.PRODUCTION_SERVER_BINDING_PORT }} + BLUE_SERVER_BINDING_PORT=${BLUE_PORT} + GREEN_SERVER_BINDING_PORT=${GREEN_PORT} SERVER_LOGS_PATH=${{ secrets.SERVER_LOGS_PATH }} EOF - - - name: Stop and remove existing containers + + - name: remove old spring-app image + run: | + sudo docker image rm -f ${{ secrets.DOCKER_REPO_NAME }}/springboot-app; + + - name: Start the new (green/blue) environment + run: | + sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml -p $GREEN_PORT up -d + + - name: Wait for new environment to be healthy run: | - sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml down --rmi all - - name: Deploy docker container + until curl -sf http://localhost:${GREEN_PORT}/api/actuator/health | grep "UP"; do sleep 5; done + + - name: Reload NGINX run: | - sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml up -d + sudo systemctl reload nginx + - name: Stop and remove the old environment + run: | + sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml -p $BLUE_PORT down + + - name: Delete Dangling docker images + run: | + sudo docker image prune -a -f + deployB: environment: production runs-on: production-ec2-B-runner - needs: deployA + needs: build defaults: run: working-directory: ./backend @@ -126,15 +152,20 @@ jobs: run: | sudo mv be_app-docker-compose.yml ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/ - - name: waiting deployA complete - run: | - sudo ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/scheduler.sh - - name: Extract secrets as .be_app-env file run: | + echo $(pwd) + chmod +x ./deploy.sh # 스크립트에 실행 권한 부여 + echo chmod ok + source ./deploy.sh + echo source ok + echo "BLUE_PORT=$BLUE_PORT" >> $GITHUB_ENV + echo "GREEN_PORT=$GREEN_PORT" >> $GITHUB_ENV + cat < ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env # Docker Hub info from Github Secrets + DOCKER_IMAGE_VERSION=latest DOCKER_REPO_NAME=${{ secrets.DOCKER_REPO_NAME }} # DB Configuration secrets info from Github Secrets @@ -150,7 +181,6 @@ jobs: SLAVE_DB_PASSWORD=${{ secrets.SLAVE_DB_PASSWORD }} DDL_AUTO=${{ secrets.DDL_AUTO }} - # OAUTH & JWT CLIENT_ID=${{ secrets.CLIENT_ID }} CLIENT_SECRET=${{ secrets.CLIENT_SECRET }} @@ -160,15 +190,32 @@ jobs: # INSTANCE NAME INSTANCE_NAME=${{ secrets.INSTANCE_B_NAME }} - # Server App - SERVER_BINDING_PORT=${{ secrets.PRODUCTION_SERVER_BINDING_PORT }} + BLUE_SERVER_BINDING_PORT=${BLUE_PORT} + GREEN_SERVER_BINDING_PORT=${GREEN_PORT} SERVER_LOGS_PATH=${{ secrets.SERVER_LOGS_PATH }} EOF - - name: Stop and remove existing containers + - name: remove old spring-app image + run: | + sudo docker image rm -f ${{ secrets.DOCKER_REPO_NAME }}/springboot-app; + + - name: Start the new (green/blue) environment + run: | + sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml -p $GREEN_PORT up -d + + - name: Wait for new environment to be healthy + run: | + until curl -sf http://localhost:${GREEN_PORT}/api/actuator/health | grep "UP"; do sleep 5; done + + - name: Reload NGINX + run: | + sudo systemctl reload nginx + + - name: Stop and remove the old environment run: | - sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml down --rmi all - - name: Deploy docker container + sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml -p $BLUE_PORT down + + - name: Delete Dangling docker images run: | - sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml up -d + sudo docker image prune -a -f diff --git a/.github/workflows/be_cd-test.yml b/.github/workflows/be_cd-test.yml index d88f5a059..4c5d76003 100644 --- a/.github/workflows/be_cd-test.yml +++ b/.github/workflows/be_cd-test.yml @@ -128,4 +128,8 @@ jobs: - name: Delete Dangling docker images run: | - sudo docker image prune -a -f + sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml up -d + + - name: Delete Dangling docker images + run: | + sudo docker image prune diff --git a/backend/src/main/resources/application-prod.yml b/backend/src/main/resources/application-prod.yml index ac8d94932..60b34aee1 100644 --- a/backend/src/main/resources/application-prod.yml +++ b/backend/src/main/resources/application-prod.yml @@ -33,11 +33,12 @@ management: endpoints: web: exposure: - include: prometheus + include: prometheus, health base-path: /api/actuator server: tomcat: + accept-count: 300 mbeanregistry: enabled: true