docker ja helm build context root monorepo ja in folder build
CI Feature / Load example-gitea-env.conf to pipeline env (push) Successful in 33s
unit-tests Bats test report
acc-tests Cucumber test report
CI Feature / Cucumber tests (push) Successful in 1m34s
CI Feature / Bats tests (push) Successful in 1m35s
CI Feature / Report Summary (push) Successful in 6s
CI Feature / Load example-gitea-env.conf to pipeline env (push) Successful in 33s
unit-tests Bats test report
acc-tests Cucumber test report
CI Feature / Cucumber tests (push) Successful in 1m34s
CI Feature / Bats tests (push) Successful in 1m35s
CI Feature / Report Summary (push) Successful in 6s
This commit is contained in:
@@ -123,6 +123,88 @@ ajetaan kontin *sisällä* — myös `actions/checkout@v4`. Se on JavaScript-act
|
||||
joka vaatii sekä `nodejs` että `git`. Varmista että CI-kontin Dockerfilessä on
|
||||
molemmat — muuten checkout ei toimi ja pipeline failaa.
|
||||
|
||||
### 4.4 Build-konteksti, `.dockerignore` ja `COPY`
|
||||
|
||||
**Build-konteksti** on aina tiedoston (Dockerfile, Chart.yaml) oman hakemiston
|
||||
juuri (`dirname "${DOCKERFILE}"` / `dirname "${CHART_FILE}"`). Kaikki
|
||||
suhteelliset polut — ignore-tiedosto, `COPY`, `ADD` — ovat suhteessa tähän
|
||||
kontekstiin.
|
||||
|
||||
| Tiedosto | Konteksti | Ignore-tiedosto | Käyttö |
|
||||
|---|---|---|---|
|
||||
| `Dockerfile` | `.` | `./.dockerignore` | `docker build` / `COPY src/ src/` |
|
||||
| `api/Dockerfile` | `api/` | `api/.dockerignore` | `docker build` / `COPY src/ src/` |
|
||||
| `Chart.yaml` (`VERSION_FILE`) | `.` | `./.helmignore` | `helm package` |
|
||||
| `api/Chart.yaml` (`VERSION_FILE`) | `api/` | `api/.helmignore` | `helm package` |
|
||||
|
||||
Helm chartin polku luetaan confin `VERSION_FILE`-kentästä — sama rivi jota
|
||||
`check-version.yml` käyttää version lähteenä. Yksi conf-rivi ohjaa molempia:
|
||||
sekä versionlaskentaa että chartin sijaintia.
|
||||
|
||||
**Mitä ignore-tiedosto sisältää:** Kaikki mikä EI ole konttiin tai chart-pakettiin
|
||||
tarkoitettua koodia tai resurssia, ON oltava ignore-tiedostossa:
|
||||
|
||||
- Git- ja CI-historia (`.git/`, `.gitea/`, `.github/`)
|
||||
- Testikoodi, testidata, testiraportit (`tests/`, `reports/`, `coverage/`)
|
||||
- Dokumentaatio (`docs/`, `guides/`, `*.md`, `CHANGELOG`, `README`)
|
||||
- Editori- ja työkalukonfiguraatio (`.vscode/`, `.cursor/`, `.idea/`, `.DS_Store`)
|
||||
- Riippuvuudet jotka asennetaan Dockerfilessä (`node_modules/`)
|
||||
- Väliaikaistiedostot (`tmp/`, `*.log`)
|
||||
- Projektikohtaiset konfiguraatiot (`.env`, `*.conf`, `CURRENT_PROVIDER_VERSION`)
|
||||
|
||||
**Miksi:** Build-kontekstin koko vaikuttaa suoraan `docker build` -nopeuteen.
|
||||
Raskas konteksti (etenkin `.git/` ja `node_modules/`) hidastaa buildia ja
|
||||
kuluttaa runnerin resursseja turhaan. Ylimääräiset tiedostot kontissa ovat
|
||||
**tietoturvariski** — tokenit, `.env` ja sensitiivinen data voivat päätyä
|
||||
kontin layeriin jos `.dockerignore` ei ole kattava.
|
||||
|
||||
### 4.5 `COPY`-kuri — kopioi vain tarvittava
|
||||
|
||||
`COPY . .` on kielletty. Jokainen `COPY` kopioi vain tarvittavat tiedostot
|
||||
tai hakemistot:
|
||||
|
||||
```dockerfile
|
||||
# VÄÄRIN
|
||||
COPY . .
|
||||
|
||||
# OIKEIN
|
||||
COPY package.json package-lock.json ./
|
||||
COPY src/ src/
|
||||
COPY public/ public/
|
||||
```
|
||||
|
||||
**Miksi:**
|
||||
- Layer-cache: `COPY . .` rikkoo välimuistin — mikä tahansa muutos
|
||||
tiedostossa tyhjentää koko layerin
|
||||
- Tietoturva: konttiin voi päätyä ylimääräisiä tiedostoja vaikka
|
||||
`.dockerignore` olisi kattava (unohtunut ignore-rivi, uusi työkalu
|
||||
joka luo tiedostoja build-kontekstiin)
|
||||
- Luettavuus: `COPY . .` ei kerro mitä kontti todella sisältää
|
||||
- Kontin koko: eksplisiittinen `COPY` pitää image-koon kurissa
|
||||
|
||||
### 4.6 `.helmignore` — pidä chart-paketti siistinä
|
||||
|
||||
`helm package` käyttää `.helmignore`-tiedostoa samalla periaatteella kuin
|
||||
`docker build` käyttää `.dockerignore`a:
|
||||
|
||||
- Chart-hakemisto luetaan confin `VERSION_FILE`-kentästä (`dirname "${VERSION_FILE}"`)
|
||||
- ignore-tiedosto luetaan chart-hakemiston juuresta (sama konteksti kuin
|
||||
`Chart.yaml`, ks. 4.4)
|
||||
- Kaikki turha (testit, docs, git, CI-konffit, kuvat) on poissuljettava
|
||||
- Jos `.helmignore` puuttuu, `helm package` paketoi mukaan kaikki
|
||||
chart-hakemiston tiedostot — turhaa bulkkia registryyn
|
||||
|
||||
**`.helmignore` on pakollinen** jokaiselle chartille. Minimisisältö:
|
||||
|
||||
```
|
||||
.git/
|
||||
.gitignore
|
||||
tests/
|
||||
docs/
|
||||
*.md
|
||||
.DS_Store
|
||||
```
|
||||
|
||||
## 5. Raporttitasot
|
||||
|
||||
Testi tuottaa raportin `reports/<suite>/`-hakemistoon. Yksi `ci-report.sh`-kutsu hoitaa sekä
|
||||
@@ -257,6 +339,7 @@ Pakkaa ja pushee Helm-chartin OCI-registryyn. Käyttää `alpine/helm`-konttia.
|
||||
|
||||
```yaml
|
||||
HELM_REGISTRY: gitea.app.keskikuja.site/niko
|
||||
VERSION_FILE: platform-helm/Chart.yaml # chart-hakemisto + versionlähde
|
||||
```
|
||||
|
||||
**Käyttö reitittimessä:**
|
||||
@@ -270,20 +353,163 @@ helm-build-push:
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
version: ${{ needs.check-version.outputs.version }}
|
||||
# chart_path: '.' # oletus, vaihda jos Chart.yaml on alihakemistossa
|
||||
```
|
||||
|
||||
**Vanhentunut käytäntö:** Nykyinen `helm-build-push.yml` asentaa node.js:n
|
||||
lennossa `apk add --no-cache nodejs` ennen checkouttia — tämä rikkoo
|
||||
Offline Container -vaatimusta (4.1).
|
||||
|
||||
**Korjaustoimenpide:** Rakenna custom CI-kontti `ci-container-build`-skillillä
|
||||
jossa on helm + nodejs + git (katso pre-cache-esimerkit `REFERENCE.md`:stä),
|
||||
päivitä workflow'n `container: image:` osoittamaan omaan konttiin, ja poista
|
||||
runtime-apk.
|
||||
Chart-hakemisto johdetaan `VERSION_FILE`-polusta: `dirname "${VERSION_FILE}"`.
|
||||
Jos `VERSION_FILE` on `Chart.yaml`, konteksti on juuri. Jos `platform-helm/Chart.yaml`,
|
||||
konteksti on `platform-helm/`.
|
||||
|
||||
**Yksittäisten Helm-UI-linkkien raportointi:** `HELM_UI_URL` on
|
||||
tarkoitettu yleiselle registry UI:lle — provider muodostaa linkin
|
||||
`${HELM_UI_URL}/${CHART_NAME}/${VERSION}` automaattisesti.
|
||||
|
||||
Tarkka input/secret-lista: `docs/workflows.md`.
|
||||
|
||||
## 11. Multi-artifact monorepo -komponentti
|
||||
|
||||
Yksi monorepo-komponentti voi tuottaa useita artefakteja (esim. Docker image
|
||||
+ Helm chart). Kukin artefakti on **omassa reitittimessään** — ei yhtä
|
||||
monoliittista pipelinea. Tämä on tietoinen arkkitehtuurivalinta:
|
||||
|
||||
- Reitittimet ovat itsenäisiä: eri `paths:`-triggerit, eri tagit, eri confit
|
||||
- Yksi commit voi triggeröidä molemmat rinnakkain
|
||||
- Yhden artefaktin build tai testi ei estä toista
|
||||
|
||||
### Esimerkki: `platform-helm` joka tuottaa Docker-imagen ja Helm chartin
|
||||
|
||||
```
|
||||
.gitea/workflows/
|
||||
├── platform-helm.ci-main.yml # Docker build & push
|
||||
├── platform-helm.gitea-env.conf # Docker-konffi
|
||||
├── platform-helm.helm-ci-main.yml # Helm build & push
|
||||
├── platform-helm.helm-gitea-env.conf # Helm-konffi
|
||||
├── platform-helm.helm-chart-lint.yml # Chart-testi
|
||||
└── platform-helm.ci-container-build-helm.yml # CI-kontin build
|
||||
```
|
||||
|
||||
### `platform-helm.gitea-env.conf` (Docker)
|
||||
|
||||
```ini
|
||||
DOCKER_REGISTRY=gitea.app.keskikuja.site/niko
|
||||
DOCKER_IMAGE_NAME=platform-helm
|
||||
GIT_TAG_PREFIX=platform-helm/
|
||||
```
|
||||
|
||||
### `platform-helm.helm-gitea-env.conf` (Helm)
|
||||
|
||||
```ini
|
||||
HELM_REGISTRY=gitea.app.keskikuja.site/niko
|
||||
VERSION_FILE=platform-helm/Chart.yaml
|
||||
GIT_TAG_PREFIX=chart/
|
||||
```
|
||||
|
||||
### Reitittimet
|
||||
|
||||
**`platform-helm.ci-main.yml`** — Docker-buildi, testit, oma tagi:
|
||||
|
||||
```yaml
|
||||
name: platform-helm CI Main
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- platform-helm/**
|
||||
- .gitea/workflows/platform-helm.*
|
||||
|
||||
jobs:
|
||||
load-config:
|
||||
uses: OWNER/gitea-ci-library/.gitea/workflows/config-provider.yml@v1
|
||||
secrets: inherit
|
||||
with:
|
||||
config_path: .gitea/workflows/platform-helm.gitea-env.conf
|
||||
|
||||
check-version:
|
||||
needs: [load-config]
|
||||
uses: OWNER/gitea-ci-library/.gitea/workflows/check-version.yml@v1
|
||||
secrets: inherit
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
|
||||
test:
|
||||
needs: [load-config, check-version]
|
||||
uses: ./.gitea/workflows/platform-helm.sbom-lint.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
|
||||
build-push:
|
||||
needs: [load-config, check-version, test]
|
||||
if: needs.check-version.outputs.artifact_exists == 'false'
|
||||
uses: OWNER/gitea-ci-library/.gitea/workflows/docker-build-push.yml@v1
|
||||
secrets: inherit
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
version: ${{ needs.check-version.outputs.version }}
|
||||
|
||||
report-summary:
|
||||
needs: [load-config, test, build-push]
|
||||
if: always()
|
||||
uses: OWNER/gitea-ci-library/.gitea/workflows/report-summary.yml@v1
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
suites: ''
|
||||
```
|
||||
|
||||
**`platform-helm.helm-ci-main.yml`** — Helm-buildi, chart-testi, oma tagi:
|
||||
|
||||
```yaml
|
||||
name: platform-helm Helm CI Main
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- platform-helm/**
|
||||
- .gitea/workflows/platform-helm.helm*
|
||||
|
||||
jobs:
|
||||
load-config:
|
||||
uses: OWNER/gitea-ci-library/.gitea/workflows/config-provider.yml@v1
|
||||
secrets: inherit
|
||||
with:
|
||||
config_path: .gitea/workflows/platform-helm.helm-gitea-env.conf
|
||||
|
||||
check-version:
|
||||
needs: [load-config]
|
||||
uses: OWNER/gitea-ci-library/.gitea/workflows/check-version.yml@v1
|
||||
secrets: inherit
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
|
||||
chart-lint:
|
||||
needs: [load-config, check-version]
|
||||
uses: ./.gitea/workflows/platform-helm.helm-chart-lint.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
|
||||
helm-build-push:
|
||||
needs: [load-config, check-version, chart-lint]
|
||||
if: needs.check-version.outputs.artifact_exists == 'false'
|
||||
uses: OWNER/gitea-ci-library/.gitea/workflows/helm-build-push.yml@v1
|
||||
secrets: inherit
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
version: ${{ needs.check-version.outputs.version }}
|
||||
|
||||
report-summary:
|
||||
needs: [load-config, chart-lint, helm-build-push]
|
||||
if: always()
|
||||
uses: OWNER/gitea-ci-library/.gitea/workflows/report-summary.yml@v1
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
suites: ''
|
||||
```
|
||||
|
||||
### Säännöt
|
||||
|
||||
- Jokaisella artefaktilla on oma reititin, oma conf, omat testit
|
||||
- Conf-tiedoston nimi erottaa artefaktit: `<komponentti>.gitea-env.conf` vs
|
||||
`<komponentti>.helm-gitea-env.conf`
|
||||
- `<komponentti>.helm-`-prefiksi erottaa Helm-artefaktin tiedostot
|
||||
- `GIT_TAG_PREFIX` pitää tagit erillään: `platform-helm/1.2.3` vs `chart/1.2.3`
|
||||
- Molemmat reitittimet voivat triggeröityä samasta commitista
|
||||
|
||||
Reference in New Issue
Block a user