Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] 새로운 AWS 계정에서 Prod 환경 CI/CD 구축 #418

Merged
merged 10 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사소한 의견) Linux랑 X64까지 표기해줬으면 좋겠어요~
환경까지 구분 명확히 해주면 좋을 것 같아서요~ 저는 dev, X64, Linux 로 해뒀어용

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

./.github/workflows/blue-green.yml에 값을 넘겨 주어 사용하는 것이다 보니, 환경까지 넘겨주기에는 최적화 되어있지 않네요;;

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}
Comment on lines +5 to +8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

내 소중한 작업이ㅠㅠㅠ


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

properties:
hibernate:
jdbc:
Expand Down