Files
seaweedfs/.github/workflows/block-release.yml
T
d4893ebffb seaweed-block: sw-block mini starts as any user with no sudo (#13421)
* seaweed-block: sw-block mini starts as any user with no sudo

blockvolume gets --volume-lock-dir, a trial-run override of the host
volume lock directory (refused under systemd and together with the test
override). sw-block mini passes <dir>/locks to its holder, so it starts
as any user on a host without /run/sw-block. mini also runs v1 with no
scheduled snapshot (it prints the command that takes one), names
sw-block and weed by their absolute paths in every command it prints,
and after a failed start stops what it started and prints the --reuse
command for the same --dir. The release archive carries
sw-block.tmpfiles.conf for the units' lock directory. The README Quick
Start drops its sudo lines, and the v1.1.1 known issue reads fixed in
v1.1.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* seaweed-block: mini under a systemd process tree, and no new lock-dir flag (on #13421) (#13425)

* seaweed-block: mini starts its children without INVOCATION_ID

Run from a systemd service's process tree (a CI runner unit, a terminal
server), mini passed INVOCATION_ID to blockvolume, which then refused
mini's lock directory and the run stopped at startup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* seaweed-block: mini's interrupt test expects the resume command with mini's own path

mini prints the resume command with os.Executable(), so the in-process
test saw the test binary's path, not a bare sw-block, and failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* seaweed-block: mini uses the existing hidden lock-dir override, no new flag

--volume-lock-dir set the same field as the hidden --volume-lock-dir-test-only
with the same systemd refusal, and mini was its only caller. Keep one hidden
override so operators are not offered a documented knob that drops the
one-holder-per-volume guarantee outside systemd (containers, hand-run hosts).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

* docs: track mini resolve helper time bounds

* Test active release assets and relative mini paths

* Complete mini release assets and bounded process checks

* Terminate owned mini groups before checking for residue

* Accept inaccessible host locks as a non-root precondition

* Harden mini test ownership and fail-stop cleanup

* test: reproduce empty filtered mini child environment

* fix(block): complete mini startup and cleanup proof

* test(block): claim the mini test's ports host-wide

The pid-derived --port-shift put mini's 13 ports inside the handoff and
weed pair ranges the other process-level harnesses claim, unclaimed, so a
parallel CI shard could bind one of them. Pick a shift whose every port is
claimed and free, as handoffAddress does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(block): claim the failed-start mini launch's ports too

The second launch ran at shift+1, whose ports were neither claimed nor
checked, so a parallel shard could take one and fail the launch before
it reached the deliberate blockvolume refusal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(block): exercise production mini hint with quoted paths

* docs(block): explain mini local data lock scope

* fix(block): preserve mini executable and cleanup proof

* test(block): settle a leader that exits as member capture expires

stopGroup checked done only at the top of each capture iteration. A
leader that exited after that check, once the one-second window had
passed, made the next failed read fail-stop even though the group had
settled. Both capture deadlines now defer to assertStopped when done has
closed, so live residue still fail-stops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(block): refuse a PATH weed found through the current directory

exec.LookPath reports exec.ErrDot for a weed found only through . in PATH.
Making that name absolute let exec.Command start it, where it refused
before; mini now refuses it and names --weed ./weed as the explicit choice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(block): accept a reused --weed that names the recorded executable

A relative --weed made absolute from another working directory names the
same file through a different path; mini compared the strings and refused
the retry. Compare file identity when the paths differ, so a different
executable is still refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(block): prove the selected weed ran in the mini startup tests

A start failure and the fixture weed's exit both return 1, and the printed
command and the record exist either way. The dying fixture weed now writes
a marker file, and both startup tests require it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(block): name the mini trial lock in the M4 start arrows

The table already says a mini trial's blockvolume locks the run's
--dir/locks; the diagram's start arrows still named only the host lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(block): shell-quote mini's startup trace

Making --weed absolute can put a space from the working directory into the
printed command. Quote the executable and each argument with shQuote, as
mini's other printed commands already are, so the trace runs as printed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(block): count the mini group again when it is gone after a census

A member listed by the census can exit before the signal-0 query reports
ESRCH. On the iteration that crosses the deadline that stale count
fail-stopped a settled group. Count again when the group is absent, so only
a member still listed holds the settlement; the residue control still
fail-stops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(block): name the empty-census case in the mini group fail-stop

A group that still exists while the census lists no live member failed
with "live residue []". Say what it can be: a member the census missed,
or zombies their new parent does not reap. Both stay fail-stops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(block): match the quoted failed-start trace in the non-root mini test

The startup trace is shell-quoted now, and this test's weed path has a
quote in it, so match each binary through miniHintWord.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(block): let --reuse take its recorded run past a weed found through .

The exec.ErrDot refusal ran before the record was read, so a reuse of a
recorded run failed whenever . in PATH found a ./weed, although the reuse
would use the recorded weed (or none for a walstore run). A reuse now
ignores that weed; a fresh start still refuses it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(block): match the shell-quoted start trace in the mini unit tests

mini shell-quotes each word of its "+" trace, so a TMPDIR holding a
space prints the blockmaster, blockvolume and weed paths quoted, and
three unit tests looked for them bare.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(block): pin that a normal start keeps the host volume lock

A start under systemd (INVOCATION_ID set, as every shipped unit runs)
gets no lock directory of its own, so the provider uses the host one,
and the hidden test-only override is refused, naming the host lock
directory. The test is listed under INV-WS-ONE-PROCESS-PER-HOST-001.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(block): mini quotes the --weed path in its dot-in-PATH hint

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
2026-12-05 23:30:27 -08:00

203 lines
8.3 KiB
YAML

name: Publish block release
on:
workflow_dispatch:
push:
tags:
- "seaweed-block/v*"
permissions:
contents: write
packages: write
env:
REGISTRY: ghcr.io
BLOCK_IMAGE: ghcr.io/seaweedfs/seaweed-block
CSI_IMAGE: ghcr.io/seaweedfs/seaweed-block-csi
jobs:
publish:
# Publish only from a version tag; a manual run from a branch must not move :alpha.
if: startsWith(github.ref, 'refs/tags/seaweed-block/v')
runs-on: ubuntu-latest
steps:
- name: Runner free space
working-directory: ${{ runner.temp }}
run: |
python3 -I - <<'PY'
import os
import shutil
import sys
required = 10_000_000_000
for path in dict.fromkeys((os.environ["GITHUB_WORKSPACE"], os.environ["RUNNER_TEMP"])):
try:
free = shutil.disk_usage(path).free
except OSError as err:
print(f"runner_disk_check_failed path={path!r} error={err}")
sys.exit(75)
if free < required:
print(f"runner_disk_low path={path!r} free_bytes={free} required_bytes={required}")
sys.exit(75)
print(f"runner_disk_ok path={path!r} free_bytes={free} required_bytes={required}")
PY
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # the tag list decides whether :alpha moves
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute image tags
id: tags
shell: bash
run: |
set -euo pipefail
# vX.Y.Z-pre (a release candidate) publishes only its own version tag. A stable vX.Y.Z also
# publishes sha-*, and moves :alpha only when it is the highest stable version tag, so a later
# patch on an older line never moves :alpha back.
short_sha="${GITHUB_SHA::12}"
version="${GITHUB_REF_NAME#seaweed-block/}"
if [[ ! "${version}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$ ]]; then
echo "refusing to publish: tag ${version} is not vX.Y.Z or vX.Y.Z-pre" >&2
exit 1
fi
notes="seaweed-block/docs/releases/${version%%-*}.md"
if [[ ! -s "${notes}" ]]; then
echo "refusing to publish: release notes ${notes} are missing or empty" >&2
exit 1
fi
echo "notes=${notes}" >> "$GITHUB_OUTPUT"
stable=false
move_alpha=false
if [[ "${version}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
stable=true
highest="$(git tag -l 'seaweed-block/v*' | sed 's|^seaweed-block/||' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1)"
if [[ "${version}" == "${highest}" ]]; then
move_alpha=true
fi
fi
{
echo "block_tags<<EOF"
echo "${BLOCK_IMAGE}:${version}"
if [[ "${stable}" == true ]]; then echo "${BLOCK_IMAGE}:sha-${short_sha}"; fi
if [[ "${move_alpha}" == true ]]; then echo "${BLOCK_IMAGE}:alpha"; fi
echo "EOF"
echo "csi_tags<<EOF"
echo "${CSI_IMAGE}:${version}"
if [[ "${stable}" == true ]]; then echo "${CSI_IMAGE}:sha-${short_sha}"; fi
if [[ "${move_alpha}" == true ]]; then echo "${CSI_IMAGE}:alpha"; fi
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Build and push block image
id: block
uses: docker/build-push-action@v6
with:
context: .
file: .github/dockerfiles/block-sw-block.Dockerfile
platforms: linux/amd64
push: true
tags: ${{ steps.tags.outputs.block_tags }}
- name: Build and push CSI image
uses: docker/build-push-action@v6
with:
context: .
file: .github/dockerfiles/block-blockcsi.Dockerfile
platforms: linux/amd64
push: true
tags: ${{ steps.tags.outputs.csi_tags }}
- name: Publish matching binary tarball
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BLOCK_DIGEST: ${{ steps.block.outputs.digest }}
NOTES: ${{ steps.tags.outputs.notes }}
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME#seaweed-block/}"
out="$RUNNER_TEMP/block-release"
mkdir -p "$out/bin"
docker pull "${BLOCK_IMAGE}@${BLOCK_DIGEST}"
container=$(docker create "${BLOCK_IMAGE}@${BLOCK_DIGEST}")
trap 'docker rm "$container" >/dev/null' EXIT
for binary in blockmaster blockvolume sw-block; do
docker cp "$container:/usr/local/bin/$binary" "$out/bin/$binary"
done
bash seaweed-block/scripts/refuse-lab-binary.sh "$out/bin/"*
cp seaweed-block/deploy/systemd/sw-block.tmpfiles.conf "$out/bin/sw-block.tmpfiles.conf"
asset="sw-block-${version}-linux-amd64.tar.gz"
tar -C "$out/bin" -czf "$out/$asset" blockmaster blockvolume sw-block sw-block.tmpfiles.conf
(cd "$out" && sha256sum "$asset" >SHA256SUMS)
prerelease=false
if [[ "$version" == *-* ]]; then prerelease=true; fi
# A rerun replaces the assets, then publishes a draft an interrupted run left.
if gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
gh release upload "$GITHUB_REF_NAME" "$out/$asset" "$out/SHA256SUMS" --repo "$GITHUB_REPOSITORY" --clobber
gh release edit "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --prerelease="$prerelease" --draft=false --latest=false
else
gh release create "$GITHUB_REF_NAME" "$out/$asset" "$out/SHA256SUMS" --repo "$GITHUB_REPOSITORY" --verify-tag --latest=false \
--prerelease="$prerelease" --title "Seaweed Block $version" --notes-file "$NOTES"
fi
- name: Clean job workspace
# Hosted runners are disposable; their setup-go cache upload runs in
# a post action and still needs the checkout. Persistent runners do not
# upload that cache, and must release their checkout/build files here.
if: always() && runner.environment == 'self-hosted'
working-directory: ${{ runner.temp }}
run: |
python3 -I - <<'PY'
import os
from pathlib import Path
import shutil
import sys
root = Path(os.environ["GITHUB_WORKSPACE"])
# Refuse aliases rather than resolving them. Open EVERY component without
# following symlinks, then keep cleanup anchored to the verified directory fd.
if not root.is_absolute() or ".." in root.parts or root == Path(root.anchor) or root.name != root.parent.name or root == Path(os.environ["RUNNER_TEMP"]):
print(f"runner_workspace_cleanup_refused path={str(root)!r}")
sys.exit(1)
flags = os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW
fd = os.open(root.anchor, flags)
previous = os.open(".", flags)
errors = []
try:
for part in root.parts[1:]:
child = os.open(part, flags, dir_fd=fd)
os.close(fd)
fd = child
if not shutil.rmtree.avoids_symlink_attacks:
raise OSError("descriptor-safe directory removal is unavailable")
os.fchdir(fd)
for entry in os.scandir("."):
try:
if entry.is_dir(follow_symlinks=False):
shutil.rmtree(entry.name)
else:
os.unlink(entry.name)
except OSError as err:
errors.append(f"{entry.name}: {err}")
except OSError as err:
print(f"runner_workspace_cleanup_refused path={str(root)!r} error={err}")
sys.exit(1)
finally:
os.fchdir(previous)
os.close(previous)
os.close(fd)
if errors:
print("runner_workspace_cleanup_failed " + "; ".join(errors))
sys.exit(1)
print(f"runner_workspace_clean path={str(root)!r}")
PY