From 33b6d7d677b9e0f2619fd8daf61956b13eee1a0d Mon Sep 17 00:00:00 2001 From: Stille Date: Mon, 11 Apr 2022 19:57:39 +0800 Subject: [PATCH] Create registry-proxy --- registry-proxy/Dockerfile | 7 +++++++ registry-proxy/README.md | 32 +++++++++++++++++++++++++++++++ registry-proxy/docker-compose.yml | 12 ++++++++++++ registry-proxy/entrypoint.sh | 22 +++++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 registry-proxy/Dockerfile create mode 100644 registry-proxy/README.md create mode 100644 registry-proxy/docker-compose.yml create mode 100755 registry-proxy/entrypoint.sh diff --git a/registry-proxy/Dockerfile b/registry-proxy/Dockerfile new file mode 100644 index 0000000..485e062 --- /dev/null +++ b/registry-proxy/Dockerfile @@ -0,0 +1,7 @@ +FROM registry:latest +LABEL maintainer="Stille " + +ENV PROXY_REMOTE_URL="" \ + DELETE_ENABLED="" + +COPY entrypoint.sh /entrypoint.sh diff --git a/registry-proxy/README.md b/registry-proxy/README.md new file mode 100644 index 0000000..6be2035 --- /dev/null +++ b/registry-proxy/README.md @@ -0,0 +1,32 @@ +# mc + +GitHub [stilleshan/dockerfiles](https://github.com/stilleshan/dockerfiles) +Docker [stilleshan/registry-proxy](https://hub.docker.com/r/stilleshan/registry-proxy) +> *docker image support for X86 and ARM* + +## 简介 +代理 ghcr.io / gcr.io / k8s.gcr.io 等镜像仓库的 registry proxy 镜像. + +## 使用 +### docker +环境变量`PROXY_REMOTE_URL`: +- https://ghcr.io +- https://gcr.io +- https://k8s.gcr.io + +```shell +docker run -d --restart always \ + -v /data/path:/var/lib/registry\ + -p 5000:5000 \ + -e PROXY_REMOTE_URL=https://ghcr.io \ + stilleshan/registry-proxy +``` + +### docker compose +下载 [docker-compose.yml](https://raw.githubusercontent.com/stilleshan/dockerfiles/main/registry-proxy/docker-compose.yml) 执行以下命令启动: +```shell +docker-compose up -d +``` + +## 参考 +- GitHub [findsec-cn/registry-proxy](https://github.com/findsec-cn/registry-proxy) diff --git a/registry-proxy/docker-compose.yml b/registry-proxy/docker-compose.yml new file mode 100644 index 0000000..d3366ff --- /dev/null +++ b/registry-proxy/docker-compose.yml @@ -0,0 +1,12 @@ +version: "3" +services: + ghcr.io: + image: stilleshan/registry-proxy + volumes: + - ./data:/var/lib/registry + - /etc/localtime:/etc/localtime + ports: + - 5000:5000 + environment: + - PROXY_REMOTE_URL=https://ghcr.io + restart: always diff --git a/registry-proxy/entrypoint.sh b/registry-proxy/entrypoint.sh new file mode 100755 index 0000000..bc65b07 --- /dev/null +++ b/registry-proxy/entrypoint.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +set -e + +CONFIG_YML=/etc/docker/registry/config.yml + +if [ -n "$PROXY_REMOTE_URL" -a `grep -c "$PROXY_REMOTE_URL" $CONFIG_YML` -eq 0 ]; then + echo "proxy:" >> $CONFIG_YML + echo " remoteurl: $PROXY_REMOTE_URL" >> $CONFIG_YML + echo "------ Enabled proxy to remote: $PROXY_REMOTE_URL ------" +elif [ $DELETE_ENABLED = true -a `grep -c "delete:" $CONFIG_YML` -eq 0 ]; then + sed -i '/rootdirectory/a\ delete:' $CONFIG_YML + sed -i '/delete/a\ enabled: true' $CONFIG_YML + echo "------ Enabled local storage delete -----" +fi + +case "$1" in + *.yaml|*.yml) set -- registry serve "$@" ;; + serve|garbage-collect|help|-*) set -- registry "$@" ;; +esac + +exec "$@"