Skip to content

Commit

Permalink
merge: [FEAT] 새로운 AWS 계정에서 Prod 환경 CI/CD 구축 #415
Browse files Browse the repository at this point in the history
  • Loading branch information
leegwichan authored Nov 28, 2024
2 parents f41d55e + 056ce94 commit b998bdd
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 169 deletions.
103 changes: 28 additions & 75 deletions .github/workflows/be-cd-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions backend/scripts/green_health_check.sh → backend/scripts/prod/green_health_check.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
GREEN_PORT=$1

health_check_process() {
# 헬스 체크를 최대 5번 시도 (3초 간격)
# 헬스 체크를 최대 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 3 seconds before next check..."
sleep 3
echo "Waiting 5 seconds before next check..."
sleep 5
done

# 5번 시도 후에도 실패하면 종료
Expand Down
54 changes: 0 additions & 54 deletions backend/src/main/java/ddangkong/config/sql/DataSourceConfig.java

This file was deleted.

18 changes: 0 additions & 18 deletions backend/src/main/java/ddangkong/config/sql/RoutingDataSource.java

This file was deleted.

This file was deleted.

16 changes: 5 additions & 11 deletions backend/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ 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}
password: ${secret.datasource.password}

sql:
init:
Expand All @@ -20,7 +14,7 @@ spring:
jpa:
database-platform: org.hibernate.dialect.MySQLDialect
hibernate:
ddl-auto: none
ddl-auto: validate
properties:
hibernate:
jdbc:
Expand Down

0 comments on commit b998bdd

Please sign in to comment.