feature/docker-build-arg
CI Feature / Load example-gitea-env.conf to pipeline env (push) Successful in 17s
unit-tests Bats test report
CI Feature / Bats tests (push) Successful in 1m12s
acc-tests Cucumber test report
CI Feature / Cucumber tests (push) Successful in 1m19s
CI Feature / Report Summary (push) Successful in 4s

This commit is contained in:
moilanik
2026-06-28 13:03:40 +03:00
parent f3abd42f17
commit bea0b5cfae
4 changed files with 39 additions and 1 deletions
+14 -1
View File
@@ -8,6 +8,9 @@ on:
version: version:
required: true required: true
type: string type: string
build_args:
required: false
type: string
secrets: secrets:
GITEA_TOKEN: GITEA_TOKEN:
required: true required: true
@@ -44,6 +47,7 @@ jobs:
env: env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME || github.actor }} DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME || github.actor }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
BUILD_ARGS_INPUT: ${{ inputs.build_args }}
run: | run: |
if [ -z "${DOCKER_REGISTRY}" ]; then echo "ERROR: DOCKER_REGISTRY not set in env.conf"; exit 1; fi if [ -z "${DOCKER_REGISTRY}" ]; then echo "ERROR: DOCKER_REGISTRY not set in env.conf"; exit 1; fi
if [ -z "${DOCKER_IMAGE_NAME}" ]; then echo "ERROR: DOCKER_IMAGE_NAME not set in env.conf"; exit 1; fi if [ -z "${DOCKER_IMAGE_NAME}" ]; then echo "ERROR: DOCKER_IMAGE_NAME not set in env.conf"; exit 1; fi
@@ -51,9 +55,18 @@ jobs:
IMAGE="${DOCKER_IMAGE_NAME}" IMAGE="${DOCKER_IMAGE_NAME}"
REGISTRY_HOST="${REGISTRY%%/*}" REGISTRY_HOST="${REGISTRY%%/*}"
BUILD_ARGS=""
if [ -n "$BUILD_ARGS_INPUT" ]; then
while IFS= read -r arg; do
[ -n "$arg" ] && BUILD_ARGS="$BUILD_ARGS --build-arg $arg"
done <<EOF
$BUILD_ARGS_INPUT
EOF
fi
NOW=$(date -u +%Y-%m-%dT%H:%M:%SZ) NOW=$(date -u +%Y-%m-%dT%H:%M:%SZ)
CONTEXT_DIR=$(dirname "${DOCKERFILE}") CONTEXT_DIR=$(dirname "${DOCKERFILE}")
docker build \ docker build $BUILD_ARGS \
--label "git.commit=${{ github.sha }}" \ --label "git.commit=${{ github.sha }}" \
--label "git.commitBy=${{ github.actor }}" \ --label "git.commitBy=${{ github.actor }}" \
--label "build.date=${NOW}" \ --label "build.date=${NOW}" \
+3
View File
@@ -48,6 +48,9 @@ jobs:
with: with:
env_json: ${{ needs.load-config.outputs.env_json }} env_json: ${{ needs.load-config.outputs.env_json }}
version: ${{ needs.check-version.outputs.version }} version: ${{ needs.check-version.outputs.version }}
build_args: |
VERSION=${{ needs.check-version.outputs.version }}
FOO=bar
docker-gitops: docker-gitops:
name: GitOps name: GitOps
+3
View File
@@ -1 +1,4 @@
FROM alpine:latest FROM alpine:latest
ARG VERSION=unknown
ARG FOO=unknown
RUN mkdir -p /app && echo "$VERSION" > /app/version.txt && echo "$FOO" > /app/foo.txt
+19
View File
@@ -345,6 +345,14 @@ DOCKER_REGISTRY: gitea.app.keskikuja.site/niko
DOCKER_IMAGE_NAME: my-app DOCKER_IMAGE_NAME: my-app
``` ```
**Inputit:**
| Parametri | Pakollinen | Kuvaus |
|-----------|------------|--------|
| `env_json` | Kyllä | Konffi `gitea-env.conf`:stä |
| `version` | Kyllä | Version string (check-version output) |
| `build_args` | Ei | Monirivinen KEY=VALUE-lista välitettynä `--build-arg`-lipuiksi `docker build` -komennolle |
**Käyttö reitittimessä:** **Käyttö reitittimessä:**
```yaml ```yaml
@@ -356,8 +364,19 @@ docker-build-push:
with: with:
env_json: ${{ needs.load-config.outputs.env_json }} env_json: ${{ needs.load-config.outputs.env_json }}
version: ${{ needs.check-version.outputs.version }} version: ${{ needs.check-version.outputs.version }}
build_args: |
VERSION=${{ needs.check-version.outputs.version }}
``` ```
**Dockerfilessä** ARG otetaan vastaan oletusarvolla ja kirjoitetaan tiedostoksi:
```dockerfile
ARG VERSION=unknown
RUN mkdir -p /app && echo "$VERSION" > /app/version.txt
```
Katso referenssi: repon juuren `Dockerfile` (`gitea-ci-library/Dockerfile`).
Tarkka input/secret-lista: `docs/workflows.md`. Tarkka input/secret-lista: `docs/workflows.md`.
### `helm-build-push.yml` — Helm chart build & push ### `helm-build-push.yml` — Helm chart build & push