From 4639441fcc5ab1c9df565c89f77e0c5de7b928f1 Mon Sep 17 00:00:00 2001 From: jiminnimij <124450012+jiminnimij@users.noreply.github.com> Date: Mon, 29 Dec 2025 22:56:00 +0900 Subject: [PATCH 01/10] =?UTF-8?q?:sparkles:=20=EB=B8=94=EB=A3=A8=20?= =?UTF-8?q?=EA=B7=B8=EB=A6=B0=20=EB=B0=B0=ED=8F=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cicdDeploy.yml | 94 ------------------------------ .github/workflows/gradle.yml | 57 +++++++++++++++++- Dockerfile | 5 +- config/nginx/default.conf | 39 ++++++++++--- docker-compose-blue.yml | 19 ++++++ docker-compose-green.yml | 19 ++++++ docker-compose.yml | 26 ++++----- src/main/resources/application.yml | 33 ++++++++++- 8 files changed, 169 insertions(+), 123 deletions(-) delete mode 100644 .github/workflows/cicdDeploy.yml create mode 100644 docker-compose-blue.yml create mode 100644 docker-compose-green.yml diff --git a/.github/workflows/cicdDeploy.yml b/.github/workflows/cicdDeploy.yml deleted file mode 100644 index 182ff34..0000000 --- a/.github/workflows/cicdDeploy.yml +++ /dev/null @@ -1,94 +0,0 @@ -name: Deploy to EC2 - -on: - push: - branches: - - 2-chore-cicd - workflow_dispatch: - inputs: - name: - description: 'admin' - required: true - default: 'user' - message: - description: 'message' - required: false - default: '수동 워크플로우 트리거' - -permissions: - contents: read - -jobs: - build: - runs-on: ubuntu-latest - steps: - # 기본 체크아웃 - - name: Checkout - uses: actions/checkout@v3 - - - name: Make application-secret.yml without env - run: | - touch ./src/main/resources/application.yml - echo "${{ secrets.APPLICATION }}" > ./src/main/resources/application.yml - touch ./src/main/resources/application-prod.yml - echo "${{ secrets.APPLICATION_PROD }}" > ./src/main/resources/application-prod.yml - - # JDK version 설정 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - - - name: Grant execute permission for gradlew - run: chmod +x ./gradlew - - ## gradle build - - name: Build with Gradle - run: ./gradlew bootJar - - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Docker app build & push - uses: docker/build-push-action@v5 - with: - context: . - file: ./Dockerfile - platforms: linux/amd64 - push: true - tags: ${{ secrets.DOCKER_USERNAME }}/backend - - - name: Docker nginx build & push - uses: docker/build-push-action@v5 - with: - context: . - file: ./config/nginx/Dockerfile - platforms: linux/amd64 - push: true - tags: ${{ secrets.DOCKER_USERNAME }}/nginx - - # ssh 접근 후 docker 이미지 pull 및 컨테이너 재시작 - - name: executing remote ssh commands using password - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.EC2_HOST }} - username: ubuntu # ec2-user 에서 변경 - key: ${{ secrets.EC2_KEY }} - script: | - cd /home/ubuntu/ceos - - sudo touch .env - echo "${{ secrets.ENV }}" | sudo tee .env > /dev/null - - sudo curl -o docker-compose.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/2-chore-cicd/docker-compose.yml - - sudo chmod 666 /var/run/docker.sock - sudo docker rm -f $(docker ps -qa) - sudo docker pull ${{ secrets.DOCKER_USERNAME }}/backend - sudo docker pull ${{ secrets.DOCKER_USERNAME }}/nginx - docker compose -f docker-compose.yml --env-file .env up -d - docker image prune -f diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index f203b05..a52527b 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - feature/SCRUM-66-bluegreenDeploy workflow_dispatch: inputs: name: @@ -71,6 +72,29 @@ jobs: push: true tags: ${{ secrets.DOCKER_USERNAME }}/nginx + - name: set target IP + run: | + STATUS=$(curl -o /dev/null -w "%{http_code}" "http://${{ secrets.EC2_HOST }}/env") + echo $STATUS + if [ $STATUS = 200 ]; then + CURRENT_UPSTREAM=$(curl -s "http://${{ secrets.EC2_HOST }}/env") + else + CURRENT_UPSTREAM=green + fi + echo CURRENT_UPSTREAM=$CURRENT_UPSTREAM >> $GITHUB_ENV + if [ $CURRENT_UPSTREAM = blue ]; then + echo "CURRENT_PORT=8080" >> $GITHUB_ENV + echo "STOPPED_PORT=8081" >> $GITHUB_ENV + echo "TARGET_UPSTREAM=green" >> $GITHUB_ENV + elif [ $CURRENT_UPSTREAM = green ]; then + echo "CURRENT_PORT=8081" >> $GITHUB_ENV + echo "STOPPED_PORT=8080" >> $GITHUB_ENV + echo "TARGET_UPSTREAM=blue" >> $GITHUB_ENV + else + echo "error" + exit 1 + fi + # ssh 접근 후 docker 이미지 pull 및 컨테이너 재시작 - name: executing remote ssh commands using password uses: appleboy/ssh-action@master @@ -84,11 +108,38 @@ jobs: sudo touch .env echo "${{ secrets.ENV }}" | sudo tee .env > /dev/null - sudo curl -o docker-compose.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/main/docker-compose.yml + sudo curl -o docker-compose.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/feature/SCRUM-66-bluegreenDeploy/docker-compose.yml + sudo curl -o docker-compose-blue.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/feature/SCRUM-66-bluegreenDeploy/docker-compose-blue.yml + sudo curl -o docker-compose-green.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/feature/SCRUM-66-bluegreenDeploy/docker-compose-green.yml sudo chmod 666 /var/run/docker.sock sudo docker rm -f $(docker ps -qa) sudo docker pull ${{ secrets.DOCKER_USERNAME }}/backend - sudo docker pull ${{ secrets.DOCKER_USERNAME }}/nginx - docker compose -f docker-compose.yml --env-file .env up -d + docker compose -f docker-compose-${{env.TARGET_UPSTREAM}}.yml --env-file .env up -d docker image prune -f + + - name: Check deploy server URL + uses: jtalk/url-health-check-action@v3 + with: + url: http://${{ secrets.EC2_HOST }}:${{env.STOPPED_PORT}}/actuator/health + max-attempts: 3 + retry-delay: 10s + + - name: Change nginx upstream + uses: appleboy/ssh-action@master + with: + username: ubuntu + host: ${{ secrets.EC2_HOST }} + key: ${{ secrets.EC2_KEY }} + script: | + sudo docker exec -i nginx bash -c 'echo "set \$service_url ${{ env.TARGET_UPSTREAM }};" > /etc/nginx/conf.d/service-env.inc && nginx -s reload' + + - name: Stop current server + uses: appleboy/ssh-action@master + with: + username: ubuntu + host: ${{ secrets.EC2_HOST }} + key: ${{ secrets.EC2_KEY }} + script: | + sudo docker stop ${{env.CURRENT_UPSTREAM}} + sudo docker rm ${{env.CURRENT_UPSTREAM}} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 80f3d1f..20b3389 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,5 +10,8 @@ ENV MANAGEMENT_METRICS_BINDERS_PROCESSOR_ENABLED="false" EXPOSE 80 ARG JAR_FILE=/build/libs/*.jar +ARG PROFILES +ARG ENV COPY ${JAR_FILE} app.jar -ENTRYPOINT ["java","-jar","-Duser.timezone=Asia/Seoul","-Dspring.profiles.active=prod","/app.jar"] \ No newline at end of file + +ENTRYPOINT ["java","-jar","-Duser.timezone=Asia/Seoul","-Dspring.profiles.active=${PROFILES}", "-Dsever.env=${ENV}","/app.jar"] \ No newline at end of file diff --git a/config/nginx/default.conf b/config/nginx/default.conf index 22b378a..156a658 100644 --- a/config/nginx/default.conf +++ b/config/nginx/default.conf @@ -1,12 +1,33 @@ +upstream blue { + server blue:8080; +} + +upstream green { + server green:8081; +} + server { - listen 80; - listen [::]:80; + listen 80; + listen [::]:80; + + include /etc/nginx/conf.d/service-env.inc; - location / { - proxy_set_header Host $host; - proxy_pass http://backend:8080/; - proxy_read_timeout 90; + location / { + proxy_pass http://$service_url; + + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; - ## try_files $uri $uri/ =404; - } -} \ No newline at end of file + root /usr/share/nginx/html; + index index.html index.htm; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} + + + \ No newline at end of file diff --git a/docker-compose-blue.yml b/docker-compose-blue.yml new file mode 100644 index 0000000..3aac587 --- /dev/null +++ b/docker-compose-blue.yml @@ -0,0 +1,19 @@ +version: '3.8' + +services: + blue: + image: nokmaster/backend + container_name: blue + ports: + - "8080:8080" + env_file: + - .env + environment: + - PROFILES=blue + - ENV=blue + networks: + - nok-network + +networks: + nok-network: + external: true diff --git a/docker-compose-green.yml b/docker-compose-green.yml new file mode 100644 index 0000000..7ce2198 --- /dev/null +++ b/docker-compose-green.yml @@ -0,0 +1,19 @@ +version: '3.8' + +services: + green: + image: nokmaster/backend + container_name: green + ports: + - "8081:8081" + env_file: + - .env + environment: + - PROFILES=green + - ENV=green + networks: + - nok-network + +networks: + nok-network: + external: true \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 0f62ccb..2c2c7dd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,19 +1,17 @@ -version: "3" - +version: '3.8' services: - backend: - image: nokmaster/backend - container_name: backend - hostname: backend - env_file: - - .env - expose: - - "8080" - nginx: image: nokmaster/nginx - depends_on: - - backend + container_name: nginx restart: always ports: - - "80:80" \ No newline at end of file + - "80:80" + networks: + - nok-network + +volumes: + redis-data: + +networks: + nok-network: + name: nok-network diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f4c32d9..609d3df 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -4,7 +4,12 @@ spring: max-file-size: 10MB max-request-size: 10MB profiles: - active: prod + active: blue + group: + local: local + blue: blue, prod + green: green, prod + security: oauth2: client: @@ -65,4 +70,28 @@ logging: level: org.hibernate.SQL: debug org.hibernate.orm.jdbc.bind: trace - com.zaxxer.hikari: DEBUG \ No newline at end of file + com.zaxxer.hikari: DEBUG + +--- +spring: + config: + activate: + on-profile: blue + +server: + port: 8080 + serverAddress: \${SERVER_PROD_URL} + +serverName: blue_server +--- +spring: + config: + activate: + on-profile: green + +server: + port: 8080 + serverAddress: \${SERVER_PROD_URL} + +serverName: green_server +--- \ No newline at end of file From 61975e9869952c8667a60c14673d5a61dbc62982 Mon Sep 17 00:00:00 2001 From: jiminnimij <124450012+jiminnimij@users.noreply.github.com> Date: Mon, 29 Dec 2025 23:09:48 +0900 Subject: [PATCH 02/10] =?UTF-8?q?:bug:=20nginx=20volume=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 2c2c7dd..c35a259 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,12 +6,11 @@ services: restart: always ports: - "80:80" + volumes: + - ./nginx/conf.d:/etc/nginx/conf.d networks: - nok-network -volumes: - redis-data: - networks: nok-network: name: nok-network From 2c96e678cbb3b6270e42b52ee19ace8712683aa4 Mon Sep 17 00:00:00 2001 From: jiminnimij <124450012+jiminnimij@users.noreply.github.com> Date: Mon, 29 Dec 2025 23:12:17 +0900 Subject: [PATCH 03/10] =?UTF-8?q?:sparkles:=20/env=20=EA=B2=BD=EB=A1=9C=20?= =?UTF-8?q?=ED=97=88=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 6 +++++- .../com/example/tikitaka/global/config/SecurityConfig.java | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 20b3389..94d3a1a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,4 +14,8 @@ ARG PROFILES ARG ENV COPY ${JAR_FILE} app.jar -ENTRYPOINT ["java","-jar","-Duser.timezone=Asia/Seoul","-Dspring.profiles.active=${PROFILES}", "-Dsever.env=${ENV}","/app.jar"] \ No newline at end of file +ENTRYPOINT ["sh", "-c", "java \ + -Duser.timezone=Asia/Seoul \ + -Dspring.profiles.active=${PROFILES:-prod} \ + -Dserver.env=${ENV:-prod} \ + -jar /app/app.jar"] \ No newline at end of file diff --git a/src/main/java/com/example/tikitaka/global/config/SecurityConfig.java b/src/main/java/com/example/tikitaka/global/config/SecurityConfig.java index 435706d..0503392 100644 --- a/src/main/java/com/example/tikitaka/global/config/SecurityConfig.java +++ b/src/main/java/com/example/tikitaka/global/config/SecurityConfig.java @@ -54,7 +54,7 @@ public PasswordEncoder passwordEncoder() { }; private final String[] ActuatorPatterns = { - "/actuator/health" + "/actuator/health", "/env" }; private final String[] GetPermittedPatterns = { From 9d4fa353cf96e9cb9fe638b9e29b3e2971841ff7 Mon Sep 17 00:00:00 2001 From: jiminnimij <124450012+jiminnimij@users.noreply.github.com> Date: Mon, 29 Dec 2025 23:15:29 +0900 Subject: [PATCH 04/10] =?UTF-8?q?:bug:=20=EC=9D=B4=EC=A0=84=20=EC=BB=A8?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EB=84=88=20=EC=82=AD=EC=A0=9C=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/gradle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index a52527b..804cf3a 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -113,7 +113,7 @@ jobs: sudo curl -o docker-compose-green.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/feature/SCRUM-66-bluegreenDeploy/docker-compose-green.yml sudo chmod 666 /var/run/docker.sock - sudo docker rm -f $(docker ps -qa) + sudo docker pull ${{ secrets.DOCKER_USERNAME }}/backend docker compose -f docker-compose-${{env.TARGET_UPSTREAM}}.yml --env-file .env up -d docker image prune -f From 96eddf535c2b9824703cd7a8efbe8453f9e2c6eb Mon Sep 17 00:00:00 2001 From: jiminnimij <124450012+jiminnimij@users.noreply.github.com> Date: Mon, 29 Dec 2025 23:23:31 +0900 Subject: [PATCH 05/10] =?UTF-8?q?:bug:=20dockerfile=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 94d3a1a..c95dd90 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,8 +8,10 @@ ENV SPRING_AUTOCONFIGURE_EXCLUDE="org.springframework.boot.actuate.autoconfigure # (중요) ProcessorMetrics 바인더 비활성화 ENV MANAGEMENT_METRICS_BINDERS_PROCESSOR_ENABLED="false" +WORKDIR /app + EXPOSE 80 -ARG JAR_FILE=/build/libs/*.jar +ARG JAR_FILE=build/libs/*.jar ARG PROFILES ARG ENV COPY ${JAR_FILE} app.jar @@ -18,4 +20,4 @@ ENTRYPOINT ["sh", "-c", "java \ -Duser.timezone=Asia/Seoul \ -Dspring.profiles.active=${PROFILES:-prod} \ -Dserver.env=${ENV:-prod} \ - -jar /app/app.jar"] \ No newline at end of file + -jar app.jar"] \ No newline at end of file From 98c3b0f2f470d3649a33bba45ce5f7a367478141 Mon Sep 17 00:00:00 2001 From: jiminnimij <124450012+jiminnimij@users.noreply.github.com> Date: Mon, 29 Dec 2025 23:39:35 +0900 Subject: [PATCH 06/10] =?UTF-8?q?:bug:=20main=EC=97=90=EC=84=9C=EB=A7=8C?= =?UTF-8?q?=20=EB=8F=99=EC=9E=91=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/gradle.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 804cf3a..ce85c05 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -4,7 +4,6 @@ on: push: branches: - main - - feature/SCRUM-66-bluegreenDeploy workflow_dispatch: inputs: name: @@ -108,9 +107,9 @@ jobs: sudo touch .env echo "${{ secrets.ENV }}" | sudo tee .env > /dev/null - sudo curl -o docker-compose.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/feature/SCRUM-66-bluegreenDeploy/docker-compose.yml - sudo curl -o docker-compose-blue.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/feature/SCRUM-66-bluegreenDeploy/docker-compose-blue.yml - sudo curl -o docker-compose-green.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/feature/SCRUM-66-bluegreenDeploy/docker-compose-green.yml + sudo curl -o docker-compose.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/main/docker-compose.yml + sudo curl -o docker-compose-blue.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/main/docker-compose-blue.yml + sudo curl -o docker-compose-green.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/main/docker-compose-green.yml sudo chmod 666 /var/run/docker.sock From 9067a649c853f1ab5a4b65ad2a6d38e2fba1d363 Mon Sep 17 00:00:00 2001 From: jiminnimij <124450012+jiminnimij@users.noreply.github.com> Date: Tue, 30 Dec 2025 22:38:17 +0900 Subject: [PATCH 07/10] =?UTF-8?q?:bug:=20nginx=EB=A1=9C=20/env=20=ED=99=9C?= =?UTF-8?q?=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/gradle.yml | 9 +++++---- Dockerfile | 6 +----- config/nginx/default.conf | 7 ++++++- docker-compose-green.yml | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index ce85c05..ff46308 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - feature/SCRUM-66-bluegreenDeploy workflow_dispatch: inputs: name: @@ -73,7 +74,7 @@ jobs: - name: set target IP run: | - STATUS=$(curl -o /dev/null -w "%{http_code}" "http://${{ secrets.EC2_HOST }}/env") + STATUS=$(curl -o /dev/null -w "%{http_code}" "http://${{ secrets.EC2_HOST }}/actuator/health") echo $STATUS if [ $STATUS = 200 ]; then CURRENT_UPSTREAM=$(curl -s "http://${{ secrets.EC2_HOST }}/env") @@ -107,9 +108,9 @@ jobs: sudo touch .env echo "${{ secrets.ENV }}" | sudo tee .env > /dev/null - sudo curl -o docker-compose.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/main/docker-compose.yml - sudo curl -o docker-compose-blue.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/main/docker-compose-blue.yml - sudo curl -o docker-compose-green.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/main/docker-compose-green.yml + sudo curl -o docker-compose.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/feature/SCRUM-66-bluegreenDeploy/docker-compose.yml + sudo curl -o docker-compose-blue.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/feature/SCRUM-66-bluegreenDeploy/docker-compose-blue.yml + sudo curl -o docker-compose-green.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/feature/SCRUM-66-bluegreenDeploy/docker-compose-green.yml sudo chmod 666 /var/run/docker.sock diff --git a/Dockerfile b/Dockerfile index c95dd90..9972400 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,8 +16,4 @@ ARG PROFILES ARG ENV COPY ${JAR_FILE} app.jar -ENTRYPOINT ["sh", "-c", "java \ - -Duser.timezone=Asia/Seoul \ - -Dspring.profiles.active=${PROFILES:-prod} \ - -Dserver.env=${ENV:-prod} \ - -jar app.jar"] \ No newline at end of file +ENTRYPOINT ["java","-jar","-Duser.timezone=Asia/Seoul","-Dspring.profiles.active=prod","/app.jar"] \ No newline at end of file diff --git a/config/nginx/default.conf b/config/nginx/default.conf index 156a658..07aab9f 100644 --- a/config/nginx/default.conf +++ b/config/nginx/default.conf @@ -3,7 +3,7 @@ upstream blue { } upstream green { - server green:8081; + server green:8080; } server { @@ -12,6 +12,11 @@ server { include /etc/nginx/conf.d/service-env.inc; + location = /env { + default_type text/plain; + return 200 "service_url"; + } + location / { proxy_pass http://$service_url; diff --git a/docker-compose-green.yml b/docker-compose-green.yml index 7ce2198..5bfab32 100644 --- a/docker-compose-green.yml +++ b/docker-compose-green.yml @@ -5,7 +5,7 @@ services: image: nokmaster/backend container_name: green ports: - - "8081:8081" + - "8081:8080" env_file: - .env environment: From 1ff16e0aafbf6e73a5262649e22339eae0ce0786 Mon Sep 17 00:00:00 2001 From: jiminnimij <124450012+jiminnimij@users.noreply.github.com> Date: Tue, 30 Dec 2025 22:45:05 +0900 Subject: [PATCH 08/10] =?UTF-8?q?:bug:=20=EB=B3=80=EA=B2=BD=20port=20?= =?UTF-8?q?=ED=99=9C=EC=84=B1=ED=99=94=20=EC=B2=B4=ED=81=AC=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/gradle.yml | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index ff46308..192c611 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -119,11 +119,24 @@ jobs: docker image prune -f - name: Check deploy server URL - uses: jtalk/url-health-check-action@v3 + uses: appleboy/ssh-action@master with: - url: http://${{ secrets.EC2_HOST }}:${{env.STOPPED_PORT}}/actuator/health - max-attempts: 3 - retry-delay: 10s + host: ${{ secrets.EC2_HOST }} + username: ubuntu + key: ${{ secrets.EC2_KEY }} + script: | + set -e + for i in {1..10}; do + echo "[$i] health check..." + if curl -f http://localhost:${{ env.STOPPED_PORT }}/actuator/health > /dev/null 2>&1; then + echo "health check success" + exit 0 + fi + echo "health check failed, retrying in 5s..." + sleep 5 + done + echo "health check failed after 10 attempts" + exit 1 - name: Change nginx upstream uses: appleboy/ssh-action@master From 539801fb23d58757e5968ee1581766de678fb3ca Mon Sep 17 00:00:00 2001 From: jiminnimij <124450012+jiminnimij@users.noreply.github.com> Date: Tue, 30 Dec 2025 22:53:00 +0900 Subject: [PATCH 09/10] =?UTF-8?q?:bug:=20dockerfile=20app.jar=20=EC=98=AC?= =?UTF-8?q?=20=E3=85=A0=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9972400..679be8e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ FROM eclipse-temurin:17-jdk +WORKDIR /app # (중요) cgroup 리소스 감지 비활성화 ENV JAVA_TOOL_OPTIONS="-XX:-UseContainerSupport" @@ -16,4 +17,4 @@ ARG PROFILES ARG ENV COPY ${JAR_FILE} app.jar -ENTRYPOINT ["java","-jar","-Duser.timezone=Asia/Seoul","-Dspring.profiles.active=prod","/app.jar"] \ No newline at end of file +ENTRYPOINT ["java","-jar","-Duser.timezone=Asia/Seoul","-Dspring.profiles.active=prod","/app/app.jar"] \ No newline at end of file From 27fb45e8459a437cded75d64094605036555d45f Mon Sep 17 00:00:00 2001 From: jiminnimij <124450012+jiminnimij@users.noreply.github.com> Date: Tue, 30 Dec 2025 22:57:18 +0900 Subject: [PATCH 10/10] =?UTF-8?q?:bug:=20main=EC=97=90=EB=A7=8C=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/gradle.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 192c611..0aee0bc 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -4,7 +4,6 @@ on: push: branches: - main - - feature/SCRUM-66-bluegreenDeploy workflow_dispatch: inputs: name: @@ -108,9 +107,9 @@ jobs: sudo touch .env echo "${{ secrets.ENV }}" | sudo tee .env > /dev/null - sudo curl -o docker-compose.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/feature/SCRUM-66-bluegreenDeploy/docker-compose.yml - sudo curl -o docker-compose-blue.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/feature/SCRUM-66-bluegreenDeploy/docker-compose-blue.yml - sudo curl -o docker-compose-green.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/feature/SCRUM-66-bluegreenDeploy/docker-compose-green.yml + sudo curl -o docker-compose.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/main/docker-compose.yml + sudo curl -o docker-compose-blue.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/main/docker-compose-blue.yml + sudo curl -o docker-compose-green.yml https://raw.githubusercontent.com/ewha-exhibition/Backend/main/docker-compose-green.yml sudo chmod 666 /var/run/docker.sock