ci: probe the two-architecture build (throw-away branch)
This commit is contained in:
parent
dae5118354
commit
a2f8993601
3 changed files with 77 additions and 98 deletions
56
.forgejo/workflows/probe-arm.yml
Normal file
56
.forgejo/workflows/probe-arm.yml
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
name: probe-arm
|
||||
on:
|
||||
push:
|
||||
branches: [ci/probe-arm]
|
||||
jobs:
|
||||
# One image for each architecture, each built by kaniko for its own: the Go program crosses to the other one with no
|
||||
# emulation, and the last stage of the Dockerfile runs no command (see the Dockerfile).
|
||||
image:
|
||||
runs-on: docker
|
||||
strategy:
|
||||
matrix:
|
||||
arch: [amd64, arm64]
|
||||
container:
|
||||
image: gcr.io/kaniko-project/executor:v1.23.2-debug
|
||||
steps:
|
||||
- name: Build the image from the tag and push it as X.Y.Z-ARCH
|
||||
env:
|
||||
VERSION: probe
|
||||
ARCH: ${{ matrix.arch }}
|
||||
REGISTRY_USER: squid
|
||||
REGISTRY_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
||||
run: |
|
||||
set -eu
|
||||
mkdir -p /kaniko/.docker
|
||||
auth="$(printf '%s:%s' "$REGISTRY_USER" "$REGISTRY_TOKEN" | base64 | tr -d '\n')"
|
||||
printf '{"auths":{"git.kmalloc.org":{"auth":"%s"}}}' "$auth" > /kaniko/.docker/config.json
|
||||
/kaniko/executor \
|
||||
--custom-platform "linux/${ARCH}" \
|
||||
--dockerfile Dockerfile \
|
||||
--context "git://git.kmalloc.org/squid/sonda.git#refs/heads/ci/probe-arm" \
|
||||
--build-arg "VERSION=${VERSION}" \
|
||||
--label "org.opencontainers.image.version=${VERSION}" \
|
||||
--destination "git.kmalloc.org/squid/sonda:${VERSION}-${ARCH}" \
|
||||
--verbosity info
|
||||
|
||||
# The tags that people use (X.Y.Z, X.Y, latest) point at a list of the two images, so that each machine takes its own.
|
||||
manifest:
|
||||
needs: [image]
|
||||
runs-on: docker
|
||||
container:
|
||||
image: gcr.io/go-containerregistry/crane:debug
|
||||
steps:
|
||||
- name: Join the images under X.Y.Z, X.Y and latest
|
||||
env:
|
||||
VERSION: probe
|
||||
REGISTRY_USER: squid
|
||||
REGISTRY_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
||||
run: |
|
||||
set -eu
|
||||
image=git.kmalloc.org/squid/sonda
|
||||
crane auth login git.kmalloc.org -u "$REGISTRY_USER" -p "$REGISTRY_TOKEN"
|
||||
crane index append \
|
||||
--tag "${image}:${VERSION}" \
|
||||
--manifest "${image}:${VERSION}-amd64" \
|
||||
--manifest "${image}:${VERSION}-arm64"
|
||||
crane tag "${image}:${VERSION}" probe-latest
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
# What happens at every merge into main:
|
||||
# 1. semantic-release reads the commits since the last release (Conventional Commits), works out the next version,
|
||||
# writes CHANGELOG.md, makes the release on the forge and tags it. A merge with nothing to release (docs, tests, ci)
|
||||
# makes none.
|
||||
# 2. When there is a release, the image is built from the tag and pushed to git.kmalloc.org/squid/sonda as
|
||||
# X.Y.Z, X.Y and latest.
|
||||
# The runner has no Docker, so the image is built with kaniko, which needs no daemon.
|
||||
# Secret needed: FORGEJO_TOKEN, a token of the owner with the scopes write:repository and write:package.
|
||||
name: release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
# One release at a time: two merges close together must not make two versions at once.
|
||||
concurrency:
|
||||
group: release
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: docker
|
||||
# The commit that the release makes (CHANGELOG.md) says [skip ci]; this is the belt for those braces.
|
||||
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
|
||||
outputs:
|
||||
version: ${{ steps.version.outputs.version }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # the whole history: the next version depends on every commit since the last tag
|
||||
token: ${{ secrets.FORGEJO_TOKEN }}
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 24
|
||||
- name: Release
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
||||
GITEA_URL: https://git.kmalloc.org
|
||||
GIT_AUTHOR_NAME: sonda-release
|
||||
GIT_AUTHOR_EMAIL: squid@kmalloc.org
|
||||
GIT_COMMITTER_NAME: sonda-release
|
||||
GIT_COMMITTER_EMAIL: squid@kmalloc.org
|
||||
run: >
|
||||
npx --yes
|
||||
-p semantic-release@25
|
||||
-p @semantic-release/commit-analyzer@13.0.1
|
||||
-p @semantic-release/release-notes-generator@14.1.1
|
||||
-p @semantic-release/changelog@7.0.0
|
||||
-p @semantic-release/git@11.0.1
|
||||
-p conventional-changelog-conventionalcommits@8.0.0
|
||||
-p @saithodev/semantic-release-gitea@2.1.0
|
||||
semantic-release
|
||||
- name: Which version was made, if any
|
||||
id: version
|
||||
run: |
|
||||
# The tag of a release points at the commit the release made, which is where the checkout now is.
|
||||
tag="$(git tag --points-at HEAD | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1 || true)"
|
||||
echo "version=${tag#v}" >> "$GITHUB_OUTPUT"
|
||||
echo "released: ${tag:-nothing}"
|
||||
|
||||
image:
|
||||
needs: release
|
||||
if: ${{ needs.release.outputs.version != '' }}
|
||||
runs-on: docker
|
||||
container:
|
||||
image: gcr.io/kaniko-project/executor:v1.23.2-debug
|
||||
steps:
|
||||
- name: Build the image from the tag and push it
|
||||
env:
|
||||
VERSION: ${{ needs.release.outputs.version }}
|
||||
REGISTRY_USER: squid
|
||||
REGISTRY_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
||||
run: |
|
||||
set -eu
|
||||
mkdir -p /kaniko/.docker
|
||||
auth="$(printf '%s:%s' "$REGISTRY_USER" "$REGISTRY_TOKEN" | base64 | tr -d '\n')"
|
||||
printf '{"auths":{"git.kmalloc.org":{"auth":"%s"}}}' "$auth" > /kaniko/.docker/config.json
|
||||
image=git.kmalloc.org/squid/sonda
|
||||
minor="${VERSION%.*}"
|
||||
/kaniko/executor \
|
||||
--dockerfile Dockerfile \
|
||||
--context "git://git.kmalloc.org/squid/sonda.git#refs/tags/v${VERSION}" \
|
||||
--build-arg "VERSION=${VERSION}" \
|
||||
--label "org.opencontainers.image.version=${VERSION}" \
|
||||
--destination "${image}:${VERSION}" \
|
||||
--destination "${image}:${minor}" \
|
||||
--destination "${image}:latest" \
|
||||
--verbosity info
|
||||
31
Dockerfile
31
Dockerfile
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
# The web app: built once here, written (by its Vite config) to /src/internal/webui/dist, where the Go
|
||||
# build below embeds it. Nothing of Node reaches the final image.
|
||||
FROM node:24-alpine AS web
|
||||
FROM --platform=$BUILDPLATFORM node:24-alpine AS web
|
||||
WORKDIR /src/web
|
||||
COPY web/package.json web/package-lock.json ./
|
||||
RUN npm ci
|
||||
|
|
@ -12,7 +12,11 @@ RUN npm run build
|
|||
# Build: Sonda has no CGO (SQLite, PostgreSQL and the tag reader are pure Go), so the binary
|
||||
# is static and the final image needs nothing but it and the CA certificates. The web app is inside it
|
||||
# (-tags webui), so sondad serves it on / and the API on /api.
|
||||
FROM golang:1.27-alpine AS build
|
||||
FROM --platform=$BUILDPLATFORM golang:1.27-alpine AS build
|
||||
# Built on the machine that builds, for the machine that runs: Go crosses to another architecture with no emulation
|
||||
# (TARGETOS and TARGETARCH come from the platform asked for).
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
WORKDIR /src
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
|
@ -22,19 +26,26 @@ COPY migrations ./migrations
|
|||
COPY --from=web /src/internal/webui/dist ./internal/webui/dist
|
||||
# The version of the release (see .releaserc.json), as GET /version and the User-Agent of the providers say it.
|
||||
ARG VERSION=dev
|
||||
RUN CGO_ENABLED=0 go build -tags webui -trimpath -ldflags="-s -w -X main.version=${VERSION}" -o /out/sondad ./cmd/sondad
|
||||
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} go build -tags webui -trimpath -ldflags="-s -w -X main.version=${VERSION}" -o /out/sondad ./cmd/sondad
|
||||
|
||||
# What the image has besides the program (the zones of tzdata, the user, the folders) is made here, on the machine that
|
||||
# builds. The last stage then runs no command, so it can be built for another architecture with no emulation.
|
||||
FROM --platform=$BUILDPLATFORM alpine:3.22 AS rootfs
|
||||
RUN apk add --no-cache tzdata \
|
||||
&& addgroup -S -g 10001 sonda \
|
||||
&& adduser -S -u 10001 -G sonda -h /data -H sonda \
|
||||
&& mkdir -p /out/data /out/music
|
||||
|
||||
FROM alpine:3.22
|
||||
LABEL org.opencontainers.image.title="Sonda" \
|
||||
org.opencontainers.image.description="A privacy-first, self-hosted music server" \
|
||||
org.opencontainers.image.source="https://git.kmalloc.org/squid/sonda"
|
||||
# ca-certificates: the providers an admin may switch on are reached over https.
|
||||
# tzdata: log times in the zone the operator sets with TZ.
|
||||
RUN apk add --no-cache ca-certificates tzdata \
|
||||
&& addgroup -S -g 10001 sonda \
|
||||
&& adduser -S -u 10001 -G sonda -h /data -H sonda \
|
||||
&& mkdir -p /data /music \
|
||||
&& chown sonda:sonda /data
|
||||
# The certificates of alpine (ca-certificates-bundle) are what the providers an admin may switch on are reached with,
|
||||
# over https. tzdata is for the log times in the zone the operator sets with TZ.
|
||||
COPY --from=rootfs /usr/share/zoneinfo /usr/share/zoneinfo
|
||||
COPY --from=rootfs /etc/passwd /etc/group /etc/shadow /etc/
|
||||
COPY --from=rootfs --chown=10001:10001 /out/data /data
|
||||
COPY --from=rootfs /out/music /music
|
||||
COPY --from=build /out/sondad /usr/local/bin/sondad
|
||||
|
||||
# Everything Sonda writes is under /data: the database and the files it makes (covers, pictures).
|
||||
|
|
|
|||
Loading…
Reference in a new issue