diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index e0926b19..4f0aaa0b 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -11,61 +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: + java-version: '11' + distribution: 'adopt' + + - name: Setup Gradle + uses: gradle/gradle-build-action@v3 + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew build + + - name: copy file via ssh + uses: appleboy/scp-action@master with: 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: execute deploy shell script via ssh + uses: appleboy/ssh-action@master + with: + 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: | - set -e - REPO_PATH=${{ secrets.IBAS_DEV_PATH }}/Inhabas.com-api - - if [ -d "$REPO_PATH" ]; then - cd $REPO_PATH - git checkout dev - 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 - - if [ $(docker ps -q -f name=$CONTAINER_NAME) ]; then - docker stop $CONTAINER_NAME - docker rm $CONTAINER_NAME - fi - - if [ $(docker images -q $IMAGE_NAME) ]; then - docker rmi $IMAGE_NAME - fi - - 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 - - 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 }} - - - - 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 + bash ${{ secrets.IBAS_DEV_DEPLOY_PATH }}/deploy.sh diff --git a/.github/workflows/depoly-production.yml b/.github/workflows/depoly-production.yml index 4280ac64..454901e7 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: "Backend 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: "Backend production deployment failed..." \ No newline at end of file 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;