Skip to content

Commit

Permalink
chore: 운영 서버 마이그레이션 작업 및 DB 데이터 이동 (#924)
Browse files Browse the repository at this point in the history
* chore: prod datasource 설정 변경

* chore: prod v2 cd 스크립트 추가

* chore: dockerfile default profile 변경

* fix: prod datasource 암호문 변경

* chore: prod v2 트리거 수정

* chore: prod v2 스크립트 jasypt 변경

* chore: prod v2 TZ 추가

* chore: prod v2 롤백 작업 추가

* style: 개행 제거

* chore: cd prod v2 트리거 브랜치 main으로 수정
  • Loading branch information
eun-byeol committed Jan 3, 2025
1 parent f34aae2 commit 8ac539f
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 8 deletions.
125 changes: 125 additions & 0 deletions .github/workflows/backend-cd-prod-v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: backend-cd-prod-v2

on:
pull_request:
branches:
- main
types:
- closed

env:
DOCKERHUB_REPOSITORY: ody-official

jobs:
build-and-push:
if: github.event.pull_request.merged == true && (startsWith(github.event.pull_request.head.ref, 'release-be/') || startsWith(github.event.pull_request.head.ref, 'hotfix-be/'))

runs-on: ubuntu-latest
env:
TZ: 'Asia/Seoul'

defaults:
run:
working-directory: backend

steps:
- uses: actions/checkout@v4
with:
ref: main

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Check system timezone
run: |
echo "Current date and time: $(date)"
echo "TZ environment variable: $TZ"
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Clean Build With Gradle Wrapper
run: ./gradlew clean build

- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: ${{ github.workspace }}/backend/build/test-results/**/*.xml

- name: JUnit Report Action
uses: mikepenz/action-junit-report@v4
if: always()
with:
report_paths: ${{ github.workspace }}/backend/build/test-results/**/*.xml

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Back Up Image For Rollback
run: |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/$DOCKERHUB_REPOSITORY:prod-latest || true
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/$DOCKERHUB_REPOSITORY:prod-latest ${{ secrets.DOCKERHUB_USERNAME }}/$DOCKERHUB_REPOSITORY:prod-previous || true
docker push ${{ secrets.DOCKERHUB_USERNAME }}/$DOCKERHUB_REPOSITORY:prod-previous || true
- name: Docker Image Build And Push
run: docker build --platform linux/arm64 -t ${{ secrets.DOCKERHUB_USERNAME }}/$DOCKERHUB_REPOSITORY:${{ github.sha }}-prod_v2 -f Dockerfile . --push

pull-and-deploy:
needs: build-and-push
runs-on: prod
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Clean Up Legacy Image
run: |
docker compose down || true
docker rmi $(docker images -q) -f || true
- name: Docker Compose up
run: |
export DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
export DOCKERHUB_REPOSITORY=$DOCKERHUB_REPOSITORY
export PROD_MYSQL_PASSWORD=${{ secrets.PROD_MYSQL_PASSWORD }}
export JASYPT_ENCRYPTOR_PASSWORD=${{ secrets.JASYPT_PASSWORD }}
export TAG=${{ github.sha }}-prod_v2
docker compose up -d
#TODO: 도메인 연결 시, health check 필요

- name: Rollback if Health Check fails
if: failure()
run: |
docker compose down || true
docker rmi $(docker images -q) -f || true
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/$DOCKERHUB_REPOSITORY:prod-previous
export DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
export DOCKERHUB_REPOSITORY=$DOCKERHUB_REPOSITORY
export PROD_MYSQL_PASSWORD=${{ secrets.PROD_MYSQL_PASSWORD }}
export JASYPT_ENCRYPTOR_PASSWORD=${{ secrets.JASYPT_PASSWORD }}
export TAG=prod-previous
docker compose up -d
- name: Tag successful deployment as latest
if: success()
run: |
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/$DOCKERHUB_REPOSITORY:${{ github.sha }}-prod_v2 ${{ secrets.DOCKERHUB_USERNAME }}/$DOCKERHUB_REPOSITORY:prod-latest
docker push ${{ secrets.DOCKERHUB_USERNAME }}/$DOCKERHUB_REPOSITORY:prod-latest
- name: Check Docker Process
if: always()
run: docker ps
3 changes: 2 additions & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ FROM openjdk:17-jdk

ARG JAR_FILE=./build/libs/ody-backend-0.0.1-SNAPSHOT.jar

ENV SPRING_PROFILES_ACTIVE=dev
ENV SPRING_PROFILES_ACTIVE=prod
# dev로 변경
ENV JASYPT_ENCRYPTOR_PASSWORD=${JASYPT_ENCRYPTOR_PASSWORD}

COPY ${JAR_FILE} ody-backend.jar
Expand Down
14 changes: 7 additions & 7 deletions backend/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ spring:
datasource:
write:
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: ENC(/pYkPoMxvv/cFWWYEEIJ1/7gtMSjD9WKhM4oSIUEiK3WGRrcXZGELR8s+ozO5hmimO3U99cs3yMKf5B/5uh7RLk4wC3W1IuZ3F0oX3hSEJeq16YkxR1okYZokeE3mZXTxcOHBb3krNg=)
username: ENC(Pjtz7HDMEVm9ScNAjaDEqA==)
password: ENC(9yYOk4n/7co8h0HDfOA20tduvw3htCFa)
jdbc-url: ENC(+p2DZSe9yNp28DPB+6F7aERvNdgI9vTRrbpU5C5RmKIkrZaNNBTThg/Kb2xg1M1qrtOhYVLtbFnLLbiXUKIfmRPls9py5cf1eO/sAER4Rqpx9oxMQ8m75pOqw/L3CKzAMlL7/TvoXDB0HIvkeYejqg==)
username: ENC(YZ2LkaSgfkD9S8m67TunJw==)
password: ENC(yjnFbKAlVVvzzQuWNECa7DcpWubhBn0Q)
read:
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: ENC(Ho2WMst/QlNJngqZ1nnRiQIaytH55rjohNVg/5W14vhcd88rAhk16y1yO3zzorKNGSsYV95t/lChWuFA5ivEz4Rh5NaZHjxddhvs1T7HHltl/eC5V1bhPh3+ck98Lk2iil0+RljDy+I=)
username: ENC(Pjtz7HDMEVm9ScNAjaDEqA==)
password: ENC(9yYOk4n/7co8h0HDfOA20tduvw3htCFa)
jdbc-url: ENC(+p2DZSe9yNp28DPB+6F7aERvNdgI9vTRrbpU5C5RmKIkrZaNNBTThg/Kb2xg1M1qrtOhYVLtbFnLLbiXUKIfmRPls9py5cf1eO/sAER4Rqpx9oxMQ8m75pOqw/L3CKzAMlL7/TvoXDB0HIvkeYejqg==)
username: ENC(YZ2LkaSgfkD9S8m67TunJw==)
password: ENC(yjnFbKAlVVvzzQuWNECa7DcpWubhBn0Q)
flyway:
baseline-version: 2

log:
file:
path: /ody-prod-logs

0 comments on commit 8ac539f

Please sign in to comment.