#!/bin/sh # SUMMARY: Check that we can access a registry with auth # LABELS: set -e # Source libraries. Uncomment if needed/defined #. "${RT_LIB}" . "${RT_PROJECT_ROOT}/_lib/lib.sh" clean_up() { docker kill "${REGISTRY_NAME}" || true DOCKER_CONFIG="${DOCKER_CONFIG}" docker buildx rm "${BUILDKIT_NAME}" || true [ -n "${CACHEDIR}" ] && rm -rf "${CACHEDIR}" [ -n "${DOCKER_CONFIG}" ] && rm -rf "${DOCKER_CONFIG}" [ -n "${REGISTRY_DIR}" ] && rm -rf "${REGISTRY_DIR}" } trap clean_up EXIT # determine platform ARCH=$(uname -m) if [ "${ARCH}" = "x86_64" ]; then ARCH="amd64" elif [ "${ARCH}" = "aarch64" ]; then ARCH="arm64" fi PLATFORM="linux/${ARCH}" # container names REGISTRY_NAME="test-registry-$$" BUILDKIT_NAME="test-buildkitd-$$" # start a registry with auth REGISTRY_USER="testuser" REGISTRY_PASS="testpass" REGISTRY_PORT="5000" REGISTRY_DIR=$(mktemp -d) mkdir -p "$REGISTRY_DIR/auth" docker run --rm \ --entrypoint htpasswd \ httpd:2 -Bbn "${REGISTRY_USER}" "${REGISTRY_PASS}" > "$REGISTRY_DIR/auth/htpasswd" # Start registry REGISTRY_CID=$(docker run -d --rm \ -p ":${REGISTRY_PORT}" \ -v "$REGISTRY_DIR/auth:/auth" \ -e "REGISTRY_AUTH=htpasswd" \ -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \ -e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" \ --name "${REGISTRY_NAME}" \ registry:3) REGISTRY_IP=$(docker inspect "${REGISTRY_NAME}" \ --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}') IMAGENAME="${REGISTRY_IP}:${REGISTRY_PORT}/myimage" # start an insecure buildkit so we can load an image to the registry cat > buildkitd.toml < "${DOCKER_CONFIG}/config.json" < Dockerfile <