fix(scripts): publish.sh — drop bogus auth check, helpful buildx error

- The 'authenticate first' reminder was checking docker system info's
  IndexServerAddress for 'gitea.04080616.xyz', but that field always
  reports Docker Hub regardless of which registries you've logged into.
  The reminder fired even right after a successful 'docker login' to
  Gitea — pure noise. Reduced to a comment for the maintainer.

- The buildx error message now points at the actual root cause: buildx
  is usually installed at the per-user ~/.docker/cli-plugins path, which
  sudo doesn't see. Two fixes presented: docker group (no-sudo) or apt
  install docker-buildx-plugin (sudo).
This commit is contained in:
yiekheng 2026-05-03 10:41:52 +08:00
parent 66737596b8
commit 98a0a433a1

View File

@ -51,23 +51,37 @@ EOF
exit 1 exit 1
fi fi
if ! "${DOCKER[@]}" system info --format '{{json .IndexServerAddress}}' 2>/dev/null | grep -q "gitea.04080616.xyz"; then # (Earlier versions checked `docker system info` for the registry — but
cat <<EOF >&2 # IndexServerAddress always points at Docker Hub regardless of which
Reminder: authenticate first as the same user that runs the build: # registries you've logged into, so the check was a guaranteed false
${SUDO:+sudo }docker login gitea.04080616.xyz # positive. If push fails with 401, run:
EOF # ${SUDO:+sudo }docker login gitea.04080616.xyz
fi
IMAGE_TAG="${1:-${DOCKER_IMAGE_TAG:-latest}}" IMAGE_TAG="${1:-${DOCKER_IMAGE_TAG:-latest}}"
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
PLATFORMS="${CM_IMAGE_PLATFORMS:-linux/amd64}" PLATFORMS="${CM_IMAGE_PLATFORMS:-linux/amd64}"
if ! "${DOCKER[@]}" buildx version >/dev/null 2>&1; then if ! "${DOCKER[@]}" buildx version >/dev/null 2>&1; then
cat <<'EOF' >&2 cat <<EOF >&2
Docker Buildx is required for producing registry-compatible images. Docker Buildx isn't reachable as the user this script runs docker as
Install/enable buildx and rerun, for example: (${SUDO:+root via sudo}${SUDO:-current user}).
docker buildx create --use --name cm-bot-builder
docker buildx inspect --bootstrap Likely cause: buildx is installed at the per-user path
~/.docker/cli-plugins/docker-buildx, which sudo doesn't see.
Pick one fix:
1) Add yourself to the docker group (works for everything, no sudo):
sudo usermod -aG docker \$USER
newgrp docker
docker login gitea.04080616.xyz
NO_SUDO=1 bash scripts/publish.sh ${1:-latest}
2) Install the buildx plugin system-wide:
sudo apt install docker-buildx-plugin
sudo docker login gitea.04080616.xyz
bash scripts/publish.sh ${1:-latest}
EOF EOF
exit 1 exit 1
fi fi