bugzilla/scripts/reproduce-containerd-referrers.sh
Tiara Rodney 883f31932e
init
2026-03-14 05:38:45 +01:00

98 lines
2.4 KiB
Bash

#!/bin/sh
# Reproduce: containerd-snapshotter pull-through mirror referrers failure
#
# Prerequisites: Docker Engine installed, root access
# This script:
# 1. Starts a pull-through registry mirror for Docker Hub
# 2. Enables containerd-snapshotter
# 3. Configures Docker to use the mirror via hosts.toml
# 4. Pulls an image — fails with "failed to decode referrers index"
#
# Run as root.
set -eu
MIRROR_PORT=5555
MIRROR_NAME=registry-mirror-test
cleanup() {
echo "==> Cleaning up"
docker rm -f "$MIRROR_NAME" 2>/dev/null || true
rm -rf /etc/docker/certs.d/docker.io
rm -f /tmp/mirror-config.yml
# Restore daemon.json
if [ -f /etc/docker/daemon.json.bak ]; then
mv /etc/docker/daemon.json.bak /etc/docker/daemon.json
else
rm -f /etc/docker/daemon.json
fi
systemctl restart docker 2>/dev/null || true
}
trap cleanup EXIT
echo "==> Step 1: Start pull-through registry mirror"
cat > /tmp/mirror-config.yml <<EOF
version: 0.1
log:
fields:
service: registry
storage:
filesystem:
rootdirectory: /var/lib/registry
delete:
enabled: true
http:
addr: :5000
proxy:
remoteurl: https://registry-1.docker.io
EOF
docker rm -f "$MIRROR_NAME" 2>/dev/null || true
docker run -d \
--name "$MIRROR_NAME" \
-p "${MIRROR_PORT}:5000" \
-v /tmp/mirror-config.yml:/etc/docker/registry/config.yml:ro \
registry:2
echo " Waiting for mirror to start..."
sleep 3
echo "==> Step 2: Enable containerd-snapshotter"
if [ -f /etc/docker/daemon.json ]; then
cp /etc/docker/daemon.json /etc/docker/daemon.json.bak
fi
cat > /etc/docker/daemon.json <<EOF
{
"features": {
"containerd-snapshotter": true
}
}
EOF
echo "==> Step 3: Configure mirror via hosts.toml"
mkdir -p /etc/docker/certs.d/docker.io
cat > /etc/docker/certs.d/docker.io/hosts.toml <<EOF
server = "https://docker.io"
[host."http://127.0.0.1:${MIRROR_PORT}"]
capabilities = ["pull", "resolve"]
EOF
echo "==> Step 4: Restart Docker"
systemctl restart docker
sleep 3
echo "==> Step 5: Remove cached image and pull through mirror"
docker image rm alpine:latest 2>/dev/null || true
echo " Pulling alpine:latest..."
if docker pull alpine:latest; then
echo " PASS: Pull succeeded (issue may be fixed)"
else
echo " FAIL: Pull failed with referrers error (issue reproduced)"
fi
echo
echo "==> Docker version:"
docker version --format '{{.Server.Version}}'
echo "==> Storage driver:"
docker info --format '{{.Driver}}'