refactor: νΌλλ°± κ²μ¦μ΄ μ΄λ€μ§μ§ μλ λ¬Έμ λ₯Ό ν΄κ²°νλ€. #138
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |