Skip to content
Snippets Groups Projects
Commit c0fac3fe authored by godog's avatar godog
Browse files

base-docker: add registry mirror

A sample utility to run a local registry is provided
parent e880282c
Branches
No related tags found
No related merge requests found
Pipeline #93661 passed with warnings
#!/bin/bash
CACHE_DIR="./cache"
PORT="5001"
REGISTRY_URL=""
while [[ $# -gt 0 ]]; do
case $1 in
--cache-dir)
CACHE_DIR="$2"
shift 2
;;
--port)
PORT="$2"
shift 2
;;
*)
REGISTRY_URL="$1"
shift
;;
esac
done
if [ -z "$REGISTRY_URL" ]; then
echo "Error: Registry URL is required"
echo "Usage: $0 [--cache-dir DIR] [--port PORT] registry-url"
exit 1
fi
if [[ ! "$REGISTRY_URL" =~ ^https?:// ]]; then
echo "Error: Registry URL must start with http:// or https://"
echo "Provided URL: $REGISTRY_URL"
exit 1
fi
install -d "$CACHE_DIR"
CONFIG_FILE=$(mktemp)
trap "rm -f $CONFIG_FILE" EXIT
cat > "$CONFIG_FILE" << EOF
version: 0.1
log:
level: info
storage:
filesystem:
rootdirectory: /var/lib/registry
delete:
enabled: true
cache:
blobdescriptor: inmemory
http:
addr: 0.0.0.0:$PORT
headers:
X-Content-Type-Options: [nosniff]
proxy:
remoteurl: $REGISTRY_URL
ttl: 168h
EOF
echo "Starting registry proxy for $REGISTRY_URL on port $PORT."
echo "Cache directory: $CACHE_DIR"
CONTAINER_NAME="registry-mirror-$(echo "$REGISTRY_URL" | sed -E 's|^https?://||')"
podman run --rm \
--name $CONTAINER_NAME \
--network host \
-v "$CACHE_DIR:/var/lib/registry:Z" \
-v "$CONFIG_FILE:/etc/docker/registry/config.yml:ro,Z" \
docker.io/library/registry:2
...@@ -45,6 +45,15 @@ ...@@ -45,6 +45,15 @@
content: "33 3 * * * root runcron --quiet /usr/local/bin/docker-cleanup\n" content: "33 3 * * * root runcron --quiet /usr/local/bin/docker-cleanup\n"
mode: 0644 mode: 0644
- name: Create registry mirror configuration files
template:
src: registry-mirror.yml.j2
dest: "/etc/containers/registries.conf.d/{{ item.key }}.conf"
owner: root
group: root
mode: '0644'
loop: "{{ registry_mirrors | dict2items }}"
- import_tasks: start.yml - import_tasks: start.yml
# Grab the list of currently running containers, and stop / cleanup # Grab the list of currently running containers, and stop / cleanup
......
[[registry]]
location = "{{ item.key }}"
[[registry.mirror]]
location = "{{ item.value }}"
insecure = true
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment