okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Docker docs, compose defaults, scripts and the file test name the 0.2.7 image tags (0.2.7-cuda13 and the other flavors)df20d7784

main
5.4 KiB92 linesraw
1#!/bin/sh
2# Build the Strata images of one release from its engine packages and, only with --push, push them to the registry.
3# The GitHub Actions workflow (.github/workflows/docker-images.yml) runs this script once per flavor; you can run it by hand too.
4#
5#   docker/publish.sh --release-tag v0.2.7                        # builds every flavor the release has a package for; pushes nothing
6#   docker/publish.sh --release-tag v0.2.7 --flavors cuda13,cuda12 --push
7#   docker/publish.sh --source ~/release-folder --version 0.2.7-test --flavors cuda13 --no-latest
8#
9# For every flavor:
10#   1. docker/fetch-engines.py downloads the engine package from the release (a GitHub release URL, or --source) and checks it
11#      against the signed update feed: the feed's Ed25519 signature, the archive's size and SHA-256, the manifest hash, the package
12#      signature and every file's hash. A package that fails stops the run before anything is built.
13#   2. docker/build.sh builds <image>:<version>-<flavor> (the Dockerfile checks the package again, and that its libraries resolve).
14#   3. a short check that the image starts and the Terminal inside it reports the version.
15#   4. with --push: docker push of <image>:<version>-<flavor> and, unless --no-latest, <image>:latest-<flavor>. You must be logged in
16#      to the registry already (`docker login ghcr.io`; the workflow logs in with GITHUB_TOKEN).
17#
18#   --release-tag TAG    the release, for example v0.2.7; the image version is the tag without the leading v
19#   --source DIR|URL     use this folder or URL (with strata-feed.json, its .sig and the archives) instead of the GitHub release
20#   --version V          image version (default: the tag without v)
21#   --flavors LIST       comma separated (default: all that the release has: cuda13 cuda12 rocm-gfx120x rocm-gfx110x rocm-gfx1151 sycl)
22#   --image NAME         image repository (default ghcr.io/niko1221/strata)
23#   --work DIR           where packages are unpacked (default a temporary folder, removed at the end)
24#   --push               push the images (default: build only)
25#   --no-latest          do not tag / push latest-<flavor>
26#   --keep-images        do not remove the local images after the run (default: removed only when this script pushed them)
27# Environment: STRATA_DOCKER_BUILD_OPTS adds options to `docker build` (see build.sh).
28set -eu
29
30here=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
31repo=$(CDPATH= cd -- "$here/.." && pwd -P)
32tag=""; source=""; version=""; flavors=""; image="ghcr.io/niko1221/strata"; work=""; push=""; latest=1; keepimg=""
33while [ $# -gt 0 ]; do
34  case "$1" in
35    --release-tag) tag=$2; shift 2 ;;
36    --source) source=$2; shift 2 ;;
37    --version) version=$2; shift 2 ;;
38    --flavors) flavors=$2; shift 2 ;;
39    --image) image=$2; shift 2 ;;
40    --work) work=$2; shift 2 ;;
41    --push) push=1; shift ;;
42    --no-latest) latest=""; shift ;;
43    --keep-images) keepimg=1; shift ;;
44    -h|--help) sed -n '2,29p' "$0"; exit 0 ;;
45    *) echo "publish.sh: unknown option $1" >&2; exit 2 ;;
46  esac
47done
48[ -n "$tag" ] || [ -n "$source" ] || { echo "publish.sh: give --release-tag or --source" >&2; exit 2; }
49if [ -z "$version" ]; then
50  [ -n "$tag" ] || { echo "publish.sh: --version is required with --source" >&2; exit 2; }
51  version=${tag#v}
52fi
53case "$image" in *[A-Z]*) echo "publish.sh: the image name must be lower case ($image)" >&2; exit 2 ;; esac
54command -v docker >/dev/null || { echo "publish.sh: docker not found" >&2; exit 2; }
55PY=${PYTHON:-python3}
56
57own_work=""
58if [ -z "$work" ]; then work=$(mktemp -d "${TMPDIR:-/tmp}/strata-docker-pkgs.XXXXXX"); own_work=1; fi
59mkdir -p "$work"
60cleanup() { if [ -n "$own_work" ]; then rm -rf "$work"; fi; }
61trap cleanup EXIT
62
63built=""
64# one flavor at a time: the package is deleted after its image is built, so the disk never holds more than one
65flavor_list=${flavors:-cuda13,cuda12,rocm-gfx120x,rocm-gfx110x,rocm-gfx1151,sycl}
66for flavor in $(echo "$flavor_list" | tr ',' ' '); do
67  echo "=== $flavor"
68  src_arg="--release-tag $tag"; [ -n "$source" ] && src_arg="--source $source"
69  # a failed fetch (bad signature, bad hash) must stop the run: it is not a skipped flavor
70  $PY "$here/fetch-engines.py" --out "$work" --skip-missing --flavors "$flavor" $src_arg > "$work/.fetch.out"
71  line=$(tail -1 "$work/.fetch.out")
72  bflavor=$(echo "$line" | cut -f2); folder=$(echo "$line" | cut -f3)
73  if [ "$folder" = "SKIP" ] || [ -z "$folder" ]; then echo "$flavor: no package in this release, skipped"; continue; fi
74  img="$image:$version-$flavor"
75  "$here/build.sh" --flavor "$bflavor" --engine "$folder" --tag "$img" --version "$version" --repo "$repo"
76  [ -n "$latest" ] && docker tag "$img" "$image:latest-$flavor"
77  # the image starts and its Terminal runs (no GPU needed for this)
78  docker run --rm --entrypoint /opt/strata/terminal/bin/strata "$img" --version
79  rm -rf "$folder"
80  if [ -n "$push" ]; then
81    docker push "$img"
82    [ -n "$latest" ] && docker push "$image:latest-$flavor"
83    echo "pushed $img$( [ -n "$latest" ] && echo " and $image:latest-$flavor")"
84    docker image inspect "$img" --format '{{index .RepoDigests 0}}' 2>/dev/null || true
85    [ -z "$keepimg" ] && { docker rmi "$img" >/dev/null 2>&1 || true; [ -n "$latest" ] && { docker rmi "$image:latest-$flavor" >/dev/null 2>&1 || true; }; }
86  else
87    echo "built $img (not pushed; add --push)"
88  fi
89  built="$built $flavor"
90done
91[ -n "$built" ] || { echo "publish.sh: no flavor was built (the release has none of: $flavor_list)" >&2; exit 3; }
92echo "done:$built"