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 Apr 14, 2023
1 parent 298c56b commit 2655975
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
14 changes: 13 additions & 1 deletion auto-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ for i in "$@"; do
fi
shift # past argument=value
;;
--registry=*)
registry="${i#*=}"
if [ "$registry" != "docker" ] && [ "$registry" != "oci" ]; then
if [ "$registry" != "" ]; then
echo "Unsupported registry type: ${registry}"
exit 1
else
registry="docker";
fi
fi
shift # past argument=value
;;
-n=* | --buildName=*)
buildName="${i#*=}"
shift # past argument=value
Expand Down Expand Up @@ -102,7 +114,7 @@ if [ "$(sudo ./"${ARCH}"/bin/kubeadm config images list --config rootfs/etc/kube
sudo sed -i "s/k8s.gcr.io/sea.hub:5000/g" rootfs/etc/kubeadm.yml.tmpl
pauseImage=$(./"${ARCH}"/bin/kubeadm config images list --config "rootfs/etc/kubeadm.yml" 2>/dev/null | sed "/WARNING/d" | grep pause)
if [ -f "rootfs/etc/dump-config.toml" ]; then sudo sed -i "s/sea.hub:5000\/pause:3.6/$(echo "$pauseImage" | sed 's/\//\\\//g')/g" rootfs/etc/dump-config.toml; fi
sudo sealer build -t "docker.io/sealerio/kubernetes:${k8s_version}" -f Kubefile
sudo sealer build -t "docker.io/sealerio/kubernetes:${k8s_version}" -f Kubefile --registry-type=${registry}
if [[ "$push" == "true" ]]; then
if [[ -n "$username" ]] && [[ -n "$password" ]]; then
sudo sealer login "$(echo "docker.io" | cut -d "/" -f1)" -u "${username}" -p "${password}"
Expand Down
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 2655975

Please sign in to comment.