diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 781d06d..6d9175a 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -10,6 +10,8 @@ on: pull_request: env: + REGISTRY: gitea.tap-tap.win + IMAGE_NAME: taptap/audiomanager # Built by scripts/build-ci-image.sh from ci/Dockerfile. Bump the tag when # ci/Dockerfile changes. CI_IMAGE: gitea.tap-tap.win/taptap/audiomanager-ci:2 @@ -36,3 +38,51 @@ jobs: run: | helm lint charts/musicmanager helm template musicmanager charts/musicmanager --set users.existingSecret=test > /dev/null + + image: + needs: + - test + - chart + if: github.event_name == 'push' + runs-on: ubuntu-latest + container: + image: gitea.tap-tap.win/taptap/audiomanager-ci:2 + permissions: + contents: read + packages: write + env: + # A multi-stage build replaces / with the last stage's root filesystem, + # which deletes $HOME/.docker/config.json. Kaniko then has no credentials + # left for the push and gets an anonymous registry token (Gitea reports + # this as "401 reqPackageAccess"). /kaniko is preserved by kaniko, so + # keep the Docker credential store there for the whole job. + DOCKER_CONFIG: /kaniko/.docker + steps: + - uses: actions/checkout@v4 + - name: Log in to the registry + run: | + mkdir -p "$DOCKER_CONFIG" + echo "${{ secrets.AUDIOMANAGER_REGISTRY_TOKEN }}" \ + | docker login "$REGISTRY" \ + --username "${{ gitea.actor }}" \ + --password-stdin + - name: Build and push + run: | + set -euo pipefail + tags=("$REGISTRY/$IMAGE_NAME:sha-${GITHUB_SHA::7}") + if [[ "$GITHUB_REF" == refs/tags/* ]]; then + tags+=("$REGISTRY/$IMAGE_NAME:${GITHUB_REF_NAME}") + else + tags+=("$REGISTRY/$IMAGE_NAME:latest") + fi + + destinations=() + for tag in "${tags[@]}"; do + destinations+=(--destination "$tag") + done + + kaniko-executor \ + --context="dir://$PWD" \ + --dockerfile="$PWD/Dockerfile" \ + --snapshot-mode=redo \ + "${destinations[@]}" diff --git a/README.md b/README.md index 8df5d5f..91c4201 100644 --- a/README.md +++ b/README.md @@ -630,9 +630,15 @@ Cover extraction order: embedded APIC frame -> `cover.jpg`/`folder.jpg`/`front.j - Runtime flags: `-XX:+UseSerialGC -Xmx256m` (adjustable via Helm). - Non-root user (UID 10001), read-only root filesystem, `/tmp` as `emptyDir`, `/data` as PVC. - Image: `gitea.tap-tap.win/taptap/audiomanager:` (registry paths must be lowercase). -- Images are built and pushed from a trusted machine, not from Gitea Actions; `imagePullSecret` is provided by the cluster. +- Gitea Actions builds and pushes `:sha-` and `:latest` on `main`, and the tag name for `v*` tags; `imagePullSecret` is provided by the cluster. -Build and push the image: +The CI image job uses kaniko and keeps `DOCKER_CONFIG=/kaniko/.docker` for the +whole job. A multi-stage build replaces `/` with the last stage's root +filesystem, which deletes `$HOME/.docker/config.json`; without this setting +kaniko would push anonymously and Gitea would reject it with +`401 reqPackageAccess`. + +To build and push manually (or to deploy from a workstation): ```bash docker login gitea.tap-tap.win @@ -641,12 +647,6 @@ scripts/release.sh --tag v1.0.0 # explicit tag scripts/release.sh --deploy # also apply the users secret and helm upgrade ``` -`.gitea/workflows/ci.yaml` only runs the test suite, the smoke script and the Helm -chart lint. Image builds do not run in CI because the Gitea registry rejects -pushes from job containers (`401 Unauthorized: reqPackageAccess`), while the same -credentials work from a normal machine. Releases therefore stay a deliberate local -step; `scripts/release.sh --deploy` covers build, push and `helm upgrade`. - ### 9.2 Helm chart `charts/musicmanager` renders: diff --git a/scripts/release.sh b/scripts/release.sh index 5acfc97..795d0e4 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -3,9 +3,9 @@ # Builds and pushes the application image from the local machine, and can # optionally deploy the Helm chart to the current kube context. # -# Image pushes intentionally do not run in Gitea Actions: kaniko inside the job -# container was rejected by the registry with 401 reqPackageAccess, while the -# same credentials work from here. +# CI also builds and pushes the image (see .gitea/workflows/ci.yaml). This +# script is the local alternative, mainly for releases that also deploy with +# --deploy. set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"