From b53b50c4a1b0b3152d2651b879ccf911817a0dce Mon Sep 17 00:00:00 2001 From: scheduled-for-hacker Date: Sun, 2 Jun 2024 21:00:22 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[bugfix/#286]=20dev=20branch=20=EC=98=81?= =?UTF-8?q?=EA=B5=AC=20=EC=82=AD=EC=A0=9C=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index e0926b19..090d744b 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -27,7 +27,7 @@ jobs: if [ -d "$REPO_PATH" ]; then cd $REPO_PATH - git checkout dev + git checkout master git pull else echo "Error: Directory $REPO_PATH does not exist." From cf83552d938d7308c5d980fb107b5c442621dc26 Mon Sep 17 00:00:00 2001 From: scheduled-for-hacker Date: Sun, 2 Jun 2024 21:26:24 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[bugfix/#286]=20discord=20=ED=88=B4=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-dev.yml | 18 ++++++++---------- .github/workflows/depoly-production.yml | 17 ++++++++--------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index 090d744b..cf377ac5 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -53,19 +53,17 @@ jobs: docker run -d --name $CONTAINER_NAME --network host -p 8082:8082 -e SPRING_CONFIG_IMPORT=configserver:http://localhost:8888 $IMAGE_NAME echo "Deployment done" - - name: Notify Discord on Success if: success() - run: | - curl -H "Content-Type: application/json" \ - -d '{"content": "Production deployment completed successfully!"}' \ - ${{ secrets.DISCORD_WEBHOOK_URL }} - + uses: discord-actions/message@v2 + with: + webhookUrl: ${{ secrets.DISCORD_WEBHOOK_URL }} + message: "Dev deployment completed successfully!" - name: Notify Discord on Failure if: failure() - run: | - curl -H "Content-Type: application/json" \ - -d '{"content": "Production deployment failed!"}' \ - ${{ secrets.DISCORD_WEBHOOK_URL }} \ No newline at end of file + uses: discord-actions/message@v2 + with: + webhookUrl: ${{ secrets.DISCORD_WEBHOOK_URL }} + message: "Dev deployment failed..." \ No newline at end of file diff --git a/.github/workflows/depoly-production.yml b/.github/workflows/depoly-production.yml index 4280ac64..715585ed 100644 --- a/.github/workflows/depoly-production.yml +++ b/.github/workflows/depoly-production.yml @@ -55,15 +55,14 @@ jobs: - name: Notify Discord on Success if: success() - run: | - curl -H "Content-Type: application/json" \ - -d '{"content": "Production deployment completed successfully!"}' \ - ${{ secrets.DISCORD_WEBHOOK_URL }} - + uses: discord-actions/message@v2 + with: + webhookUrl: ${{ secrets.DISCORD_WEBHOOK_URL }} + message: "Production deployment completed successfully!" - name: Notify Discord on Failure if: failure() - run: | - curl -H "Content-Type: application/json" \ - -d '{"content": "Production deployment failed!"}' \ - ${{ secrets.DISCORD_WEBHOOK_URL }} \ No newline at end of file + uses: discord-actions/message@v2 + with: + webhookUrl: ${{ secrets.DISCORD_WEBHOOK_URL }} + message: "Production deployment failed..." \ No newline at end of file From 9df503e842e7b9cd29c74323261b81fc9305dda3 Mon Sep 17 00:00:00 2001 From: scheduled-for-hacker Date: Sun, 2 Jun 2024 21:56:58 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[bugfix/#286]=20discord=20comment=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-dev.yml | 7 +++++-- .github/workflows/depoly-production.yml | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index cf377ac5..cb7e18f9 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -52,6 +52,9 @@ jobs: docker build -t $IMAGE_NAME . docker run -d --name $CONTAINER_NAME --network host -p 8082:8082 -e SPRING_CONFIG_IMPORT=configserver:http://localhost:8888 $IMAGE_NAME + docker system prune -f + docker buildx prune -f + echo "Deployment done" - name: Notify Discord on Success @@ -59,11 +62,11 @@ jobs: uses: discord-actions/message@v2 with: webhookUrl: ${{ secrets.DISCORD_WEBHOOK_URL }} - message: "Dev deployment completed successfully!" + message: "Backend dev deployment completed successfully!" - name: Notify Discord on Failure if: failure() uses: discord-actions/message@v2 with: webhookUrl: ${{ secrets.DISCORD_WEBHOOK_URL }} - message: "Dev deployment failed..." \ No newline at end of file + message: "Backend dev deployment failed..." \ No newline at end of file diff --git a/.github/workflows/depoly-production.yml b/.github/workflows/depoly-production.yml index 715585ed..454901e7 100644 --- a/.github/workflows/depoly-production.yml +++ b/.github/workflows/depoly-production.yml @@ -58,11 +58,11 @@ jobs: uses: discord-actions/message@v2 with: webhookUrl: ${{ secrets.DISCORD_WEBHOOK_URL }} - message: "Production deployment completed successfully!" + message: "Backend production deployment completed successfully!" - name: Notify Discord on Failure if: failure() uses: discord-actions/message@v2 with: webhookUrl: ${{ secrets.DISCORD_WEBHOOK_URL }} - message: "Production deployment failed..." \ No newline at end of file + message: "Backend production deployment failed..." \ No newline at end of file From 8c5bd39ddfb01ddd04781f98deb4764764c5c244 Mon Sep 17 00:00:00 2001 From: whitemark Date: Fri, 14 Jun 2024 09:15:23 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[feature/#286]=20blue/green=20profiles=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=20controller=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/auth/config/AuthSecurityConfig.java | 2 +- .../inhabas/api/auth/config/CorsConfig.java | 2 +- .../api/auth/config/ProdCorsConfig.java | 2 +- .../java/com/inhabas/api/config/S3Config.java | 2 +- .../com/inhabas/api/config/SwaggerConfig.java | 2 +- .../inhabas/api/config/WebSecurityConfig.java | 2 +- .../api/web/EnvironmentController.java | 43 +++++++++++++++++++ .../ArgumentResolverConfig.java | 2 +- 8 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 resource-server/src/main/java/com/inhabas/api/web/EnvironmentController.java diff --git a/module-auth/src/main/java/com/inhabas/api/auth/config/AuthSecurityConfig.java b/module-auth/src/main/java/com/inhabas/api/auth/config/AuthSecurityConfig.java index 966a8681..4cb67a49 100644 --- a/module-auth/src/main/java/com/inhabas/api/auth/config/AuthSecurityConfig.java +++ b/module-auth/src/main/java/com/inhabas/api/auth/config/AuthSecurityConfig.java @@ -19,7 +19,7 @@ @Order(0) // 인증 관련 security filter chain 은 우선순위가 가장 높아야 함. @EnableWebSecurity @RequiredArgsConstructor -@Profile({"dev", "local", "production"}) // 테스트에는 포함시키지 않음. +@Profile({"dev1", "dev2", "local", "prod1", "prod2"}) // 테스트에는 포함시키지 않음. public class AuthSecurityConfig extends WebSecurityConfigurerAdapter { private final CustomOAuth2UserService customOAuth2UserService; diff --git a/module-auth/src/main/java/com/inhabas/api/auth/config/CorsConfig.java b/module-auth/src/main/java/com/inhabas/api/auth/config/CorsConfig.java index 76cf9936..f7d9caae 100644 --- a/module-auth/src/main/java/com/inhabas/api/auth/config/CorsConfig.java +++ b/module-auth/src/main/java/com/inhabas/api/auth/config/CorsConfig.java @@ -7,7 +7,7 @@ /** 개발 서버에 한해서만 cors 를 적용함. 대신 개발 전용 api 에 대해 높은 수준의 access control 이 보장되어야 함. */ @Configuration -@Profile("dev") +@Profile({"dev1", "dev2"}) public class CorsConfig implements WebMvcConfigurer { @Override diff --git a/module-auth/src/main/java/com/inhabas/api/auth/config/ProdCorsConfig.java b/module-auth/src/main/java/com/inhabas/api/auth/config/ProdCorsConfig.java index 19568b43..7012cf37 100644 --- a/module-auth/src/main/java/com/inhabas/api/auth/config/ProdCorsConfig.java +++ b/module-auth/src/main/java/com/inhabas/api/auth/config/ProdCorsConfig.java @@ -6,7 +6,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration -@Profile("production") +@Profile({"prod1", "prod2"}) public class ProdCorsConfig implements WebMvcConfigurer { @Override diff --git a/module-fileStorage/src/main/java/com/inhabas/api/config/S3Config.java b/module-fileStorage/src/main/java/com/inhabas/api/config/S3Config.java index 1551ccb3..bec75e3d 100644 --- a/module-fileStorage/src/main/java/com/inhabas/api/config/S3Config.java +++ b/module-fileStorage/src/main/java/com/inhabas/api/config/S3Config.java @@ -12,7 +12,7 @@ import com.amazonaws.services.s3.AmazonS3ClientBuilder; @Configuration -@Profile({"dev", "production", "local", "test", "integration_test"}) +@Profile({"dev1", "dev2", "prod1", "prod2", "local", "test", "integration_test"}) public class S3Config { @Value("${cloud.aws.credentials.accessKey}") diff --git a/resource-server/src/main/java/com/inhabas/api/config/SwaggerConfig.java b/resource-server/src/main/java/com/inhabas/api/config/SwaggerConfig.java index c7df315e..664f6878 100644 --- a/resource-server/src/main/java/com/inhabas/api/config/SwaggerConfig.java +++ b/resource-server/src/main/java/com/inhabas/api/config/SwaggerConfig.java @@ -56,7 +56,7 @@ private OpenAPI createOpenAPI( } @Bean - @Profile("dev") + @Profile({"dev1", "dev2"}) public OpenAPI devOpenAPI() { // HTTPS 서버 URL 설정 Server server = new Server().url(DOMAIN); diff --git a/resource-server/src/main/java/com/inhabas/api/config/WebSecurityConfig.java b/resource-server/src/main/java/com/inhabas/api/config/WebSecurityConfig.java index 99341724..9bdbee85 100644 --- a/resource-server/src/main/java/com/inhabas/api/config/WebSecurityConfig.java +++ b/resource-server/src/main/java/com/inhabas/api/config/WebSecurityConfig.java @@ -69,7 +69,7 @@ public class WebSecurityConfig { @EnableGlobalMethodSecurity(prePostEnabled = true, jsr250Enabled = true) @EnableWebSecurity @RequiredArgsConstructor - @Profile({"local", "dev", "default_mvc_test", "production", "integration_test"}) + @Profile({"local", "dev1", "dev2", "default_mvc_test", "prod1", "prod2", "integration_test"}) public static class ApiSecurityForDev extends WebSecurityConfigurerAdapter { private final JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint; diff --git a/resource-server/src/main/java/com/inhabas/api/web/EnvironmentController.java b/resource-server/src/main/java/com/inhabas/api/web/EnvironmentController.java new file mode 100644 index 00000000..30743618 --- /dev/null +++ b/resource-server/src/main/java/com/inhabas/api/web/EnvironmentController.java @@ -0,0 +1,43 @@ +package com.inhabas.api.web; + +import java.util.Arrays; +import java.util.List; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +import org.springframework.core.env.Environment; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@Slf4j +@RestController +@RequiredArgsConstructor +public class EnvironmentController { + + private final Environment environment; + + @GetMapping("/prod/profiles") + public String prodProfile() { + final List profiles = Arrays.asList(environment.getActiveProfiles()); + final List prodProfiles = Arrays.asList("production1", "production2"); + final String defaultProfile = profiles.get(0); + + return Arrays.stream(environment.getActiveProfiles()) + .filter(prodProfiles::contains) + .findAny() + .orElse(defaultProfile); + } + + @GetMapping("/dev/profiles") + public String devProfile() { + final List profiles = Arrays.asList(environment.getActiveProfiles()); + final List prodProfiles = Arrays.asList("dev1", "dev2"); + final String defaultProfile = profiles.get(0); + + return Arrays.stream(environment.getActiveProfiles()) + .filter(prodProfiles::contains) + .findAny() + .orElse(defaultProfile); + } +} diff --git a/resource-server/src/main/java/com/inhabas/api/web/argumentResolver/ArgumentResolverConfig.java b/resource-server/src/main/java/com/inhabas/api/web/argumentResolver/ArgumentResolverConfig.java index 68f89677..a0433f0d 100644 --- a/resource-server/src/main/java/com/inhabas/api/web/argumentResolver/ArgumentResolverConfig.java +++ b/resource-server/src/main/java/com/inhabas/api/web/argumentResolver/ArgumentResolverConfig.java @@ -11,7 +11,7 @@ @Configuration @RequiredArgsConstructor -@Profile({"dev", "production", "local", "integration_test"}) +@Profile({"dev1", "dev2", "prod1", "prod2", "local", "integration_test"}) public class ArgumentResolverConfig implements WebMvcConfigurer { private final LoginMemberArgumentResolver loginMemberArgumentResolver; From 47479350300c229a5a899bba1349fdc5e656fa4a Mon Sep 17 00:00:00 2001 From: whitemark Date: Sat, 15 Jun 2024 23:57:01 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[feature/#286]=20blue/green=20=EB=AC=B4?= =?UTF-8?q?=EC=A4=91=EB=8B=A8=20=EB=B0=B0=ED=8F=AC=20=EC=A0=84=EB=9E=B5=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-dev.yml | 80 ++++++++++++-------------------- 1 file changed, 30 insertions(+), 50 deletions(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index cb7e18f9..4f0aaa0b 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -11,62 +11,42 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout sources + uses: actions/checkout@v4 - - name: executing remote ssh commands using password - uses: appleboy/ssh-action@master + - name: Set up JDK 11 + uses: actions/setup-java@v4 with: - host: ${{ secrets.IBAS_DEV_HOST }} - username: ${{ secrets.IBAS_DEV_USERNAME }} - passphrase: ${{ secrets.IBAS_DEV_PASSWORD }} - key: ${{ secrets.IBAS_DEV_SSH_KEY }} - # port: ${{ secrets.PORT }} # default : 22 - script: | - set -e - REPO_PATH=${{ secrets.IBAS_DEV_PATH }}/Inhabas.com-api - - if [ -d "$REPO_PATH" ]; then - cd $REPO_PATH - git checkout master - git pull - else - echo "Error: Directory $REPO_PATH does not exist." - exit 1 - fi - - chmod u+x gradlew - ./gradlew build -x test - - CONTAINER_NAME=api-dev - IMAGE_NAME=api-dev + java-version: '11' + distribution: 'adopt' - if [ $(docker ps -q -f name=$CONTAINER_NAME) ]; then - docker stop $CONTAINER_NAME - docker rm $CONTAINER_NAME - fi + - name: Setup Gradle + uses: gradle/gradle-build-action@v3 - if [ $(docker images -q $IMAGE_NAME) ]; then - docker rmi $IMAGE_NAME - fi + - name: Grant execute permission for gradlew + run: chmod +x gradlew - docker build -t $IMAGE_NAME . - docker run -d --name $CONTAINER_NAME --network host -p 8082:8082 -e SPRING_CONFIG_IMPORT=configserver:http://localhost:8888 $IMAGE_NAME - - docker system prune -f - docker buildx prune -f - - echo "Deployment done" + - name: Build with Gradle + run: ./gradlew build - - name: Notify Discord on Success - if: success() - uses: discord-actions/message@v2 + - name: copy file via ssh + uses: appleboy/scp-action@master with: - webhookUrl: ${{ secrets.DISCORD_WEBHOOK_URL }} - message: "Backend dev deployment completed successfully!" + host: ${{ secrets.IBAS_DEV_HOST }} + username: ${{ secrets.IBAS_DEV_USERNAME }} + key: ${{ secrets.IBAS_DEV_SSH_KEY }} + passphrase: ${{ secrets.IBAS_DEV_PASSWORD }} + # port: ${{ secrets.PORT }} # default : 22 + source: "resource-server/build/libs/resource-server-0.0.1-SNAPSHOT.jar" + target: ${{ secrets.IBAS_DEV_DEPLOY_PATH }} - - name: Notify Discord on Failure - if: failure() - uses: discord-actions/message@v2 + - name: execute deploy shell script via ssh + uses: appleboy/ssh-action@master with: - webhookUrl: ${{ secrets.DISCORD_WEBHOOK_URL }} - message: "Backend dev deployment failed..." \ No newline at end of file + host: ${{ secrets.IBAS_DEV_HOST }} + username: ${{ secrets.IBAS_DEV_USERNAME }} + key: ${{ secrets.IBAS_DEV_SSH_KEY }} + passphrase: ${{ secrets.IBAS_DEV_PASSWORD }} + # port: ${{ secrets.PORT }} # default : 22 + script: | + bash ${{ secrets.IBAS_DEV_DEPLOY_PATH }}/deploy.sh