-
Notifications
You must be signed in to change notification settings - Fork 3
89 lines (77 loc) Β· 3.17 KB
/
ci-dev-db.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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