Docker Compose Acceptance #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Docker Compose Acceptance | |
| on: | |
| pull_request: | |
| branches: [agent/bootstrap-siteops] | |
| push: | |
| branches: [agent/bootstrap-siteops] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| docker-compose-acceptance: | |
| runs-on: ubuntu-24.04 | |
| timeout-minutes: 25 | |
| env: | |
| COMPOSE_PROJECT_NAME: siteops-acceptance-${{ github.run_id }} | |
| ACCEPTANCE_DIR: /tmp/siteops-acceptance-${{ github.run_id }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| - name: Enable pnpm | |
| run: corepack enable | |
| - name: Preflight source and Docker tools | |
| shell: bash | |
| run: | | |
| set -Eeuo pipefail | |
| pnpm install --frozen-lockfile | |
| pnpm verify | |
| sh -n scripts/qa-distribution.sh scripts/qa-local-fixture.sh scripts/install-local.sh | |
| docker version --format '{{.Server.Version}}' | |
| docker compose version | |
| - name: Run canonical Docker distribution acceptance | |
| shell: bash | |
| run: | | |
| set -Eeuo pipefail | |
| mkdir -p "$ACCEPTANCE_DIR" | |
| log="$ACCEPTANCE_DIR/acceptance.log" | |
| summary="$ACCEPTANCE_DIR/acceptance-summary.txt" | |
| cleanup="$ACCEPTANCE_DIR/cleanup-receipt.txt" | |
| wrapper_log="$ACCEPTANCE_DIR/docker-wrapper.log" | |
| : >"$log" | |
| echo "commit=${GITHUB_SHA}" >"$summary" | |
| docker version --format 'docker_server={{.Server.Version}}' >>"$summary" | |
| docker compose version >>"$summary" | |
| real_docker="$(command -v docker)" | |
| wrapper_dir="$RUNNER_TEMP/siteops-docker-wrapper" | |
| mkdir -p "$wrapper_dir" | |
| cat >"$wrapper_dir/docker" <<'EOF' | |
| #!/usr/bin/env bash | |
| set -Eeuo pipefail | |
| if [[ "${1:-}" == "compose" && "${2:-}" == "down" ]]; then | |
| { | |
| echo "--- compose-down-preflight ---" | |
| "$REAL_DOCKER_BIN" compose ps -a || true | |
| container_id="$("$REAL_DOCKER_BIN" compose ps -aq siteops || true)" | |
| if [[ -n "$container_id" ]]; then | |
| "$REAL_DOCKER_BIN" inspect --format 'config_user={{.Config.User}} path={{.Path}} args={{json .Args}} pid={{.State.Pid}} exit={{.State.ExitCode}} cap_add={{json .HostConfig.CapAdd}} cap_drop={{json .HostConfig.CapDrop}} security_opt={{json .HostConfig.SecurityOpt}} health_test={{json .Config.Healthcheck.Test}} mounts={{range .Mounts}}{{println .Destination .RW}}{{end}}' "$container_id" || true | |
| fi | |
| "$REAL_DOCKER_BIN" compose logs --no-color siteops || true | |
| } >>"$WRAPPER_LOG" 2>&1 | |
| fi | |
| exec "$REAL_DOCKER_BIN" "$@" | |
| EOF | |
| chmod +x "$wrapper_dir/docker" | |
| export REAL_DOCKER_BIN="$real_docker" | |
| export WRAPPER_LOG="$wrapper_log" | |
| export PATH="$wrapper_dir:$PATH" | |
| trap 'status=$?; set +e; test -f "$wrapper_log" && cat "$wrapper_log" >>"$log"; docker compose ps -a >>"$log" 2>&1; docker compose logs --no-color siteops >>"$log" 2>&1; docker compose down --volumes >>"$log" 2>&1; cleanup_status=$?; printf "project=%s\\ncleanup_status=%s\\n" "$COMPOSE_PROJECT_NAME" "$cleanup_status" >"$cleanup"; printf "acceptance_status=%s\\ncleanup_status=%s\\n" "$status" "$cleanup_status" >>"$summary"; if [ "$status" -eq 0 ] && [ "$cleanup_status" -ne 0 ]; then exit "$cleanup_status"; fi; exit "$status"' EXIT | |
| scripts/qa-distribution.sh >>"$log" 2>&1 | |
| image_id="$(docker image inspect --format '{{.Id}}' baota-siteops:test)" | |
| printf "image_id=%s\\nhealth_url=http://127.0.0.1:3210/healthz\\nresult=passed\\n" "$image_id" >>"$summary" | |
| - name: Publish run summary | |
| if: always() | |
| shell: bash | |
| run: | | |
| set -Eeuo pipefail | |
| { | |
| echo '## Docker Compose Acceptance' | |
| echo | |
| echo "Tested commit: \`${GITHUB_SHA}\`" | |
| test -f "$ACCEPTANCE_DIR/acceptance-summary.txt" && sed 's/^/- /' "$ACCEPTANCE_DIR/acceptance-summary.txt" || echo '- No acceptance summary was produced.' | |
| test -f "$ACCEPTANCE_DIR/cleanup-receipt.txt" && sed 's/^/- /' "$ACCEPTANCE_DIR/cleanup-receipt.txt" || echo '- No cleanup receipt was produced.' | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| - name: Upload successful acceptance summary | |
| if: success() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: siteops-docker-acceptance-summary-${{ github.run_id }} | |
| path: ${{ env.ACCEPTANCE_DIR }}/acceptance-summary.txt | |
| if-no-files-found: error | |
| retention-days: 7 | |
| - name: Upload failed acceptance evidence | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: siteops-docker-acceptance-failure-${{ github.run_id }} | |
| path: | | |
| ${{ env.ACCEPTANCE_DIR }}/acceptance.log | |
| ${{ env.ACCEPTANCE_DIR }}/acceptance-summary.txt | |
| ${{ env.ACCEPTANCE_DIR }}/cleanup-receipt.txt | |
| ${{ env.ACCEPTANCE_DIR }}/docker-wrapper.log | |
| if-no-files-found: warn | |
| retention-days: 7 |