Skip to content

Commit 48587bf

Browse files
committed
Added CI provider smoke tests
1 parent 2befc18 commit 48587bf

5 files changed

Lines changed: 133 additions & 3 deletions

File tree

.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.git
2+
.github
3+
.vs
4+
5+
docs
6+
project-docs
7+
8+
**/.terraform
9+
**/.terraform/**
10+
**/*.tfstate
11+
**/*.tfstate.*
12+
src/.terraform.lock.hcl

.github/workflows/docker_ci_cd.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ jobs:
2525
- provider: sqlserver
2626
image_name: ${{ github.repository }}/database-container
2727
dockerfile: ./src/Dockerfile
28+
smoke_image: sqldockerdeploykit-ci-sqlserver
2829
- provider: postgres
2930
image_name: ${{ github.repository }}/database-container-postgres
3031
dockerfile: ./providers/postgres/Dockerfile
32+
smoke_image: sqldockerdeploykit-ci-postgres
3133

3234
steps:
3335
- name: Checkout repository
@@ -36,6 +38,12 @@ jobs:
3638
- name: Set up Docker Buildx
3739
uses: docker/setup-buildx-action@v1
3840

41+
- name: Build smoke-test image
42+
run: docker build -t "${{ matrix.smoke_image }}:${{ github.sha }}" -f "${{ matrix.dockerfile }}" .
43+
44+
- name: Smoke test image
45+
run: bash ./scripts/smoke-test-provider.sh "${{ matrix.provider }}" "${{ matrix.smoke_image }}:${{ github.sha }}"
46+
3947
- name: Log in to the Container registry
4048
if: github.event_name == 'push'
4149
uses: docker/login-action@v1
@@ -58,5 +66,3 @@ jobs:
5866
push: ${{ github.event_name == 'push' }}
5967
tags: ${{ steps.meta.outputs.tags }}
6068
labels: ${{ steps.meta.outputs.labels }}
61-
62-
# Optional: Add steps to run tests here

docs/providers.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ compatibility:
3838
- the Movies demo data is present;
3939
- a smoke query returns row counts for the expected tables.
4040

41+
CI runs `scripts/smoke-test-provider.sh` for every provider image before
42+
publishing. The smoke test starts the image, runs the provider's smoke query,
43+
and asserts the expected `5:5:5` Movies demo row counts.
44+
4145
## Adding Another Provider
4246

4347
Add a new folder under `providers/<engine>` with the provider's Dockerfile,

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ SQLDockerDeployKit users can significantly reduce the time and effort required t
3939

4040

4141
### GitHub Repository Features
42-
Any commits to the main branch trigger updates for this project's configured [GitHub Container Registry images](https://github.com/AnthonyPWatts?tab=packages&repo_name=SQLDockerDeployKit).
42+
Any commits to the main branch trigger smoke-tested updates for this project's configured [GitHub Container Registry images](https://github.com/AnthonyPWatts?tab=packages&repo_name=SQLDockerDeployKit).
4343

4444

4545
## Deployment Options

scripts/smoke-test-provider.sh

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
if [ "$#" -ne 2 ]; then
5+
echo "Usage: $0 <sqlserver|postgres> <image>"
6+
exit 2
7+
fi
8+
9+
PROVIDER="$1"
10+
IMAGE="$2"
11+
PASSWORD="${SQLDDK_SMOKE_PASSWORD:-YourStrong!Passw0rd}"
12+
TIMEOUT_SECONDS="${SQLDDK_SMOKE_TIMEOUT_SECONDS:-180}"
13+
POLL_SECONDS="${SQLDDK_SMOKE_POLL_SECONDS:-3}"
14+
CONTAINER="sqlddk-smoke-${PROVIDER}-${GITHUB_RUN_ID:-local}-$$"
15+
16+
cleanup() {
17+
docker rm -f "$CONTAINER" >/dev/null 2>&1 || true
18+
}
19+
20+
print_logs() {
21+
echo "Container logs for $CONTAINER:"
22+
docker logs "$CONTAINER" 2>&1 || true
23+
}
24+
25+
trim_last_non_empty_line() {
26+
awk 'NF { line = $0 } END { gsub(/^[ \t]+|[ \t]+$/, "", line); print line }'
27+
}
28+
29+
assert_sqlserver_counts() {
30+
local result
31+
32+
docker exec "$CONTAINER" \
33+
/opt/mssql-tools/bin/sqlcmd \
34+
-b -S localhost -U SA -P "$PASSWORD" \
35+
-i /tmp/app/provider/smoke-query.sql >/dev/null 2>&1
36+
37+
result="$(
38+
docker exec "$CONTAINER" \
39+
/opt/mssql-tools/bin/sqlcmd \
40+
-b -h -1 -W -S localhost -U SA -P "$PASSWORD" \
41+
-Q "SET NOCOUNT ON; USE MoviesDB; SELECT CAST((SELECT COUNT(*) FROM Movies) AS varchar(10)) + ':' + CAST((SELECT COUNT(*) FROM Actors) AS varchar(10)) + ':' + CAST((SELECT COUNT(*) FROM MoviesActors) AS varchar(10));" 2>/dev/null |
42+
tr -d '\r' |
43+
trim_last_non_empty_line
44+
)"
45+
46+
[ "$result" = "5:5:5" ]
47+
}
48+
49+
assert_postgres_counts() {
50+
local result
51+
52+
docker exec "$CONTAINER" \
53+
psql -U postgres -d moviesdb -v ON_ERROR_STOP=1 \
54+
-f /usr/local/share/sqldockerdeploykit/smoke-query.sql >/dev/null 2>&1
55+
56+
result="$(
57+
docker exec "$CONTAINER" \
58+
psql -U postgres -d moviesdb -v ON_ERROR_STOP=1 -t -A \
59+
-c "SELECT (SELECT COUNT(*) FROM movies)::text || ':' || (SELECT COUNT(*) FROM actors)::text || ':' || (SELECT COUNT(*) FROM movie_actors)::text;" 2>/dev/null |
60+
tr -d '\r' |
61+
trim_last_non_empty_line
62+
)"
63+
64+
[ "$result" = "5:5:5" ]
65+
}
66+
67+
wait_for_smoke() {
68+
local elapsed=0
69+
70+
while [ "$elapsed" -lt "$TIMEOUT_SECONDS" ]; do
71+
if "$@"; then
72+
echo "$PROVIDER smoke test passed for $IMAGE."
73+
return 0
74+
fi
75+
76+
local state
77+
state="$(docker inspect -f '{{.State.Status}}' "$CONTAINER" 2>/dev/null || echo missing)"
78+
if [ "$state" = "exited" ] || [ "$state" = "dead" ] || [ "$state" = "missing" ]; then
79+
echo "Container $CONTAINER stopped before smoke test passed."
80+
print_logs
81+
return 1
82+
fi
83+
84+
sleep "$POLL_SECONDS"
85+
elapsed=$((elapsed + POLL_SECONDS))
86+
done
87+
88+
echo "$PROVIDER smoke test did not pass within ${TIMEOUT_SECONDS}s."
89+
print_logs
90+
return 1
91+
}
92+
93+
trap cleanup EXIT
94+
95+
case "$PROVIDER" in
96+
sqlserver)
97+
docker run --name "$CONTAINER" -d -e "SA_PASSWORD=$PASSWORD" "$IMAGE" >/dev/null
98+
wait_for_smoke assert_sqlserver_counts
99+
;;
100+
postgres)
101+
docker run --name "$CONTAINER" -d -e "POSTGRES_PASSWORD=$PASSWORD" "$IMAGE" >/dev/null
102+
wait_for_smoke assert_postgres_counts
103+
;;
104+
*)
105+
echo "Unknown provider: $PROVIDER"
106+
exit 2
107+
;;
108+
esac

0 commit comments

Comments
 (0)