jorbenzhu on Discord (#feedback, 10-31): "建议 docker镜像 也提供 stable 类tag, 与桌面版保持同步的稳定版发布". The desktop app's Stable channel is chosen in site/worker.js (stableOf: once a week the newest release out three days, or an urgent one at once) and served at /api/latest?channel=stable. The image had latest, a version's tags, 0.1, 0 and edge, nothing for Stable. New .github/workflows/docker-stable.yml reads that feed, hourly and after each Docker run, and points ghcr.io/yetone/magpie:stable at the image docker.yml already built for that version (buildx imagetools create, no build). It decides nothing itself, so the tag can't drift from the desktop's pick. latest, edge and the version tags aren't touched. A feed it can't read (or one naming no version) leaves the tag where it was, with a warning; no image for the Stable version is a red run. Images are compared by their platform manifests, so a run with nothing to do pushes nothing. Docker docs (en, zh, ja) list the tag; worker.js's Stable comment points to the workflow. Run: - actionlint on the workflow: ok. - The step's script locally against the real feed and ghcr (create swapped for an echo): feed says 0.1.1327, :stable missing -> would create stable from 0.1.1327; feed 404 -> warning, exit 0; stable already the same manifests -> "already", exit 0; no image for the version -> exit 4 (red). - node --test site/*.test.mjs on mote: 49 pass. Not tried: - the workflow on GitHub itself: it first runs on its schedule or after the next Docker run; I didn't dispatch it by hand. Its first run creates :stable. - whether buildx imagetools create with one source keeps the index's digest (the compare is by platform manifests, so either way is fine).
70 lines
2.7 KiB
YAML
70 lines
2.7 KiB
YAML
name: Docker stable
|
||
|
||
# ghcr.io/yetone/magpie:stable is the image of the desktop app's Stable
|
||
# release (Settings › Update channel › Stable; jorbenzhu on Discord). Which
|
||
# release that is, is decided in one place only, site/worker.js's stableOf
|
||
# (a weekly pick out three days, or an urgent release at once), and served
|
||
# at /api/latest?channel=stable. This only reads that answer and points
|
||
# :stable at the image already built for that version (docker.yml); it
|
||
# never builds, and never touches latest, edge or a version's tags. While
|
||
# the feed can't be read the tag stays where it was.
|
||
|
||
on:
|
||
schedule:
|
||
- cron: '23 * * * *'
|
||
# a release's image is pushed: an urgent one is Stable at once
|
||
workflow_run:
|
||
workflows: [Docker]
|
||
types: [completed]
|
||
workflow_dispatch:
|
||
|
||
concurrency:
|
||
group: docker-stable
|
||
cancel-in-progress: false
|
||
|
||
env:
|
||
IMAGE: ghcr.io/${{ github.repository_owner }}/magpie
|
||
FEED: https://usemagpie.ai/api/latest?channel=stable
|
||
|
||
jobs:
|
||
stable:
|
||
if: github.repository == 'yetone/magpie' && (github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success')
|
||
runs-on: ubuntu-24.04
|
||
permissions:
|
||
contents: read
|
||
packages: write
|
||
steps:
|
||
- uses: docker/setup-buildx-action@v4
|
||
|
||
- uses: docker/login-action@v4
|
||
with:
|
||
registry: ghcr.io
|
||
username: ${{ github.actor }}
|
||
password: ${{ github.token }}
|
||
|
||
- name: Point stable at the Stable release's image
|
||
run: |
|
||
set -euo pipefail
|
||
if ! BODY=$(curl -fsS --retry 3 --max-time 30 "$FEED"); then
|
||
echo "::warning::the Stable feed couldn't be read; $IMAGE:stable stays where it was"
|
||
exit 0
|
||
fi
|
||
V=$(jq -r '.version // empty' <<<"$BODY")
|
||
if [[ ! "$V" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||
echo "::warning::the Stable feed named no release ($V); $IMAGE:stable stays where it was"
|
||
exit 0
|
||
fi
|
||
# an image is the platforms' manifests in it, however its index
|
||
# is written
|
||
digest() { docker buildx imagetools inspect "$1" --format '{{json .}}' | jq -er '[.manifest.manifests[]?.digest] | sort | join(",") | select(. != "")'; }
|
||
WANT=$(digest "$IMAGE:$V") # no image for the Stable release is a red run
|
||
HAVE=$(digest "$IMAGE:stable" 2>/dev/null || true)
|
||
if [[ "$HAVE" == "$WANT" ]]; then
|
||
echo "$IMAGE:stable is $V already ($WANT)"
|
||
exit 0
|
||
fi
|
||
docker buildx imagetools create -t "$IMAGE:stable" "$IMAGE:$V"
|
||
GOT=$(digest "$IMAGE:stable")
|
||
echo "$IMAGE:stable is now $V ($GOT, was ${HAVE:-none})"
|
||
test "$GOT" == "$WANT"
|