diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 3d57e8f..a12b5bb 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -10,29 +10,29 @@ on: env: REGISTRY: gitea.tap-tap.win - IMAGE_NAME: tap-tap/audiomanager + 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:1 jobs: test: runs-on: ubuntu-latest + container: + image: gitea.tap-tap.win/taptap/audiomanager-ci:1 steps: - uses: actions/checkout@v4 - - uses: actions/setup-java@v4 - with: - distribution: temurin - java-version: "21" - - name: Install ffmpeg and sqlite - run: sudo apt-get update && sudo apt-get install -y ffmpeg sqlite3 - name: Test - run: ./gradlew test --console=plain + run: gradle test --console=plain - name: Smoke test - run: ./scripts/smoke.sh + run: GRADLE=gradle ./scripts/smoke.sh chart: runs-on: ubuntu-latest + container: + image: gitea.tap-tap.win/taptap/audiomanager-ci:1 steps: - uses: actions/checkout@v4 - - uses: azure/setup-helm@v4 - name: Lint and render the chart run: | helm lint charts/musicmanager @@ -47,34 +47,35 @@ jobs: # The runner executes jobs in containers; expose its Docker daemon so the # image build works without a separate DinD service. container: - image: catthehacker/ubuntu:act-latest + image: gitea.tap-tap.win/taptap/audiomanager-ci:1 options: --volume /var/run/docker.sock:/var/run/docker.sock permissions: contents: read packages: write steps: - uses: actions/checkout@v4 - - uses: docker/setup-buildx-action@v3 - name: Log in to the registry - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ secrets.REGISTRY_USERNAME || gitea.actor }} - password: ${{ secrets.REGISTRY_PASSWORD || secrets.GITEA_TOKEN }} - - name: Image metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: | - type=ref,event=branch - type=ref,event=tag - type=sha - type=raw,value=latest,enable={{is_default_branch}} + run: | + echo "${{ secrets.REGISTRY_PASSWORD || secrets.GITEA_TOKEN }}" \ + | docker login "$REGISTRY" \ + --username "${{ secrets.REGISTRY_USERNAME || gitea.actor }}" \ + --password-stdin - name: Build and push - uses: docker/build-push-action@v6 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + 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 + + build_args=() + for tag in "${tags[@]}"; do + build_args+=(-t "$tag") + done + + docker build "${build_args[@]}" . + for tag in "${tags[@]}"; do + docker push "$tag" + done diff --git a/README.md b/README.md index b44c6fc..d0510c8 100644 --- a/README.md +++ b/README.md @@ -629,13 +629,13 @@ Cover extraction order: embedded APIC frame -> `cover.jpg`/`folder.jpg`/`front.j - Multi-stage Dockerfile: Gradle build -> glibc-based `eclipse-temurin:21-jre-jammy` with `ffmpeg` installed (Alpine/musl is unsupported by sqlite-jdbc's bundled native library). - 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/tap-tap/audiomanager:` (registry paths must be lowercase). +- Image: `gitea.tap-tap.win/taptap/audiomanager:` (registry paths must be lowercase). - Gitea Actions builds and pushes on tags; `imagePullSecret` is provided by the cluster. Build the image locally: ```bash -docker build -t gitea.tap-tap.win/tap-tap/audiomanager:dev . +docker build -t gitea.tap-tap.win/taptap/audiomanager:dev . ``` `.gitea/workflows/ci.yaml` runs tests and the smoke script, then builds and pushes @@ -731,7 +731,7 @@ Verify each step with `./gradlew test` and/or `curl`: ## 12. Open Items / Assumptions -1. **Gitea registry path:** image assumed to be `gitea.tap-tap.win/tap-tap/audiomanager` (lowercased repo `TapTap/AudioManager`). +1. **Gitea registry path:** image is `gitea.tap-tap.win/taptap/audiomanager` (lowercased package owner `taptap`). 2. **Vault layout:** the chart expects a secret with a `users.yaml` key. Exact Vault path/agent template is deployment-side and not part of the app. 3. **Per-user music roots:** Vault/config must contain one folder entry per user root (e.g. `/mnt/media/music/`); there is no implicit path convention. 4. **hostPath without pinning:** requires `/mnt/media/music` and `/mnt/media/longform` to exist on every node that can schedule the pod. Add a `nodeSelector` later if that changes. diff --git a/charts/musicmanager/values.yaml b/charts/musicmanager/values.yaml index e0b2e25..a4e7a0e 100644 --- a/charts/musicmanager/values.yaml +++ b/charts/musicmanager/values.yaml @@ -1,7 +1,7 @@ replicaCount: 1 image: - repository: gitea.tap-tap.win/tap-tap/audiomanager + repository: gitea.tap-tap.win/taptap/audiomanager tag: "" # defaults to appVersion pullPolicy: IfNotPresent diff --git a/ci/Dockerfile b/ci/Dockerfile new file mode 100644 index 0000000..036f327 --- /dev/null +++ b/ci/Dockerfile @@ -0,0 +1,50 @@ +# Image for Gitea Actions jobs. It contains every tool the pipeline needs so +# workflows do not download a JDK or install packages on every run. +# +# Build and push it with scripts/build-ci-image.sh. +FROM gradle:8.14.3-jdk21 + +ARG NODE_VERSION=22.14.0 +ARG DOCKER_VERSION=27.3.1 +ARG HELM_VERSION=3.16.4 + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + git \ + ffmpeg \ + sqlite3 \ + xz-utils \ + && rm -rf /var/lib/apt/lists/* + +# Node is required by actions/checkout and other JavaScript actions executed +# inside the job container. +RUN curl -fsSL "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz" \ + -o /tmp/node.tar.xz \ + && tar -xJf /tmp/node.tar.xz -C /usr/local --strip-components=1 \ + && rm /tmp/node.tar.xz \ + && node --version \ + && npm --version + +# Docker CLI only (the runner mounts its daemon socket into the job). +RUN curl -fsSL "https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_VERSION}.tgz" \ + -o /tmp/docker.tgz \ + && tar -xzf /tmp/docker.tgz -C /tmp \ + && install -m 0755 /tmp/docker/docker /usr/local/bin/docker \ + && rm -rf /tmp/docker /tmp/docker.tgz \ + && docker --version + +RUN curl -fsSL "https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz" \ + -o /tmp/helm.tgz \ + && tar -xzf /tmp/helm.tgz -C /tmp \ + && install -m 0755 /tmp/linux-amd64/helm /usr/local/bin/helm \ + && rm -rf /tmp/helm.tgz /tmp/linux-amd64 \ + && helm version --short + +ENV GRADLE_USER_HOME=/root/.gradle \ + JAVA_HOME=/opt/java/openjdk + +WORKDIR /workspace + +CMD ["sleep", "infinity"] diff --git a/scripts/build-ci-image.sh b/scripts/build-ci-image.sh new file mode 100755 index 0000000..6bac23f --- /dev/null +++ b/scripts/build-ci-image.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# +# Builds and pushes the CI job image used by .gitea/workflows/ci.yaml. +# Run this once after changing ci/Dockerfile, or when dependency versions change. +# +set -euo pipefail + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +IMAGE="${CI_IMAGE:-gitea.tap-tap.win/taptap/audiomanager-ci}" +TAG="${1:-1}" + +docker build -f "$ROOT/ci/Dockerfile" -t "$IMAGE:$TAG" "$ROOT" +docker push "$IMAGE:$TAG" diff --git a/scripts/smoke.sh b/scripts/smoke.sh index 6bbcefd..e719352 100755 --- a/scripts/smoke.sh +++ b/scripts/smoke.sh @@ -9,6 +9,7 @@ set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +GRADLE="${GRADLE:-./gradlew}" WORK="${1:-$(mktemp -d "${TMPDIR:-/tmp}/musicmanager-smoke.XXXXXX")}" PORT="${SMOKE_PORT:-18099}" USER="smoke" @@ -65,7 +66,7 @@ users: EOF log "Building fat JAR..." -(cd "$ROOT" && ./gradlew -q shadowJar) +(cd "$ROOT" && "$GRADLE" -q shadowJar) JAR="$(find "$ROOT/build/libs" -name 'musicmanager-*-all.jar' | head -1)" if [[ -z "$JAR" ]]; then