Skip to content

Commit 9b84405

Browse files
committed
use docker compose in CI (as sqldef does)
1 parent a65317b commit 9b84405

File tree

1 file changed

+78
-56
lines changed

1 file changed

+78
-56
lines changed

.github/workflows/example.yaml

Lines changed: 78 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,31 @@ jobs:
1111
postgresql-preview:
1212
runs-on: ubuntu-latest
1313

14-
services:
15-
postgres:
16-
image: postgres:17
17-
env:
18-
POSTGRES_USER: postgres
19-
POSTGRES_PASSWORD: postgres
20-
POSTGRES_DB: testdb
21-
options: >-
22-
--health-cmd pg_isready
23-
--health-interval 10s
24-
--health-timeout 5s
25-
--health-retries 5
26-
ports:
27-
- 5432:5432
28-
2914
steps:
3015
- name: Checkout code
3116
uses: actions/checkout@v5
3217
with:
3318
fetch-depth: 0
3419

20+
- name: Start PostgreSQL with Docker Compose
21+
run: |
22+
docker compose up -d postgres
23+
env:
24+
POSTGRES_VERSION: 17
25+
26+
- name: Wait for PostgreSQL
27+
run: |
28+
for i in {1..30}; do
29+
if docker exec $(docker compose ps -q postgres) pg_isready -U postgres >/dev/null 2>&1; then
30+
echo "PostgreSQL is ready"
31+
break
32+
fi
33+
echo "Waiting for PostgreSQL..."
34+
sleep 2
35+
done
36+
# Create the test database
37+
docker exec $(docker compose ps -q postgres) psql -U postgres -c "CREATE DATABASE testdb;"
38+
3539
- name: Preview PostgreSQL schema changes
3640
uses: ./
3741
with:
@@ -40,34 +44,43 @@ jobs:
4044
baseline-schema-file: examples/psqldef-current.sql
4145
schema-file: examples/psqldef-desired.sql
4246
pg-user: postgres
43-
pg-password: postgres
47+
pg-password: ''
4448
pg-host: localhost
4549
pg-port: 5432
4650
pg-database: testdb
4751

52+
- name: Stop PostgreSQL
53+
if: always()
54+
run: docker compose down postgres
55+
4856
mysql-preview:
4957
runs-on: ubuntu-latest
5058

51-
services:
52-
mysql:
53-
image: mysql:8.0
54-
env:
55-
MYSQL_ROOT_PASSWORD: root
56-
MYSQL_DATABASE: testdb
57-
options: >-
58-
--health-cmd="mysqladmin ping"
59-
--health-interval=10s
60-
--health-timeout=5s
61-
--health-retries=5
62-
ports:
63-
- 3306:3306
64-
6559
steps:
6660
- name: Checkout code
6761
uses: actions/checkout@v5
6862
with:
6963
fetch-depth: 0
7064

65+
- name: Start MySQL with Docker Compose
66+
run: |
67+
docker compose up -d mysql
68+
env:
69+
MYSQL_VERSION: 8.0
70+
71+
- name: Wait for MySQL
72+
run: |
73+
for i in {1..30}; do
74+
if docker exec $(docker compose ps -q mysql) mysql -uroot -e "SELECT 1" >/dev/null 2>&1; then
75+
echo "MySQL is ready"
76+
break
77+
fi
78+
echo "Waiting for MySQL..."
79+
sleep 2
80+
done
81+
# Create the test database
82+
docker exec $(docker compose ps -q mysql) mysql -uroot -e "CREATE DATABASE testdb;"
83+
7184
- name: Preview MySQL schema changes
7285
uses: ./
7386
with:
@@ -76,11 +89,15 @@ jobs:
7689
baseline-schema-file: examples/mysqldef-current.sql
7790
schema-file: examples/mysqldef-desired.sql
7891
mysql-user: root
79-
mysql-password: root
92+
mysql-password: ''
8093
mysql-host: localhost
8194
mysql-port: 3306
8295
mysql-database: testdb
8396

97+
- name: Stop MySQL
98+
if: always()
99+
run: docker compose down mysql
100+
84101
sqlite-preview:
85102
runs-on: ubuntu-latest
86103

@@ -101,38 +118,39 @@ jobs:
101118

102119
mssql-preview:
103120
runs-on: ubuntu-latest
104-
continue-on-error: true
105-
106-
services:
107-
sqlserver:
108-
image: mcr.microsoft.com/mssql/server:2022-latest
109-
env:
110-
ACCEPT_EULA: Y
111-
SA_PASSWORD: YourStrong@Passw0rd
112-
MSSQL_PID: Developer
113-
options: >-
114-
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'YourStrong@Passw0rd' -Q 'SELECT 1' -No"
115-
--health-interval 10s
116-
--health-timeout 5s
117-
--health-retries 10
118-
ports:
119-
- 1433:1433
120121

121122
steps:
122123
- name: Checkout code
123124
uses: actions/checkout@v5
124125
with:
125126
fetch-depth: 0
126127

127-
- name: Wait for SQL Server
128+
- name: Start MSSQL with Docker Compose
128129
run: |
129-
sudo apt-get update && sudo apt-get install -y mssql-tools18
130-
for i in {1..30}; do
131-
/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'YourStrong@Passw0rd' -Q 'SELECT 1' -No && break
132-
echo "Waiting for SQL Server..."
133-
sleep 2
130+
docker compose up -d mssql
131+
env:
132+
MSSQL_VERSION: 2022-latest
133+
134+
- name: Wait for MSSQL
135+
run: |
136+
# Install sqlcmd tools
137+
sudo apt-get update && sudo apt-get install -y curl gnupg
138+
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
139+
curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
140+
sudo apt-get update
141+
sudo ACCEPT_EULA=Y apt-get install -y mssql-tools18
142+
143+
# Wait for MSSQL to be ready
144+
for i in {1..60}; do
145+
if docker exec $(docker compose ps -q mssql) /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "Passw0rd" -Q "SELECT 1" >/dev/null 2>&1; then
146+
echo "MSSQL is ready"
147+
break
148+
fi
149+
echo "Waiting for MSSQL..."
150+
sleep 3
134151
done
135-
/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'YourStrong@Passw0rd' -Q "CREATE DATABASE testdb" -No
152+
# Create the test database
153+
docker exec $(docker compose ps -q mssql) /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "Passw0rd" -Q "CREATE DATABASE testdb;"
136154
137155
- name: Preview MSSQL schema changes
138156
uses: ./
@@ -141,8 +159,12 @@ jobs:
141159
version: latest
142160
baseline-schema-file: examples/mssqldef-current.sql
143161
schema-file: examples/mssqldef-desired.sql
144-
mssql-user: sa
145-
mssql-password: YourStrong@Passw0rd
162+
mssql-user: SA
163+
mssql-password: Passw0rd
146164
mssql-host: localhost
147165
mssql-port: 1433
148166
mssql-database: testdb
167+
168+
- name: Stop MSSQL
169+
if: always()
170+
run: docker compose down mssql

0 commit comments

Comments
 (0)