From 0064d398c79459971e0dad30c1c40c3b1c348f61 Mon Sep 17 00:00:00 2001 From: leegwichan Date: Wed, 27 Nov 2024 18:02:28 +0900 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20CD=20=EC=8A=A4=ED=81=AC=EB=A6=BD?= =?UTF-8?q?=ED=8A=B8=20=EB=B3=80=EA=B2=BD=20v.01=20#415?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/be-cd-prod.yml | 103 +++++++++---------------------- 1 file changed, 28 insertions(+), 75 deletions(-) diff --git a/.github/workflows/be-cd-prod.yml b/.github/workflows/be-cd-prod.yml index 033d0e9f7..688130b48 100644 --- a/.github/workflows/be-cd-prod.yml +++ b/.github/workflows/be-cd-prod.yml @@ -16,114 +16,67 @@ jobs: secrets: secret_yml: ${{ secrets.PROD_SECRET_YML }} - deploy-a: + deploy: needs: [ build ] uses: ./.github/workflows/blue-green.yml with: - self_hosted_runner: prod-a + self_hosted_runner: prod artifact_name: ${{ needs.build.outputs.artifact_name }} jar_name: ${{ needs.build.outputs.jar_name }} profile: prod app_path: ~/app - deploy-b: - needs: [ build ] - uses: ./.github/workflows/blue-green.yml - with: - self_hosted_runner: prod-b - artifact_name: ${{ needs.build.outputs.artifact_name }} - jar_name: ${{ needs.build.outputs.jar_name }} - profile: prod - app_path: ~/app - - rollback-a: - name: "[Failure] Rollback Deploy A" - needs: [ deploy-a, deploy-b ] - if: failure() && (needs.deploy-a.result == 'failure' || needs.deploy-b.result == 'failure') - uses: ./.github/workflows/shutdown.yml - with: - self_hosted_runner: prod-a - port: ${{ needs.deploy-a.outputs.green_port }} - - rollback-b: - name: "[Failure] Rollback Deploy B" - needs: [ deploy-a, deploy-b ] - if: failure() && (needs.deploy-a.result == 'failure' || needs.deploy-b.result == 'failure') + rollback: + name: "[Failure] Rollback Deploy" + needs: deploy + if: failure() && needs.deploy.result == 'failure' uses: ./.github/workflows/shutdown.yml with: - self_hosted_runner: prod-b - port: ${{ needs.deploy-b.outputs.green_port }} + self_hosted_runner: prod + port: ${{ needs.deploy.outputs.green_port }} deploy-failure-notification: name: "[Failure] Deploy Failure Notification" - needs: [ deploy-a, deploy-b ] - if: failure() && (needs.deploy-a.result == 'failure' || needs.deploy-b.result == 'failure') + needs: deploy + if: failure() && needs.deploy.result == 'failure' runs-on: ubuntu-latest steps: - name: Send notification to Discord # todo run: echo "테스트입니다" - configure-nginx-a: - needs: [ deploy-a, deploy-b ] + configure-nginx: + needs: deploy uses: ./.github/workflows/nginx-port-forwarding.yml with: - self_hosted_runner: prod-a + self_hosted_runner: prod app_path: ~/app - old_port: ${{ needs.deploy-a.outputs.blue_port }} - new_port: ${{ needs.deploy-a.outputs.green_port }} + old_port: ${{ needs.deploy.outputs.blue_port }} + new_port: ${{ needs.deploy.outputs.green_port }} - configure-nginx-b: - needs: [ deploy-a, deploy-b ] + rollback-nginx: + name: "[Failure] Rollback Nginx" + needs: configure-nginx + if: failure() && (needs.configure-nginx.result == 'failure') uses: ./.github/workflows/nginx-port-forwarding.yml with: - self_hosted_runner: prod-b + self_hosted_runner: prod app_path: ~/app - old_port: ${{ needs.deploy-b.outputs.blue_port }} - new_port: ${{ needs.deploy-b.outputs.green_port }} - - rollback-nginx-a: - name: "[Failure] Rollback Nginx A" - needs: [ configure-nginx-a, configure-nginx-b ] - if: failure() && (needs.configure-nginx-a.result == 'failure' || needs.configure-nginx-b.result == 'failure') - uses: ./.github/workflows/nginx-port-forwarding.yml - with: - self_hosted_runner: prod-a - app_path: ~/app - old_port: ${{ needs.configure-nginx-a.outputs.new_port }} - new_port: ${{ needs.configure-nginx-a.outputs.old_port }} - old_shutdown: true - - rollback-nginx-b: - name: "[Failure] Rollback Nginx B" - needs: [ configure-nginx-a, configure-nginx-b ] - if: failure() && (needs.configure-nginx-a.result == 'failure' || needs.configure-nginx-b.result == 'failure') - uses: ./.github/workflows/nginx-port-forwarding.yml - with: - self_hosted_runner: prod-b - app_path: ~/app - old_port: ${{ needs.configure-nginx-b.outputs.new_port }} - new_port: ${{ needs.configure-nginx-b.outputs.old_port }} + old_port: ${{ needs.configure-nginx.outputs.new_port }} + new_port: ${{ needs.configure-nginx.outputs.old_port }} old_shutdown: true configure-nginx-faliure-notification: name: "[Failure] Nginx Failure Notification" - needs: [ configure-nginx-a, configure-nginx-b ] - if: failure() && (needs.configure-nginx-a.result == 'failure' || needs.configure-nginx-b.result == 'failure') + needs: configure-nginx + if: failure() && needs.configure-nginx.result == 'failure' runs-on: ubuntu-latest steps: - name: Send notification to Discord # todo run: echo "테스트입니다" - blue-shutdown-a: - needs: [ configure-nginx-a, configure-nginx-b ] - uses: ./.github/workflows/shutdown.yml - with: - self_hosted_runner: prod-a - port: ${{ needs.configure-nginx-a.outputs.old_port }} - - blue-shutdown-b: - needs: [ configure-nginx-a, configure-nginx-b ] + blue-shutdown: + needs: configure-nginx uses: ./.github/workflows/shutdown.yml with: - self_hosted_runner: prod-b - port: ${{ needs.configure-nginx-b.outputs.old_port }} + self_hosted_runner: prod + port: ${{ needs.configure-nginx.outputs.old_port }} From 0055481618a3c5612922f816ff296acc3d2f101c Mon Sep 17 00:00:00 2001 From: leegwichan Date: Wed, 27 Nov 2024 18:14:52 +0900 Subject: [PATCH 2/9] =?UTF-8?q?fix:=20=EA=B8=B8=EC=96=B4=EC=A7=84=20?= =?UTF-8?q?=EC=8B=A4=ED=96=89=20=EC=8B=9C=EA=B0=84=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=95=B4=20=ED=97=AC=EC=8A=A4=20=EC=B2=B4=ED=81=AC=20?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=EC=9D=84=20=EC=A6=9D=EA=B0=80=ED=95=A8=20#41?= =?UTF-8?q?5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/scripts/green_health_check.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/scripts/green_health_check.sh b/backend/scripts/green_health_check.sh index d040ebc07..0be85a238 100755 --- a/backend/scripts/green_health_check.sh +++ b/backend/scripts/green_health_check.sh @@ -3,7 +3,7 @@ GREEN_PORT=$1 health_check_process() { - # 헬스 체크를 최대 5번 시도 (3초 간격) + # 헬스 체크를 최대 5번 시도 (15초 간격) for i in $(seq 1 5); do check_health if [ $? -eq 0 ]; then @@ -11,7 +11,7 @@ health_check_process() { return 0 fi echo "Waiting 3 seconds before next check..." - sleep 3 + sleep 15 done # 5번 시도 후에도 실패하면 종료 From b13d34c9d8aabbb9937107f48733a2dfa512c9fb Mon Sep 17 00:00:00 2001 From: leegwichan Date: Wed, 27 Nov 2024 18:37:09 +0900 Subject: [PATCH 3/9] =?UTF-8?q?feat:=20=EB=B3=80=EA=B2=BD=EB=90=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=94=84=EB=9D=BC=EC=97=90=20=EB=A7=9E=EC=B6=94?= =?UTF-8?q?=EC=96=B4=20Replication=20=EC=BD=94=EB=93=9C=20=EB=B9=84?= =?UTF-8?q?=ED=99=9C=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/ddangkong/config/sql/DataSourceConfig.java | 2 +- backend/src/main/resources/application-prod.yml | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/ddangkong/config/sql/DataSourceConfig.java b/backend/src/main/java/ddangkong/config/sql/DataSourceConfig.java index 9c4a29d78..8656ec257 100644 --- a/backend/src/main/java/ddangkong/config/sql/DataSourceConfig.java +++ b/backend/src/main/java/ddangkong/config/sql/DataSourceConfig.java @@ -12,7 +12,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy; -@Profile("prod") +@Profile("inactive") @Configuration public class DataSourceConfig { diff --git a/backend/src/main/resources/application-prod.yml b/backend/src/main/resources/application-prod.yml index 57effdc74..8dd96fd0e 100644 --- a/backend/src/main/resources/application-prod.yml +++ b/backend/src/main/resources/application-prod.yml @@ -13,6 +13,11 @@ spring: password: ${secret.datasource.replica.password} jdbc-url: jdbc:mysql://${secret.datasource.replica.host}:${secret.datasource.replica.port}/${secret.datasource.database}?serverTimezone=Asia/Seoul&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&useSSL=false + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://${secret.datasource.host}:${secret.datasource.port}/${secret.datasource.database}?useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true&autoReconnect=true&serverTimezone=Asia/Seoul&useLegacyDatetimeCode=false + username: ${secret.datasource.username} + password: ${secret.datasource.password} + sql: init: mode: never From 267c715acd293828396007e86298f1c133524698 Mon Sep 17 00:00:00 2001 From: leegwichan Date: Wed, 27 Nov 2024 18:54:44 +0900 Subject: [PATCH 4/9] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EB=B0=8F?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/scripts/green_health_check.sh | 6 +-- .../config/sql/DataSourceConfig.java | 54 ------------------- .../config/sql/RoutingDataSource.java | 18 ------- .../config/sql/type/DataSourceType.java | 7 --- .../src/main/resources/application-prod.yml | 13 +---- 5 files changed, 4 insertions(+), 94 deletions(-) delete mode 100644 backend/src/main/java/ddangkong/config/sql/DataSourceConfig.java delete mode 100644 backend/src/main/java/ddangkong/config/sql/RoutingDataSource.java delete mode 100644 backend/src/main/java/ddangkong/config/sql/type/DataSourceType.java diff --git a/backend/scripts/green_health_check.sh b/backend/scripts/green_health_check.sh index 0be85a238..cdb0d0ffa 100755 --- a/backend/scripts/green_health_check.sh +++ b/backend/scripts/green_health_check.sh @@ -3,15 +3,15 @@ GREEN_PORT=$1 health_check_process() { - # 헬스 체크를 최대 5번 시도 (15초 간격) + # 헬스 체크를 최대 5번 시도 (10초 간격) for i in $(seq 1 5); do check_health if [ $? -eq 0 ]; then echo "Health check passed on attempt $i." return 0 fi - echo "Waiting 3 seconds before next check..." - sleep 15 + echo "Waiting 10 seconds before next check..." + sleep 10 done # 5번 시도 후에도 실패하면 종료 diff --git a/backend/src/main/java/ddangkong/config/sql/DataSourceConfig.java b/backend/src/main/java/ddangkong/config/sql/DataSourceConfig.java deleted file mode 100644 index 8656ec257..000000000 --- a/backend/src/main/java/ddangkong/config/sql/DataSourceConfig.java +++ /dev/null @@ -1,54 +0,0 @@ -package ddangkong.config.sql; - -import ddangkong.config.sql.type.DataSourceType; -import java.util.HashMap; -import java.util.Map; -import javax.sql.DataSource; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.jdbc.DataSourceBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.context.annotation.Profile; -import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy; - -@Profile("inactive") -@Configuration -public class DataSourceConfig { - - @Bean - @ConfigurationProperties(prefix = "spring.datasource.source") - public DataSource sourceDataSource() { - return DataSourceBuilder.create() - .build(); - } - - @Bean - @ConfigurationProperties(prefix = "spring.datasource.replica") - public DataSource replicaDataSource() { - return DataSourceBuilder.create() - .build(); - } - - @Bean - public DataSource routingDataSource( - DataSource sourceDataSource, - DataSource replicaDataSource - ) { - Map dataSources = new HashMap<>(); - dataSources.put(DataSourceType.SOURCE, sourceDataSource); - dataSources.put(DataSourceType.REPLICA, replicaDataSource); - - RoutingDataSource routingDataSource = new RoutingDataSource(); - routingDataSource.setDefaultTargetDataSource(dataSources.get(DataSourceType.SOURCE)); - routingDataSource.setTargetDataSources(dataSources); - - return routingDataSource; - } - - @Primary - @Bean - public DataSource dataSource() { - return new LazyConnectionDataSourceProxy(routingDataSource(sourceDataSource(), replicaDataSource())); - } -} diff --git a/backend/src/main/java/ddangkong/config/sql/RoutingDataSource.java b/backend/src/main/java/ddangkong/config/sql/RoutingDataSource.java deleted file mode 100644 index 8a73602c0..000000000 --- a/backend/src/main/java/ddangkong/config/sql/RoutingDataSource.java +++ /dev/null @@ -1,18 +0,0 @@ -package ddangkong.config.sql; - -import ddangkong.config.sql.type.DataSourceType; -import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; -import org.springframework.transaction.support.TransactionSynchronizationManager; - -public class RoutingDataSource extends AbstractRoutingDataSource { - - @Override - protected Object determineCurrentLookupKey() { - boolean isReadOnly = TransactionSynchronizationManager.isCurrentTransactionReadOnly(); - if (isReadOnly) { - return DataSourceType.REPLICA; - } else { - return DataSourceType.SOURCE; - } - } -} diff --git a/backend/src/main/java/ddangkong/config/sql/type/DataSourceType.java b/backend/src/main/java/ddangkong/config/sql/type/DataSourceType.java deleted file mode 100644 index c46a4a559..000000000 --- a/backend/src/main/java/ddangkong/config/sql/type/DataSourceType.java +++ /dev/null @@ -1,7 +0,0 @@ -package ddangkong.config.sql.type; - -public enum DataSourceType { - SOURCE, - REPLICA, - ; -} diff --git a/backend/src/main/resources/application-prod.yml b/backend/src/main/resources/application-prod.yml index 8dd96fd0e..cb8e17aa6 100644 --- a/backend/src/main/resources/application-prod.yml +++ b/backend/src/main/resources/application-prod.yml @@ -2,17 +2,6 @@ spring: config: import: prod-secret.yml datasource: - source: - driver-class-name: com.mysql.cj.jdbc.Driver - username: ${secret.datasource.source.username} - password: ${secret.datasource.source.password} - jdbc-url: jdbc:mysql://${secret.datasource.source.host}:${secret.datasource.source.port}/${secret.datasource.database}?serverTimezone=Asia/Seoul&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&useSSL=false - replica: - driver-class-name: com.mysql.cj.jdbc.Driver - username: ${secret.datasource.replica.username} - password: ${secret.datasource.replica.password} - jdbc-url: jdbc:mysql://${secret.datasource.replica.host}:${secret.datasource.replica.port}/${secret.datasource.database}?serverTimezone=Asia/Seoul&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&useSSL=false - driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://${secret.datasource.host}:${secret.datasource.port}/${secret.datasource.database}?useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true&autoReconnect=true&serverTimezone=Asia/Seoul&useLegacyDatetimeCode=false username: ${secret.datasource.username} @@ -25,7 +14,7 @@ spring: jpa: database-platform: org.hibernate.dialect.MySQLDialect hibernate: - ddl-auto: none + ddl-auto: validate properties: hibernate: jdbc: From a7c71f4e7c85ae07e89c755276f175801fcd01f5 Mon Sep 17 00:00:00 2001 From: leegwichan Date: Wed, 27 Nov 2024 18:14:52 +0900 Subject: [PATCH 5/9] =?UTF-8?q?fix:=20=EA=B8=B8=EC=96=B4=EC=A7=84=20?= =?UTF-8?q?=EC=8B=A4=ED=96=89=20=EC=8B=9C=EA=B0=84=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=95=B4=20=ED=97=AC=EC=8A=A4=20=EC=B2=B4=ED=81=AC=20?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=EC=9D=84=20=EC=A6=9D=EA=B0=80=ED=95=A8=20#41?= =?UTF-8?q?5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/scripts/green_health_check.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/scripts/green_health_check.sh b/backend/scripts/green_health_check.sh index d040ebc07..0be85a238 100755 --- a/backend/scripts/green_health_check.sh +++ b/backend/scripts/green_health_check.sh @@ -3,7 +3,7 @@ GREEN_PORT=$1 health_check_process() { - # 헬스 체크를 최대 5번 시도 (3초 간격) + # 헬스 체크를 최대 5번 시도 (15초 간격) for i in $(seq 1 5); do check_health if [ $? -eq 0 ]; then @@ -11,7 +11,7 @@ health_check_process() { return 0 fi echo "Waiting 3 seconds before next check..." - sleep 3 + sleep 15 done # 5번 시도 후에도 실패하면 종료 From 02506c3f5242b87fb3b1c2c73d970a25f56acaef Mon Sep 17 00:00:00 2001 From: leegwichan Date: Wed, 27 Nov 2024 18:37:09 +0900 Subject: [PATCH 6/9] =?UTF-8?q?feat:=20=EB=B3=80=EA=B2=BD=EB=90=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=94=84=EB=9D=BC=EC=97=90=20=EB=A7=9E=EC=B6=94?= =?UTF-8?q?=EC=96=B4=20Replication=20=EC=BD=94=EB=93=9C=20=EB=B9=84?= =?UTF-8?q?=ED=99=9C=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/ddangkong/config/sql/DataSourceConfig.java | 2 +- backend/src/main/resources/application-prod.yml | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/ddangkong/config/sql/DataSourceConfig.java b/backend/src/main/java/ddangkong/config/sql/DataSourceConfig.java index 9c4a29d78..8656ec257 100644 --- a/backend/src/main/java/ddangkong/config/sql/DataSourceConfig.java +++ b/backend/src/main/java/ddangkong/config/sql/DataSourceConfig.java @@ -12,7 +12,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy; -@Profile("prod") +@Profile("inactive") @Configuration public class DataSourceConfig { diff --git a/backend/src/main/resources/application-prod.yml b/backend/src/main/resources/application-prod.yml index 57effdc74..8dd96fd0e 100644 --- a/backend/src/main/resources/application-prod.yml +++ b/backend/src/main/resources/application-prod.yml @@ -13,6 +13,11 @@ spring: password: ${secret.datasource.replica.password} jdbc-url: jdbc:mysql://${secret.datasource.replica.host}:${secret.datasource.replica.port}/${secret.datasource.database}?serverTimezone=Asia/Seoul&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&useSSL=false + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://${secret.datasource.host}:${secret.datasource.port}/${secret.datasource.database}?useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true&autoReconnect=true&serverTimezone=Asia/Seoul&useLegacyDatetimeCode=false + username: ${secret.datasource.username} + password: ${secret.datasource.password} + sql: init: mode: never From 8ef4305c081160f98d272b1b4031b8330a9b3347 Mon Sep 17 00:00:00 2001 From: leegwichan Date: Wed, 27 Nov 2024 18:54:44 +0900 Subject: [PATCH 7/9] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EB=B0=8F?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/scripts/green_health_check.sh | 6 +-- .../config/sql/DataSourceConfig.java | 54 ------------------- .../config/sql/RoutingDataSource.java | 18 ------- .../config/sql/type/DataSourceType.java | 7 --- .../src/main/resources/application-prod.yml | 13 +---- 5 files changed, 4 insertions(+), 94 deletions(-) delete mode 100644 backend/src/main/java/ddangkong/config/sql/DataSourceConfig.java delete mode 100644 backend/src/main/java/ddangkong/config/sql/RoutingDataSource.java delete mode 100644 backend/src/main/java/ddangkong/config/sql/type/DataSourceType.java diff --git a/backend/scripts/green_health_check.sh b/backend/scripts/green_health_check.sh index 0be85a238..cdb0d0ffa 100755 --- a/backend/scripts/green_health_check.sh +++ b/backend/scripts/green_health_check.sh @@ -3,15 +3,15 @@ GREEN_PORT=$1 health_check_process() { - # 헬스 체크를 최대 5번 시도 (15초 간격) + # 헬스 체크를 최대 5번 시도 (10초 간격) for i in $(seq 1 5); do check_health if [ $? -eq 0 ]; then echo "Health check passed on attempt $i." return 0 fi - echo "Waiting 3 seconds before next check..." - sleep 15 + echo "Waiting 10 seconds before next check..." + sleep 10 done # 5번 시도 후에도 실패하면 종료 diff --git a/backend/src/main/java/ddangkong/config/sql/DataSourceConfig.java b/backend/src/main/java/ddangkong/config/sql/DataSourceConfig.java deleted file mode 100644 index 8656ec257..000000000 --- a/backend/src/main/java/ddangkong/config/sql/DataSourceConfig.java +++ /dev/null @@ -1,54 +0,0 @@ -package ddangkong.config.sql; - -import ddangkong.config.sql.type.DataSourceType; -import java.util.HashMap; -import java.util.Map; -import javax.sql.DataSource; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.jdbc.DataSourceBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.context.annotation.Profile; -import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy; - -@Profile("inactive") -@Configuration -public class DataSourceConfig { - - @Bean - @ConfigurationProperties(prefix = "spring.datasource.source") - public DataSource sourceDataSource() { - return DataSourceBuilder.create() - .build(); - } - - @Bean - @ConfigurationProperties(prefix = "spring.datasource.replica") - public DataSource replicaDataSource() { - return DataSourceBuilder.create() - .build(); - } - - @Bean - public DataSource routingDataSource( - DataSource sourceDataSource, - DataSource replicaDataSource - ) { - Map dataSources = new HashMap<>(); - dataSources.put(DataSourceType.SOURCE, sourceDataSource); - dataSources.put(DataSourceType.REPLICA, replicaDataSource); - - RoutingDataSource routingDataSource = new RoutingDataSource(); - routingDataSource.setDefaultTargetDataSource(dataSources.get(DataSourceType.SOURCE)); - routingDataSource.setTargetDataSources(dataSources); - - return routingDataSource; - } - - @Primary - @Bean - public DataSource dataSource() { - return new LazyConnectionDataSourceProxy(routingDataSource(sourceDataSource(), replicaDataSource())); - } -} diff --git a/backend/src/main/java/ddangkong/config/sql/RoutingDataSource.java b/backend/src/main/java/ddangkong/config/sql/RoutingDataSource.java deleted file mode 100644 index 8a73602c0..000000000 --- a/backend/src/main/java/ddangkong/config/sql/RoutingDataSource.java +++ /dev/null @@ -1,18 +0,0 @@ -package ddangkong.config.sql; - -import ddangkong.config.sql.type.DataSourceType; -import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; -import org.springframework.transaction.support.TransactionSynchronizationManager; - -public class RoutingDataSource extends AbstractRoutingDataSource { - - @Override - protected Object determineCurrentLookupKey() { - boolean isReadOnly = TransactionSynchronizationManager.isCurrentTransactionReadOnly(); - if (isReadOnly) { - return DataSourceType.REPLICA; - } else { - return DataSourceType.SOURCE; - } - } -} diff --git a/backend/src/main/java/ddangkong/config/sql/type/DataSourceType.java b/backend/src/main/java/ddangkong/config/sql/type/DataSourceType.java deleted file mode 100644 index c46a4a559..000000000 --- a/backend/src/main/java/ddangkong/config/sql/type/DataSourceType.java +++ /dev/null @@ -1,7 +0,0 @@ -package ddangkong.config.sql.type; - -public enum DataSourceType { - SOURCE, - REPLICA, - ; -} diff --git a/backend/src/main/resources/application-prod.yml b/backend/src/main/resources/application-prod.yml index 8dd96fd0e..cb8e17aa6 100644 --- a/backend/src/main/resources/application-prod.yml +++ b/backend/src/main/resources/application-prod.yml @@ -2,17 +2,6 @@ spring: config: import: prod-secret.yml datasource: - source: - driver-class-name: com.mysql.cj.jdbc.Driver - username: ${secret.datasource.source.username} - password: ${secret.datasource.source.password} - jdbc-url: jdbc:mysql://${secret.datasource.source.host}:${secret.datasource.source.port}/${secret.datasource.database}?serverTimezone=Asia/Seoul&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&useSSL=false - replica: - driver-class-name: com.mysql.cj.jdbc.Driver - username: ${secret.datasource.replica.username} - password: ${secret.datasource.replica.password} - jdbc-url: jdbc:mysql://${secret.datasource.replica.host}:${secret.datasource.replica.port}/${secret.datasource.database}?serverTimezone=Asia/Seoul&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&useSSL=false - driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://${secret.datasource.host}:${secret.datasource.port}/${secret.datasource.database}?useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true&autoReconnect=true&serverTimezone=Asia/Seoul&useLegacyDatetimeCode=false username: ${secret.datasource.username} @@ -25,7 +14,7 @@ spring: jpa: database-platform: org.hibernate.dialect.MySQLDialect hibernate: - ddl-auto: none + ddl-auto: validate properties: hibernate: jdbc: From 9b7442fb0ebf4a71c93dd163267a6803a2615ab6 Mon Sep 17 00:00:00 2001 From: leegwichan Date: Wed, 27 Nov 2024 19:04:49 +0900 Subject: [PATCH 8/9] =?UTF-8?q?fix:=20=EA=B8=B8=EC=96=B4=EC=A7=84=20?= =?UTF-8?q?=EC=8B=A4=ED=96=89=20=EC=8B=9C=EA=B0=84=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=95=B4=20=ED=97=AC=EC=8A=A4=20=EC=B2=B4=ED=81=AC=20?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=EC=9D=84=20=EC=A6=9D=EA=B0=80=ED=95=A8=20v2?= =?UTF-8?q?=20#415?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/scripts/green_health_check.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/scripts/green_health_check.sh b/backend/scripts/green_health_check.sh index cdb0d0ffa..80b57b1fa 100755 --- a/backend/scripts/green_health_check.sh +++ b/backend/scripts/green_health_check.sh @@ -3,15 +3,15 @@ GREEN_PORT=$1 health_check_process() { - # 헬스 체크를 최대 5번 시도 (10초 간격) + # 헬스 체크를 최대 5번 시도 (5초 간격) for i in $(seq 1 5); do check_health if [ $? -eq 0 ]; then echo "Health check passed on attempt $i." return 0 fi - echo "Waiting 10 seconds before next check..." - sleep 10 + echo "Waiting 5 seconds before next check..." + sleep 5 done # 5번 시도 후에도 실패하면 종료 From 056ce941b240d533520e61d718f4b95a221b7282 Mon Sep 17 00:00:00 2001 From: leegwichan Date: Thu, 28 Nov 2024 15:25:00 +0900 Subject: [PATCH 9/9] =?UTF-8?q?refactor:=20=EC=89=98=20=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A6=BD=ED=8A=B8=EB=A5=BC=20=ED=99=98=EA=B2=BD=EC=9D=84=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC=ED=95=98=EC=97=AC=20=EA=B4=80=EB=A6=AC=20#41?= =?UTF-8?q?5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 2 +- backend/scripts/{ => prod}/change_nginx_port_forwarding.sh | 0 backend/scripts/{ => prod}/get_blue_green_port.sh | 0 backend/scripts/{ => prod}/green_health_check.sh | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename backend/scripts/{ => prod}/change_nginx_port_forwarding.sh (100%) mode change 100755 => 100644 rename backend/scripts/{ => prod}/get_blue_green_port.sh (100%) mode change 100755 => 100644 rename backend/scripts/{ => prod}/green_health_check.sh (100%) mode change 100755 => 100644 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2d5ebb699..47b418bfd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -59,7 +59,7 @@ jobs: run: | mkdir -p ${{ inputs.artifact_name }} && \ mv build/libs/*.jar ${{ inputs.artifact_name }}/${{ inputs.jar_name }} && \ - mv scripts/* ${{ inputs.artifact_name }}/ + mv scripts/${{ inputs.profile }}/* ${{ inputs.artifact_name }}/ - name: Upload artifact file uses: actions/upload-artifact@v4 diff --git a/backend/scripts/change_nginx_port_forwarding.sh b/backend/scripts/prod/change_nginx_port_forwarding.sh old mode 100755 new mode 100644 similarity index 100% rename from backend/scripts/change_nginx_port_forwarding.sh rename to backend/scripts/prod/change_nginx_port_forwarding.sh diff --git a/backend/scripts/get_blue_green_port.sh b/backend/scripts/prod/get_blue_green_port.sh old mode 100755 new mode 100644 similarity index 100% rename from backend/scripts/get_blue_green_port.sh rename to backend/scripts/prod/get_blue_green_port.sh diff --git a/backend/scripts/green_health_check.sh b/backend/scripts/prod/green_health_check.sh old mode 100755 new mode 100644 similarity index 100% rename from backend/scripts/green_health_check.sh rename to backend/scripts/prod/green_health_check.sh