Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions context/k0s/rootfs/etc/dump-config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version = 2
[plugins]
[plugins."io.containerd.grpc.v1.cri"]
sandbox_image = "sea.hub:5000/pause:3.7"
[plugins."io.containerd.grpc.v1.cri".registry]
config_path = "/etc/docker/certs.d/"
4 changes: 4 additions & 0 deletions context/k0s/rootfs/etc/registry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
domain: sea.hub
port: "5000"
username: ""
password: ""
49 changes: 49 additions & 0 deletions context/k0s/rootfs/scripts/containerd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
# Copyright © 2021 Alibaba Group Holding Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -x
set -e

# if [ $(systemctl status containerd > /dev/null 2>&1; echo $?) != 0 ]; then
# tar -xvzf ../cri/containerd.tar.gz -C /
# cp -rf ../lib64/lib* /usr/lib64/
# systemctl enable containerd.service
# systemctl restart containerd.service
# fi

rootfs=$(dirname "$(pwd)")
image_dir="$rootfs/images"
dump_config_dir="$rootfs/etc/dump-config.toml"
load_images() {
for image in "$image_dir"/*
do
if [ -f "${image}" ]
then
nerdctl load -i "${image}"
fi
done
}

# mkdir -p /etc/containerd

sed -i "s/sea.hub/${1:-sea.hub}/g" "$dump_config_dir"
sed -i "s/5000/${2:-5000}/g" "$dump_config_dir"

#add cri sandbox image and sea.hub registry cert path
##sandbox_image = "sea.hub:5000/pause:3.6" custom setup
containerd --config "$dump_config_dir" config dump > /etc/containerd/config.toml

systemctl restart containerd.service
load_images
94 changes: 94 additions & 0 deletions context/k0s/rootfs/scripts/init-registry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash
# Copyright © 2021 Alibaba Group Holding Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


set -e
set -x
# prepare registry storage as directory
cd "$(dirname "$0")"

# shellcheck disable=SC2034
REGISTRY_PORT=${1-5000}
VOLUME=${2-/var/lib/registry}
REGISTRY_DOMAIN=${3-sea.hub}

container=sealer-registry
rootfs=$(dirname "$(pwd)")
config="$rootfs/etc/registry_config.yml"
htpasswd="$rootfs/etc/registry_htpasswd"
certs_dir="$rootfs/certs"

mkdir -p "$VOLUME" || true

startRegistry() {
n=1
while (( n <= 3 ))
do
echo "attempt to start registry"
# shellcheck disable=SC2106
(nerdctl start $container && break) || (( n < 3))
(( n++ ))
sleep 3
done
}

check_registry() {
n=1
while (( n <= 3 ))
do
(nerdctl inspect sealer-registry | grep "\"Status\": \"running\"") && break
if [[ $n -eq 3 ]]; then
# shellcheck disable=SC2154
echo "sealer-registry is not running, status: $registry_status"
exit 1
fi
(( n++ ))
sleep 3
done
}


## rm container if exist.
! nerdctl ps -a |grep sealer-registry || nerdctl rmi -f sealer-registry
##
rm -rf /var/lib/nerdctl/1935db59/names/default/$container

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"

if [ -f "$config" ]; then
sed -i "s/5000/$1/g" "$config"
regArgs="$regArgs \
-v $config:/etc/docker/registry/config.yml"
fi

if [ -f "$htpasswd" ]; then
# shellcheck disable=SC2086
nerdctl 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
nerdctl run "$regArgs" registry:2.7.1 || startRegistry
fi

sleep 1
check_registry
29 changes: 29 additions & 0 deletions context/k0s/rootfs/scripts/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
# Copyright © 2021 Alibaba Group Holding Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e
set -x

#STORAGE=${1:-/var/lib/docker} compatible docker
REGISTRY_DOMAIN=${2-sea.hub}
REGISTRY_PORT=${3-5000}

chmod -R 755 ../bin/*
chmod 644 ../bin
cp ../bin/* /usr/bin

# Install containerd
chmod a+x containerd.sh
/bin/bash containerd.sh "$REGISTRY_DOMAIN" "$REGISTRY_PORT"