diff --git a/.gitea/workflows/continuous_integration.yaml b/.gitea/workflows/continuous_integration.yaml index 55ae811..8909d57 100644 --- a/.gitea/workflows/continuous_integration.yaml +++ b/.gitea/workflows/continuous_integration.yaml @@ -148,55 +148,42 @@ jobs: # database. Without a real, reachable MariaDB, those tests fail on the connection itself # before any assertion runs. # - # A `services:` block was tried first and rejected: this runner uses host networking for - # job AND service containers ("--network and --net in the options will be ignored" in the - # job log), so the `ports:` mapping was silently ignored, and the mariadb:11 service ended - # up sharing the host's network namespace directly on port 3306 -- which something else on - # this runner already answers on (root auth was rejected by a server that was clearly NOT - # the freshly-initialized container: "Access denied ... using password: YES" against a - # password nothing but this job ever set). An explicitly `docker run` container below, - # published on a free host port chosen by the engine (not 3306), avoids that collision entirely. + # The database is a job-level `services:` container, so the job needs no container-engine socket (the PC + # runner has no /var/run/docker.sock in its job containers; a manual `docker run` failed there). The server + # listens on 3308 (MYSQL_TCP_PORT) instead of 3306: on the Pi runner job and service containers share the + # host's network namespace (host networking), where the host's own database already answers on 3306 -- the + # reason the first `services:` attempt there failed. On a runner with a separate job network the service is + # reached by its name `mariadb`; with host networking it is reached on 127.0.0.1 (resolved in the test step). + services: + 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: - uses: actions/checkout@v4 - uses: actions/setup-dotnet@v4 with: 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) + shell: bash # ConnectionStrings__DefaultConnection overrides the placeholder in appsettings.Development.json for this CI # run only (environment variables are applied after appsettings.*.json), so it reaches # SlpModularCms.Api.Tests' WebApplicationFactory without touching a committed appsettings file. 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 - - 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 --- # `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 # 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 - # 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. vulnerability-scan: needs: changes