From 8622b6fc4e6238524184f815beae648be8d68567 Mon Sep 17 00:00:00 2001 From: niko Date: Tue, 16 Jun 2026 09:13:36 +0300 Subject: [PATCH] Feature/ci container (#15) Co-authored-by: moilanik Reviewed-on: https://gitea.app.keskikuja.site/niko/gitea-ci-library/pulls/15 --- .gitea/workflows/ci-container-build-push.yml | 57 +++++++++++++++++++ .gitea/workflows/example-build-ci-bats.yml | 21 +++++++ .../workflows/example-build-ci-cucumber.yml | 21 +++++++ .gitea/workflows/example-feature.yml | 2 +- .gitea/workflows/example-main.yml | 2 +- ...-report-summary.yml => report-summary.yml} | 0 Dockerfile.ci-bats | 3 + Dockerfile.ci-cucumber | 6 ++ docs/ai-context.md | 4 +- docs/architecture.md | 2 +- docs/workflows.md | 2 +- 11 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 .gitea/workflows/ci-container-build-push.yml create mode 100644 .gitea/workflows/example-build-ci-bats.yml create mode 100644 .gitea/workflows/example-build-ci-cucumber.yml rename .gitea/workflows/{example-report-summary.yml => report-summary.yml} (100%) create mode 100644 Dockerfile.ci-bats create mode 100644 Dockerfile.ci-cucumber diff --git a/.gitea/workflows/ci-container-build-push.yml b/.gitea/workflows/ci-container-build-push.yml new file mode 100644 index 0000000..da2c2fd --- /dev/null +++ b/.gitea/workflows/ci-container-build-push.yml @@ -0,0 +1,57 @@ +name: CI Container Build & Push +on: + workflow_call: + inputs: + env_json: + required: true + type: string + dockerfile_path: + required: true + type: string + image_name: + required: true + type: string + tag: + required: true + type: string + secrets: + DOCKER_USERNAME: + required: false + DOCKER_PASSWORD: + required: true + +env: + DOCKER_REGISTRY: ${{ fromJson(inputs.env_json).DOCKER_REGISTRY || '' }} + IMAGE_NAME: ${{ inputs.image_name }} + TAG: ${{ inputs.tag }} + DOCKERFILE: ${{ inputs.dockerfile_path }} + +jobs: + build-push: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Build and push CI container + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME || github.actor }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + run: | + NOW=$(date -u +%Y-%m-%dT%H:%M:%SZ) + docker build \ + --label "git.commit=${{ github.sha }}" \ + --label "git.commitBy=${{ github.actor }}" \ + --label "build.date=${NOW}" \ + -f "${DOCKERFILE}" \ + -t "${IMAGE_NAME}:${TAG}" . + + REGISTRY="${DOCKER_REGISTRY:?DOCKER_REGISTRY not set in env.conf}" + REGISTRY_HOST="${REGISTRY%%/*}" + + FULL_IMAGE="${REGISTRY}/${IMAGE_NAME}:${TAG}" + echo "Pushing ${FULL_IMAGE} ..." + + docker tag "${IMAGE_NAME}:${TAG}" "$FULL_IMAGE" + echo "$DOCKER_PASSWORD" | docker login "$REGISTRY_HOST" -u "$DOCKER_USERNAME" --password-stdin + docker push "$FULL_IMAGE" + docker logout "$REGISTRY_HOST" diff --git a/.gitea/workflows/example-build-ci-bats.yml b/.gitea/workflows/example-build-ci-bats.yml new file mode 100644 index 0000000..ead2697 --- /dev/null +++ b/.gitea/workflows/example-build-ci-bats.yml @@ -0,0 +1,21 @@ +name: Build CI Bats Container (Manual) +on: workflow_dispatch + +jobs: + load-config: + name: Load config + uses: niko/gitea-ci-library/.gitea/workflows/config-provider.yml@main + secrets: inherit + with: + config_path: .gitea/workflows/example-gitea-env.conf + + build-push: + name: Build & Push + needs: [load-config] + uses: niko/gitea-ci-library/.gitea/workflows/ci-container-build-push.yml@main + secrets: inherit + with: + env_json: ${{ needs.load-config.outputs.env_json }} + dockerfile_path: Dockerfile.ci-bats + image_name: ci-bats + tag: latest diff --git a/.gitea/workflows/example-build-ci-cucumber.yml b/.gitea/workflows/example-build-ci-cucumber.yml new file mode 100644 index 0000000..cd3f45b --- /dev/null +++ b/.gitea/workflows/example-build-ci-cucumber.yml @@ -0,0 +1,21 @@ +name: Build CI Cucumber Container (Manual) +on: workflow_dispatch + +jobs: + load-config: + name: Load config + uses: niko/gitea-ci-library/.gitea/workflows/config-provider.yml@main + secrets: inherit + with: + config_path: .gitea/workflows/example-gitea-env.conf + + build-push: + name: Build & Push + needs: [load-config] + uses: niko/gitea-ci-library/.gitea/workflows/ci-container-build-push.yml@main + secrets: inherit + with: + env_json: ${{ needs.load-config.outputs.env_json }} + dockerfile_path: Dockerfile.ci-cucumber + image_name: ci-cucumber + tag: latest diff --git a/.gitea/workflows/example-feature.yml b/.gitea/workflows/example-feature.yml index c571def..2751a2e 100644 --- a/.gitea/workflows/example-feature.yml +++ b/.gitea/workflows/example-feature.yml @@ -35,7 +35,7 @@ jobs: name: Report Summary needs: [load-config, bats, cucumber] if: always() - uses: niko/gitea-ci-library/.gitea/workflows/example-report-summary.yml@main + uses: niko/gitea-ci-library/.gitea/workflows/report-summary.yml@main with: env_json: ${{ needs.load-config.outputs.env_json }} suites: bats cucumber diff --git a/.gitea/workflows/example-main.yml b/.gitea/workflows/example-main.yml index 81d7ca6..9d5ed8e 100644 --- a/.gitea/workflows/example-main.yml +++ b/.gitea/workflows/example-main.yml @@ -55,7 +55,7 @@ jobs: name: Report Summary needs: [load-config, build-push] if: always() - uses: niko/gitea-ci-library/.gitea/workflows/example-report-summary.yml@main + uses: niko/gitea-ci-library/.gitea/workflows/report-summary.yml@main with: env_json: ${{ needs.load-config.outputs.env_json }} suites: bats cucumber diff --git a/.gitea/workflows/example-report-summary.yml b/.gitea/workflows/report-summary.yml similarity index 100% rename from .gitea/workflows/example-report-summary.yml rename to .gitea/workflows/report-summary.yml diff --git a/Dockerfile.ci-bats b/Dockerfile.ci-bats new file mode 100644 index 0000000..1ca8e17 --- /dev/null +++ b/Dockerfile.ci-bats @@ -0,0 +1,3 @@ +FROM bats/bats:latest +RUN apk add --no-cache lsof python3 jq curl ruby && \ + gem install bashcov -v 3.3.0 diff --git a/Dockerfile.ci-cucumber b/Dockerfile.ci-cucumber new file mode 100644 index 0000000..f556ac3 --- /dev/null +++ b/Dockerfile.ci-cucumber @@ -0,0 +1,6 @@ +FROM node:22 +RUN apt-get update -qq && \ + apt-get install -y -qq --no-install-recommends lsof jq && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* && \ + npm install -g @cucumber/cucumber diff --git a/docs/ai-context.md b/docs/ai-context.md index 52c1dc5..c9cde1e 100644 --- a/docs/ai-context.md +++ b/docs/ai-context.md @@ -34,13 +34,14 @@ kuuluu `git-pages/docs/`-alle, ei juuren `docs/`-kansioon. | `git-pages/` | Raporttien hostaus (Helm-chartti) | | `tests/` | Bats-testit skripteille | -### Provider workflowt (3 kpl) +### Provider workflowt (4 kpl) | Workflow | Input | Output | Kuvaus | |---|---|---|---| | `config-provider.yml` | `config_path` | `env_json`, `config_path` | Validoi ja jäsentää `.conf` → JSON. Sama kutsu hoitaa validoinnin. | | `check-version.yml` | `env_json` | `artifact_exists`, `version` | Tarkistaa git-tagit ja `package.json`:n, laskee seuraavan version. Vain main-haarassa. | | `docker-build-push.yml` | `env_json`, `version` | — | Buildaa Docker-imagen, puskea rekisteriin, tagittaa commitin. | +| `report-summary.yml` | `env_json`, `suites` | — | Generoi `GITHUB_STEP_SUMMARY`-taulukon raporttilinkeillä (Gitea 1.27+) | ### Example-tiedostot (consumer-referenssi) @@ -50,7 +51,6 @@ kuuluu `git-pages/docs/`-alle, ei juuren `docs/`-kansioon. | `example-main.yml` | push [main] | load-config → check-version → bats + cucumber → report-summary → docker-build-push | | `example-bats-tests.yml` | workflow_call | Unit-testit Batsilla, raportit git-pagesiin, status linkillä | | `example-cucumber-tests.yml` | workflow_call | Hyväksymätestit Cucumberilla, raportit git-pagesiin, status linkillä | -| `example-report-summary.yml` | workflow_call | `GITHUB_STEP_SUMMARY`-taulukko raporttilinkeillä (Gitea 1.27+) | | `example-gitea-env.conf` | — | KEY=VALUE config tälle repolle | ## Key Technical Decisions diff --git a/docs/architecture.md b/docs/architecture.md index 54d7113..60fcc93 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -33,7 +33,7 @@ Tarkemmin: ADR 0005. | `example-main.yml` | Consumer | Main-haaran CI: load-config → check-version → bats + cucumber → summary → docker | | `example-bats-tests.yml` | Consumer | Unit-testit Batsilla | | `example-cucumber-tests.yml` | Consumer | Hyväksymätestit Cucumberilla | -| `example-report-summary.yml` | Consumer | `GITHUB_STEP_SUMMARY`-taulukko (Gitea 1.27+) | +| `report-summary.yml` | Provider | `GITHUB_STEP_SUMMARY`-taulukko raporttilinkeillä (Gitea 1.27+) | | `publish-git-pages.sh` | Provider-skripti | PATCH tar git-pagesiin | | `report-status.sh` | Provider-skripti | POSTaa commit-status (vain custom-linkkiin) | | `ci-validate.sh` | Provider-skripti | Validoi `.conf`-tiedoston ja tarkistaa secretit | diff --git a/docs/workflows.md b/docs/workflows.md index 17f329b..d41d861 100644 --- a/docs/workflows.md +++ b/docs/workflows.md @@ -108,7 +108,7 @@ raportit git-pagesiin, asettaa commit-statuksen linkillä raporttiin. Ajaa Cucumber-testit Node-kontissa, julkaisee raportit git-pagesiin, asettaa commit-statuksen linkillä raporttiin. -### `example-report-summary.yml` — Raporttien koontinäkymä +### `report-summary.yml` — Raporttien koontinäkymä **Trigger:** `workflow_call` — ajetaan `if: always()` testien jälkeen