From ce067a8be647523d9ad86edd30990cf05c9fe783 Mon Sep 17 00:00:00 2001 From: moilanik Date: Wed, 17 Jun 2026 14:09:50 +0300 Subject: [PATCH] - manual start ci docker build - parametroitu job --- .gitea/workflows/ci-container-build-push.yml | 18 +-- .../workflows/example-build-ci-cucumber.yml | 40 +++-- docs/ai-context.md | 5 +- skills/ci-container-build/SKILL.md | 148 ++++++++++++++++++ skills/consumer-pipelines/SKILL.md | 17 +- 5 files changed, 200 insertions(+), 28 deletions(-) create mode 100644 skills/ci-container-build/SKILL.md diff --git a/.gitea/workflows/ci-container-build-push.yml b/.gitea/workflows/ci-container-build-push.yml index da2c2fd..9a98b9b 100644 --- a/.gitea/workflows/ci-container-build-push.yml +++ b/.gitea/workflows/ci-container-build-push.yml @@ -12,31 +12,32 @@ on: required: true type: string tag: - required: true + required: false type: string + default: 'latest' 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 + - name: Build and push container env: + DOCKER_REGISTRY: ${{ fromJson(inputs.env_json).DOCKER_REGISTRY || '' }} DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME || github.actor }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} run: | + REGISTRY="${DOCKER_REGISTRY:?DOCKER_REGISTRY not set in conf}" + DOCKERFILE="${{ inputs.dockerfile_path }}" + IMAGE_NAME="${{ inputs.image_name }}" + TAG="${{ inputs.tag }}" + NOW=$(date -u +%Y-%m-%dT%H:%M:%SZ) docker build \ --label "git.commit=${{ github.sha }}" \ @@ -45,7 +46,6 @@ jobs: -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}" diff --git a/.gitea/workflows/example-build-ci-cucumber.yml b/.gitea/workflows/example-build-ci-cucumber.yml index cd3f45b..d45c482 100644 --- a/.gitea/workflows/example-build-ci-cucumber.yml +++ b/.gitea/workflows/example-build-ci-cucumber.yml @@ -1,21 +1,41 @@ -name: Build CI Cucumber Container (Manual) -on: workflow_dispatch +name: CI Container Build Cucumber +on: + workflow_dispatch: + inputs: + config_path: + required: true + type: string + default: '.gitea/workflows/example-gitea-env.conf' + description: 'Polku .gitea-env.conf-tiedostoon' + dockerfile_path: + required: true + type: string + default: 'Dockerfile.ci-cucumber' + description: 'Polku Dockerfileen' + image_name: + required: true + type: string + default: 'ci-cucumber' + description: 'Kontin nimi ilman registry-polkua' + tag: + required: true + type: string + default: 'latest' + description: 'Image-tägi' jobs: load-config: - name: Load config - uses: niko/gitea-ci-library/.gitea/workflows/config-provider.yml@main + uses: niko/gitea-ci-library/.gitea/workflows/config-provider.yml@v1 secrets: inherit with: - config_path: .gitea/workflows/example-gitea-env.conf + config_path: ${{ inputs.config_path }} build-push: - name: Build & Push needs: [load-config] - uses: niko/gitea-ci-library/.gitea/workflows/ci-container-build-push.yml@main + uses: niko/gitea-ci-library/.gitea/workflows/ci-container-build-push.yml@v1 secrets: inherit with: env_json: ${{ needs.load-config.outputs.env_json }} - dockerfile_path: Dockerfile.ci-cucumber - image_name: ci-cucumber - tag: latest + dockerfile_path: ${{ inputs.dockerfile_path }} + image_name: ${{ inputs.image_name }} + tag: ${{ inputs.tag }} diff --git a/docs/ai-context.md b/docs/ai-context.md index 1ddd599..41dd103 100644 --- a/docs/ai-context.md +++ b/docs/ai-context.md @@ -26,22 +26,25 @@ kuuluu `git-pages/docs/`-alle, ei juuren `docs/`-kansioon. | `.gitea/workflows/config-provider.yml` | Provider: lataa + validoi config-tiedoston, tuottaa `env_json` | | `.gitea/workflows/check-version.yml` | Provider: tarkistaa onko commitille jo artifact, laskee version | | `.gitea/workflows/docker-build-push.yml` | Provider: buildaa + puskea Docker-imagen, tagittaa commitin | +| `.gitea/workflows/ci-container-build-push.yml` | Provider: buildaa + puskea CI-työkalukontin | | `.gitea/workflows/example-*` | **Consumer-esimerkki**: tämän repon oma CI (dogfood) | | `scripts/` | Provider-skriptit: `report-status.sh`, `publish-git-pages.sh`, `ci-validate.sh` | | `.gitea/scripts/` | **Consumer-skriptit**: `bats-coverage.sh`, `bats-report.sh` | | `docs/` | Arkkitehtuuri, ADRt (0004–0008) | | `skills/consumer-pipelines/` | Consumer-pipeline-standardit — AI:n pakottavat säännöt consumer-CI:lle | +| `skills/ci-container-build/` | CI-kontin build-workflow'n template — `ci-container-build-push.yml` | | `docs/adr/` | Architecture Decision Records | | `git-pages/` | Raporttien hostaus (Helm-chartti) | | `tests/` | Bats-testit skripteille | -### Provider workflowt (4 kpl) +### Provider workflowt (5 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. | +| `ci-container-build-push.yml` | `env_json`, `dockerfile_path`, `image_name`, `tag` | — | Buildaa CI-työkalukontin, puskea rekisteriin. Ei versiointia eikä git-tägäystä. | | `report-summary.yml` | `env_json`, `suites` | — | Generoi `GITHUB_STEP_SUMMARY`-taulukon raporttilinkeillä (Gitea 1.27+) | ### Example-tiedostot (consumer-referenssi) diff --git a/skills/ci-container-build/SKILL.md b/skills/ci-container-build/SKILL.md new file mode 100644 index 0000000..3c39c0a --- /dev/null +++ b/skills/ci-container-build/SKILL.md @@ -0,0 +1,148 @@ +--- +name: ci-container-build +description: | + Creating or modifying CI container build workflows. Activates when consumer + needs to build a custom CI container image (multi-tool image for tests, + linting, validation) that is pushed to a container registry for use in + other pipeline jobs. +activation-gate: | + User mentions CI container, custom CI image, ci-container-build, Dockerfile + for CI tools, multi-tool container, or needs to build/push a container that + other CI jobs will use as their runtime environment. +category: ci +impact: high +--- + +# CI Container Build — Template + +Template jolla consumer luo oman CI-kontin build-workflown. +Kontti sisältää useamman työkalun yhdistelmän (esim. helm + kubeconform + xsltproc), +jota muut jobit käyttävät ajonaikaisena ympäristönä. + +## Rakenne + +Vain `workflow_dispatch` — **ei automaattista buildausta koskaan**. Kontti buildataan +manuaalisesti Gitea Actions UI:sta. Tiedoston ilmestyessä main-haaraan workflow näkyy +välittömästi Actions-tabissa ajettavana. + +Build-prosessi lataa ensin `config-provider.yml`:llä `DOCKER_REGISTRY`:n +conf-tiedostosta, sitten buildaa ja puskaa kontin. + +Kun kontti on pushattu registryyn, se on muiden pipeline-jobien käytettävissä +`latest`-tägillä — rebuild = käyttöönotto. Mitään versioviittauksia ei tarvitse +päivittää. + +## Nimeäminen + +CI-kontin build-workflow noudattaa samaa nimeämiskonventiota kuin muutkin +tiedostot `.gitea/workflows/`-kansiossa: + +``` +.ci-feature.yml ← feature-haaran reititin +.ci-main.yml ← main-haaran reititin +..yml ← yksittäinen testi tai operaatio +.ci-container-build-.yml ← CI-kontin build-workflow +.gitea-env.conf ← komponenttikohtainen konfiguraatio +``` + +Single repossa `` jätetään pois — tiedostot ovat suoraan `ci-feature.yml`, +`ci-main.yml`, `.yml`, `ci-container-build-.yml`. + +Monorepossa prefiksi pitää komponentin tiedostot yhdessä: `ls .*` löytää kaikki +kerralla. **Olemassaolevia prefiksejä ei saa poistaa.** + +Esimerkkejä: +``` +.gitea/workflows/chart.ci-container-build-helm.yml +.gitea/workflows/api.ci-container-build-node.yml +.gitea/workflows/ci-container-build-bats.yml ← single repo +``` + +## Template + +> **Korvaa kaikki `__SUURAAKKOSET__`-placeholderit projektin todellisilla arvoilla.** +> Ainoastaan `${{ ... }}`-syntaksilla merkityt Gitea Actions -muuttujat ovat ajonaikaisia +> eikä niitä korvata. + +Luo `.gitea/workflows/__KOMPONENTTI__.ci-container-build-__KONTTI__.yml` +(single repo: `ci-container-build-__KONTTI__.yml`): + +```yaml +name: CI Container Build & Push +on: + workflow_dispatch: + inputs: + config_path: + required: true + type: string + description: 'Polku .gitea-env.conf-tiedostoon (esim. .gitea/workflows/chart.gitea-env.conf)' + dockerfile_path: + required: true + type: string + description: 'Polku Dockerfileen (esim. ci-helm.Dockerfile)' + image_name: + required: true + type: string + description: 'Kontin nimi ilman registry-polkua (esim. ci-helm)' + tag: + required: true + type: string + default: 'latest' + description: 'Image-tägi' + +jobs: + load-config: + uses: __OWNER__/gitea-ci-library/.gitea/workflows/config-provider.yml@v1 + secrets: inherit + with: + config_path: ${{ inputs.config_path }} + + build-push: + needs: [load-config] + uses: __OWNER__/gitea-ci-library/.gitea/workflows/ci-container-build-push.yml@v1 + secrets: inherit + with: + env_json: ${{ needs.load-config.outputs.env_json }} + dockerfile_path: ${{ inputs.dockerfile_path }} + image_name: ${{ inputs.image_name }} + tag: ${{ inputs.tag }} +``` + +### Käyttö + +**Gitea Actions UI:sta** (heti kun tiedosto on main-haarassa): + +``` +Gitea → Actions → CI Container Build & Push → Run workflow + +config_path: .gitea/workflows/__KOMPONENTTI__.gitea-env.conf +dockerfile_path: ci-__TYÖKALU__.Dockerfile +image_name: ci-__TYÖKALU__ +tag: latest +``` + +### Dockerfile + +Dockerfile yhdistää tarvitut työkalut yhteen konttiin. Molemmat tavat kelpaavat: + +```dockerfile +# Tapa A: COPY --from toisesta imagesta +FROM __BASE_IMAGE__:__VERSION__ +COPY --from=__SOURCE_IMAGE__:__VERSION__ /path/to/binary /usr/local/bin/ +RUN apk add --no-cache __PAKETIT__ + +# Tapa B: curl-lataus (normaali Dockerfilessa) +FROM __BASE_IMAGE__:__VERSION__ +RUN apk add --no-cache curl __PAKETIT__ && \ + curl -fsSL __URL__/__BINARY__.tar.gz | tar xz -C /usr/local/bin && \ + apk del curl +``` + +`COPY --from` on kevyempi (ei curl-asennusta). `curl` on selkeämpi kun binääri +tulee suoraan GitHub Releasesista tai vastaavasta. + +## Mitä EI kannata tehdä + +- Älä lisää `workflow_call`-triggariä — CI-konttia ei koskaan buildata automaattisesti +- Älä poista `.`-prefiksiä olemassaolevista tiedostoista — ne kuuluvat monorepo-nimeämiskonventioon +- Älä sisällytä CI-konttiin mitään sovelluskoodia — vain työkalut diff --git a/skills/consumer-pipelines/SKILL.md b/skills/consumer-pipelines/SKILL.md index a166a3e..11279d2 100644 --- a/skills/consumer-pipelines/SKILL.md +++ b/skills/consumer-pipelines/SKILL.md @@ -108,15 +108,15 @@ shellin käyttäytyminen vaihtelee. 1. **Julkiset registry-kontit kiinteällä versiolla** — `alpine/helm:3.19.0`, `node:22`, `maven:3.9-eclipse-temurin-21`. Toistettavuus ja turvallisuus eivät saa riippua ulkoisesta `latest`:sta -2. **Projektin omat CI-kontit `latest`-tägillä** — buildattu `ci-container-build-push.yml`:llä. +2. **Projektin omat CI-kontit `latest`-tägillä** — buildattu `ci-container-build-.yml`:llä. Kontin build-pipeline päivittää `latest`:n automaattisesti. Rebuild = käyttöönotto kaikissa pipelineissa ilman versioviittauksien päivittelyä. `latest` on näille paras käytäntö, ei kompromissi 3. **Ei koskaan `curl`-latauksia CI-ajon sisällä** — työkalujen asennus CI-stepeissä hidastaa, epäluotettavaa, ja vaikeuttaa toistettavuutta -Pre-buildattu kontti rakennetaan minimaalisella Dockerfilella, joka kopioi tarvitut binäärit -perusimagesta ja asentaa vain välttämättömät paketit. +CI-kontin build-workflow'n template: [skills/ci-container-build/SKILL.md](../ci-container-build/SKILL.md) — sisältää +valmiin `ci-container-build-.yml`-pohjan jossa `workflow_dispatch`-tuki manuaaliajoon. ## 5. Raporttitasot @@ -174,14 +174,15 @@ Tiedostonimet `.gitea/workflows/`-kansiossa noudattavat yhtenäistä rakennetta, tiedostot löytyvät nopeasti ja niiden rooli on selvillä: ``` -.ci-feature.yml ← feature-haaran reititin -.ci-main.yml ← main-haaran reititin -..yml ← yksittäinen testi tai operaatio -.gitea-env.conf ← komponenttikohtainen konfiguraatio +.ci-feature.yml ← feature-haaran reititin +.ci-main.yml ← main-haaran reititin +..yml ← yksittäinen testi tai operaatio +.ci-container-build-.yml ← CI-kontin build-workflow +.gitea-env.conf ← komponenttikohtainen konfiguraatio ``` Single repossa `` jätetään pois — tiedostot ovat suoraan `ci-feature.yml`, -`ci-main.yml`, `.yml`. +`ci-main.yml`, `.yml`, `ci-container-build-.yml`. Monorepossa prefiksi pitää komponentin tiedostot yhdessä: `ls .*` löytää kaikki kerralla.