Skip to content

refactor: ν”Όλ“œλ°± 검증이 이뀄지지 μ•ŠλŠ” 문제λ₯Ό ν•΄κ²°ν•œλ‹€. #138

refactor: ν”Όλ“œλ°± 검증이 이뀄지지 μ•ŠλŠ” 문제λ₯Ό ν•΄κ²°ν•œλ‹€.

refactor: ν”Όλ“œλ°± 검증이 이뀄지지 μ•ŠλŠ” 문제λ₯Ό ν•΄κ²°ν•œλ‹€. #138

Workflow file for this run

name: DB CI with Flyway
on:
workflow_dispatch:
pull_request:
branches: ["backend"]
permissions:
contents: read
jobs:
validate:
runs-on: development
defaults:
run:
working-directory: ./backend
env:
MYSQL_CONTAINER_NAME: temp-mysql
SOURCE_DB_HOSTNAME: 3.35.24.92
SOURCE_DB_PORT: 3306
SOURCE_DB_SCHEMA: digginroom_dev
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'
- name: MYSQL μ»¨ν…Œμ΄λ„ˆ μ‹€ν–‰
env:
DOCKER_HEALTHCHECK_OPTIONS: --health-cmd='mysql -uroot -proot -e "show databases;"' --health-interval=5s --health-timeout=5s --health-retries=3
# 도컀 μ»¨ν…Œμ΄λ„ˆ μ‹€ν–‰ ν›„ MySQL μ„œλ²„κ°€ μ‹€ν–‰λ˜μ–΄ 접속 κ°€λŠ₯ν•œμ§€κΉŒμ§€λ₯Ό ν™•μΈν•œλ‹€.
# μ ‘μ†κΉŒμ§€ κ°€λŠ₯ν•΄μ•Ό healthy μƒνƒœμ΄λ‹€.
timeout-minutes: 5
# 5λΆ„ μ•ˆμ— 접속 κ°€λŠ₯ν•˜μ§€ μ•ŠμœΌλ©΄ 이 단계λ₯Ό νƒ€μž„μ•„μ›ƒ μ²˜λ¦¬ν•œλ‹€.
run: |
sudo docker run --name $MYSQL_CONTAINER_NAME -e MYSQL_ROOT_PASSWORD=root -P \
${{ env.DOCKER_HEALTHCHECK_OPTIONS }} \
-d mysql:8.0
while [ "`sudo docker inspect -f {{.State.Health.Status}} $MYSQL_CONTAINER_NAME`" != "healthy" ]
do
echo "status: " `sudo docker inspect -f {{.State.Health.Status}} $MYSQL_CONTAINER_NAME`
sleep 5
done
- name: 개발 DB 덀프
env:
DUMP_OPTIONS: --single-transaction --no-tablespaces
# ν…Œμ΄λΈ” 락킹 κΆŒν•œκ³Ό ν…Œμ΄λΈ” 슀페이슀 μ—΄λžŒ κΆŒν•œ (PROCESS κΆŒν•œ) 없이 덀프할 수 μžˆλ‹€.
run: |
sudo docker exec $MYSQL_CONTAINER_NAME sh -c ' \
mysqldump \
-u ${{ secrets.DEV_DATASOURCE_USERNAME }} -p${{ secrets.DEV_DATASOURCE_PASSWORD }} \
-h ${{ env.SOURCE_DB_HOSTNAME }} -P ${{ env.SOURCE_DB_PORT }} \
-B ${{ env.SOURCE_DB_SCHEMA }} \
${{ env.DUMP_OPTIONS }} \
--where="1 limit 100" \
' > dump.sql
- name: 덀프λ₯Ό MySQL μ»¨ν…Œμ΄λ„ˆλ‘œ μž„ν¬νŠΈ
run: |
sudo docker exec -i $MYSQL_CONTAINER_NAME sh -c ' \
exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" \
' < dump.sql
- name: flyway.conf 생성
run: |
DOCKER_PORT=`sudo docker inspect --format="{{(index (index .NetworkSettings.Ports \"3306/tcp\") 0).HostPort}}" $MYSQL_CONTAINER_NAME`;
echo "MySQL Container Port: $DOCKER_PORT";
touch flyway.conf
echo "flyway.url=jdbc:mysql://127.0.0.1:$DOCKER_PORT/$SOURCE_DB_SCHEMA" >> flyway.conf
echo "flyway.user=root" >> flyway.conf
echo "flyway.password=root" >> flyway.conf
echo "flyway.encoding=UTF-8" >> flyway.conf
echo "flyway.outOfOrder=true" >> flyway.conf
echo "flyway.locations=filesystem:src/main/resources/db/migration" >> flyway.conf
- name: flywayMigrate μ‹€ν–‰
run: ./gradlew -Dflyway.configFiles=flyway.conf flywayMigrate --stacktrace >> $GITHUB_STEP_SUMMARY
- name: MYSQL μ»¨ν…Œμ΄λ„ˆ 제거
if: always()
shell: bash {0}
run: |
sudo docker rm -v -f $MYSQL_CONTAINER_NAME