CI: backend-test met services-container (geen engine-socket nodig), MariaDB op poort 3308
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -148,55 +148,42 @@ jobs:
|
|||||||
# database. Without a real, reachable MariaDB, those tests fail on the connection itself
|
# database. Without a real, reachable MariaDB, those tests fail on the connection itself
|
||||||
# before any assertion runs.
|
# before any assertion runs.
|
||||||
#
|
#
|
||||||
# A `services:` block was tried first and rejected: this runner uses host networking for
|
# The database is a job-level `services:` container, so the job needs no container-engine socket (the PC
|
||||||
# job AND service containers ("--network and --net in the options will be ignored" in the
|
# runner has no /var/run/docker.sock in its job containers; a manual `docker run` failed there). The server
|
||||||
# job log), so the `ports:` mapping was silently ignored, and the mariadb:11 service ended
|
# listens on 3308 (MYSQL_TCP_PORT) instead of 3306: on the Pi runner job and service containers share the
|
||||||
# up sharing the host's network namespace directly on port 3306 -- which something else on
|
# host's network namespace (host networking), where the host's own database already answers on 3306 -- the
|
||||||
# this runner already answers on (root auth was rejected by a server that was clearly NOT
|
# reason the first `services:` attempt there failed. On a runner with a separate job network the service is
|
||||||
# the freshly-initialized container: "Access denied ... using password: YES" against a
|
# reached by its name `mariadb`; with host networking it is reached on 127.0.0.1 (resolved in the test step).
|
||||||
# password nothing but this job ever set). An explicitly `docker run` container below,
|
services:
|
||||||
# published on a free host port chosen by the engine (not 3306), avoids that collision entirely.
|
mariadb:
|
||||||
|
image: mariadb:11
|
||||||
|
env:
|
||||||
|
MARIADB_ROOT_PASSWORD: ci_test_password
|
||||||
|
MARIADB_DATABASE: SlpModularCms
|
||||||
|
MYSQL_TCP_PORT: '3308'
|
||||||
|
options: >-
|
||||||
|
--health-cmd="mariadb-admin ping -uroot -pci_test_password --silent"
|
||||||
|
--health-interval=3s --health-timeout=3s --health-retries=40
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-dotnet@v4
|
- uses: actions/setup-dotnet@v4
|
||||||
with:
|
with:
|
||||||
dotnet-version: ${{ env.DOTNET_VERSION }}
|
dotnet-version: ${{ env.DOTNET_VERSION }}
|
||||||
- name: Start MariaDB for SlpModularCms.Api.Tests
|
|
||||||
run: |
|
|
||||||
# Runner-independent: docker or podman, a unique container name per run and a free host port chosen by the
|
|
||||||
# engine (`-p 127.0.0.1::3306`), so two runs on the same machine (or the PC's local dev database) never collide.
|
|
||||||
ENGINE=$(command -v docker || command -v podman)
|
|
||||||
NAME="ci-mariadb-${{ github.run_id }}-${{ github.run_attempt }}"
|
|
||||||
echo "CI_DB_ENGINE=$ENGINE" >> "$GITHUB_ENV"
|
|
||||||
echo "CI_DB_NAME=$NAME" >> "$GITHUB_ENV"
|
|
||||||
"$ENGINE" run -d --name "$NAME" \
|
|
||||||
-e MARIADB_ROOT_PASSWORD=ci_test_password \
|
|
||||||
-e MARIADB_DATABASE=SlpModularCms \
|
|
||||||
-p 127.0.0.1::3306 \
|
|
||||||
mariadb:11
|
|
||||||
PORT=$("$ENGINE" port "$NAME" 3306/tcp | head -1 | sed 's/.*://')
|
|
||||||
echo "CI_DB_PORT=$PORT" >> "$GITHUB_ENV"
|
|
||||||
echo "MariaDB published on 127.0.0.1:$PORT"
|
|
||||||
for i in $(seq 1 30); do
|
|
||||||
# mariadb:11 does not provide a `mysqladmin` alias -- verified locally against this
|
|
||||||
# exact image; the correct binary here is `mariadb-admin`.
|
|
||||||
if "$ENGINE" exec "$NAME" mariadb-admin ping -uroot -pci_test_password --silent 2>/dev/null; then
|
|
||||||
echo "MariaDB is ready."
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
echo "Waiting for MariaDB... ($i/30)"
|
|
||||||
sleep 2
|
|
||||||
done
|
|
||||||
- name: Test (Release)
|
- name: Test (Release)
|
||||||
|
shell: bash
|
||||||
# ConnectionStrings__DefaultConnection overrides the placeholder in appsettings.Development.json for this CI
|
# ConnectionStrings__DefaultConnection overrides the placeholder in appsettings.Development.json for this CI
|
||||||
# run only (environment variables are applied after appsettings.*.json), so it reaches
|
# run only (environment variables are applied after appsettings.*.json), so it reaches
|
||||||
# SlpModularCms.Api.Tests' WebApplicationFactory without touching a committed appsettings file.
|
# SlpModularCms.Api.Tests' WebApplicationFactory without touching a committed appsettings file.
|
||||||
run: |
|
run: |
|
||||||
export ConnectionStrings__DefaultConnection="Server=127.0.0.1;Port=$CI_DB_PORT;Database=SlpModularCms;Uid=root;Pwd=ci_test_password"
|
HOST=127.0.0.1
|
||||||
|
if getent hosts mariadb >/dev/null 2>&1; then HOST=mariadb; fi
|
||||||
|
echo "Waiting for MariaDB on $HOST:3308"
|
||||||
|
for i in $(seq 1 60); do
|
||||||
|
if (echo > "/dev/tcp/$HOST/3308") 2>/dev/null; then echo "MariaDB is accepting connections."; break; fi
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
export ConnectionStrings__DefaultConnection="Server=$HOST;Port=3308;Database=SlpModularCms;Uid=root;Pwd=ci_test_password"
|
||||||
dotnet test SlpModularCms.sln -c Release
|
dotnet test SlpModularCms.sln -c Release
|
||||||
- name: Stop MariaDB for SlpModularCms.Api.Tests
|
|
||||||
if: always()
|
|
||||||
run: '"${CI_DB_ENGINE:-docker}" rm -f "${CI_DB_NAME:-ci-mariadb}" || true'
|
|
||||||
|
|
||||||
# --- Gate 3: vulnerability scan ---
|
# --- Gate 3: vulnerability scan ---
|
||||||
# `dotnet list package --vulnerable` always exits 0, even when it reports vulnerabilities, so the
|
# `dotnet list package --vulnerable` always exits 0, even when it reports vulnerabilities, so the
|
||||||
@@ -207,7 +194,7 @@ jobs:
|
|||||||
# PC runner: global, linux, x64, podman, bryan-desktop
|
# PC runner: global, linux, x64, podman, bryan-desktop
|
||||||
# Every job uses `linux` so that any runner (PC, Pi, future ones) can pick it up; no job assumes the host
|
# Every job uses `linux` so that any runner (PC, Pi, future ones) can pick it up; no job assumes the host
|
||||||
# architecture or a specific user: publish-* cross-publishes with an explicit `-r linux-arm64`, deploy-scp.yaml only
|
# architecture or a specific user: publish-* cross-publishes with an explicit `-r linux-arm64`, deploy-scp.yaml only
|
||||||
# installs missing tools and only uses sudo when needed, backend-test picks a free port for its database.
|
# installs missing tools and only uses sudo when needed, backend-test uses a services: container (no engine socket needed).
|
||||||
# Use `raspberry-pi` only for a job that demonstrably cannot run elsewhere, and say why in a comment.
|
# Use `raspberry-pi` only for a job that demonstrably cannot run elsewhere, and say why in a comment.
|
||||||
vulnerability-scan:
|
vulnerability-scan:
|
||||||
needs: changes
|
needs: changes
|
||||||
|
|||||||
Reference in New Issue
Block a user