Skip to content

Commit

Permalink
Adapt to OCI registry
Browse files Browse the repository at this point in the history
Signed-off-by: jsparter <[email protected]>
  • Loading branch information
jsparter committed Feb 28, 2023
1 parent 298c56b commit a1091be
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
20 changes: 20 additions & 0 deletions context/rootfs/etc/oci_registry_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"distspecversion": "1.0.1-dev",
"storage": {
"rootdirectory": "/var/lib/registry"
},
"http": {
"address": "0.0.0.0",
"port": 5000,
"realm": "zot",
"tls": {
"cert": "/certs/REGISTRY_DOMAIN.cert",
"key": "/certs/REGISTRY_DOMAIN.key"
},
"auth": {
"htpasswd": {
"path": "/etc/zot/htpasswd"
}
}
}
}
104 changes: 84 additions & 20 deletions context/rootfs/scripts/init-registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ cd $(dirname "$0")
REGISTRY_PORT=${1-5000}
VOLUME=${2-/var/lib/registry}
REGISTRY_DOMAIN=${3-sea.hub}
REGISTRY_TYPE=${4-docker}

container=sealer-registry
rootfs=$(dirname "$(pwd)")
config="$rootfs/etc/registry_config.yml"
oci_config="$rootfs/etc/oci_registry_config.json"
htpasswd="$rootfs/etc/registry_htpasswd"
certs_dir="$rootfs/certs"
image_dir="$rootfs/images"
Expand Down Expand Up @@ -79,31 +81,93 @@ if [ "$(docker ps -aq -f name=$container)" ]; then
docker rm -f $container
fi

# shellcheck disable=SC2034
# shellcheck disable=SC2089
ociConfig="{ \
\"distspecversion\": \"1.0.1-dev\", \
\"storage\": { \
\"rootdirectory\": \"/var/lib/registry\" \
}, \
\"http\": { \
\"address\": \"0.0.0.0\", \
\"port\": $1, \
\"realm\": \"zot\", \
\"tls\": {
\"cert\": \"/certs/$REGISTRY_DOMAIN.cert\", \
\"key\": \"/certs/$REGISTRY_DOMAIN.key\" \
} \
} \
}"

# shellcheck disable=SC2034
# shellcheck disable=SC2089
ociConfigAuth="{ \
\"distspecversion\": \"1.0.1-dev\", \
\"storage\": { \
\"rootdirectory\": \"/var/lib/registry\" \
}, \
\"http\": { \
\"address\": \"0.0.0.0\", \
\"port\": $1, \
\"realm\": \"zot\", \
\"tls\": {
\"cert\": \"/certs/$REGISTRY_DOMAIN.cert\", \
\"key\": \"/certs/$REGISTRY_DOMAIN.key\" \
}, \
\"auth\": { \
\"htpasswd\": { \
\"path\": \"/etc/zot/htpasswd\" \
} \
} \
} \
}"

regArgs="-d --restart=always \
--net=host \
--name $container \
-v $certs_dir:/certs \
-v $VOLUME:/var/lib/registry \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/$REGISTRY_DOMAIN.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/$REGISTRY_DOMAIN.key \
-e REGISTRY_HTTP_DEBUG_ADDR=0.0.0.0:5002 \
-e REGISTRY_HTTP_DEBUG_PROMETHEUS_ENABLED=true"
-v $VOLUME:/var/lib/registry"

# shellcheck disable=SC2086
if [ -f $config ]; then
sed -i "s/5000/$1/g" $config
regArgs="$regArgs \
-v $config:/etc/docker/registry/config.yml"
fi
# shellcheck disable=SC2086
if [ -f $htpasswd ]; then
docker run $regArgs \
-v $htpasswd:/htpasswd \
-e REGISTRY_AUTH=htpasswd \
-e REGISTRY_AUTH_HTPASSWD_PATH=/htpasswd \
-e REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm" registry:2.7.1 || startRegistry
else
docker run $regArgs registry:2.7.1 || startRegistry
if [ "$REGISTRY_TYPE" == "docker" ]; then
regArgs="$regArgs \
-v $certs_dir:/certs \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/$REGISTRY_DOMAIN.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/$REGISTRY_DOMAIN.key \
-e REGISTRY_HTTP_DEBUG_ADDR=0.0.0.0:5002 \
-e REGISTRY_HTTP_DEBUG_PROMETHEUS_ENABLED=true"
# shellcheck disable=SC2086
if [ -f $config ]; then
sed -i "s/5000/$1/g" $config
regArgs="$regArgs \
-v $config:/etc/docker/registry/config.yml"
fi
# shellcheck disable=SC2086
if [ -f $htpasswd ]; then
docker run $regArgs \
-v $htpasswd:/htpasswd \
-e REGISTRY_AUTH=htpasswd \
-e REGISTRY_AUTH_HTPASSWD_PATH=/htpasswd \
-e REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm" registry:2.7.1 || startRegistry
else
docker run $regArgs registry:2.7.1 || startRegistry
fi
else # oci registry
regArgs="$regArgs \
-v $oci_config:/etc/zot/config.json
-v $certs_dir/$REGISTRY_DOMAIN.crt:/certs/$REGISTRY_DOMAIN.cert \
-v $certs_dir/$REGISTRY_DOMAIN.key:/certs/$REGISTRY_DOMAIN.key"
# shellcheck disable=SC2086
if [ -f $htpasswd ]; then
# shellcheck disable=SC2090
echo $ociConfigAuth > $oci_config
docker run $regArgs \
-v $htpasswd:/etc/zot/htpasswd \
ghcr.io/project-zot/zot-linux-amd64:v1.4.3 || startRegistry
else
# shellcheck disable=SC2090
echo $ociConfig > $oci_config
docker run $regArgs ghcr.io/project-zot/zot-linux-amd64:v1.4.3 || startRegistry
fi
fi

check_registry

0 comments on commit a1091be

Please sign in to comment.