Skip to content

Commit 94232ef

Browse files
committed
add k0s rootfs
Signed-off-by: starComingup <1225067236@qq.com>
1 parent b51bca6 commit 94232ef

5 files changed

Lines changed: 178 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version = 2
2+
[plugins]
3+
[plugins."io.containerd.grpc.v1.cri"]
4+
sandbox_image = "sea.hub:5000/pause:3.7"
5+
[plugins."io.containerd.grpc.v1.cri".registry]
6+
config_path = "/etc/docker/certs.d/"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
domain: sea.hub
2+
port: "5000"
3+
username: ""
4+
password: ""
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
# Copyright © 2021 Alibaba Group Holding Ltd.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -x
17+
set -e
18+
19+
# if [ $(systemctl status containerd > /dev/null 2>&1; echo $?) != 0 ]; then
20+
# tar -xvzf ../cri/containerd.tar.gz -C /
21+
# cp -rf ../lib64/lib* /usr/lib64/
22+
# systemctl enable containerd.service
23+
# systemctl restart containerd.service
24+
# fi
25+
26+
rootfs=$(dirname "$(pwd)")
27+
image_dir="$rootfs/images"
28+
dump_config_dir="$rootfs/etc/dump-config.toml"
29+
load_images() {
30+
for image in "$image_dir"/*
31+
do
32+
if [ -f "${image}" ]
33+
then
34+
nerdctl load -i "${image}"
35+
fi
36+
done
37+
}
38+
39+
# mkdir -p /etc/containerd
40+
41+
sed -i "s/sea.hub/${1:-sea.hub}/g" "$dump_config_dir"
42+
sed -i "s/5000/${2:-5000}/g" "$dump_config_dir"
43+
44+
#add cri sandbox image and sea.hub registry cert path
45+
##sandbox_image = "sea.hub:5000/pause:3.6" custom setup
46+
containerd --config "$dump_config_dir" config dump > /etc/containerd/config.toml
47+
48+
systemctl restart containerd.service
49+
load_images
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
# Copyright © 2021 Alibaba Group Holding Ltd.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
17+
set -e
18+
set -x
19+
# prepare registry storage as directory
20+
cd $(dirname "$0")
21+
22+
REGISTRY_PORT=${1-5000}
23+
VOLUME=${2-/var/lib/registry}
24+
REGISTRY_DOMAIN=${3-sea.hub}
25+
26+
container=sealer-registry
27+
rootfs=$(dirname "$(pwd)")
28+
config="$rootfs/etc/registry_config.yml"
29+
htpasswd="$rootfs/etc/registry_htpasswd"
30+
certs_dir="$rootfs/certs"
31+
32+
mkdir -p "$VOLUME" || true
33+
34+
startRegistry() {
35+
n=1
36+
while (( n <= 3 ))
37+
do
38+
echo "attempt to start registry"
39+
(nerdctl start $container && break) || (( n < 3))
40+
(( n++ ))
41+
sleep 3
42+
done
43+
}
44+
45+
check_registry() {
46+
n=1
47+
while (( n <= 3 ))
48+
do
49+
(nerdctl inspect sealer-registry | grep "\"Status\": \"running\"") && break
50+
if [[ $n -eq 3 ]]; then
51+
echo "sealer-registry is not running, status: $registry_status"
52+
exit 1
53+
fi
54+
(( n++ ))
55+
sleep 3
56+
done
57+
}
58+
59+
60+
## rm container if exist.
61+
! nerdctl ps -a |grep sealer-registry || nerdctl rmi -f sealer-registry
62+
##
63+
rm -rf /var/lib/nerdctl/1935db59/names/default/$container
64+
65+
regArgs="-d --restart=always \
66+
--net=host \
67+
--name $container \
68+
-v $certs_dir:/certs \
69+
-v $VOLUME:/var/lib/registry \
70+
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/$REGISTRY_DOMAIN.crt \
71+
-e REGISTRY_HTTP_TLS_KEY=/certs/$REGISTRY_DOMAIN.key"
72+
73+
if [ -f $config ]; then
74+
sed -i "s/5000/$1/g" $config
75+
regArgs="$regArgs \
76+
-v $config:/etc/docker/registry/config.yml"
77+
fi
78+
79+
if [ -f $htpasswd ]; then
80+
nerdctl run $regArgs \
81+
-v $htpasswd:/htpasswd \
82+
-e REGISTRY_AUTH=htpasswd \
83+
-e REGISTRY_AUTH_HTPASSWD_PATH=/htpasswd \
84+
-e REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm" registry:2.7.1 || startRegistry
85+
else
86+
nerdctl run $regArgs registry:2.7.1 || startRegistry
87+
fi
88+
89+
sleep 1
90+
check_registry

context/k0s/rootfs/scripts/init.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
# Copyright © 2021 Alibaba Group Holding Ltd.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -e
17+
set -x
18+
19+
#STORAGE=${1:-/var/lib/docker} compatible docker
20+
REGISTRY_DOMAIN=${2-sea.hub}
21+
REGISTRY_PORT=${3-5000}
22+
23+
chmod -R 755 ../bin/*
24+
chmod 644 ../bin
25+
cp ../bin/* /usr/bin
26+
27+
# Install containerd
28+
chmod a+x containerd.sh
29+
/bin/bash containerd.sh "$REGISTRY_DOMAIN" "$REGISTRY_PORT"

0 commit comments

Comments
 (0)