Skip to content

Commit 4660be0

Browse files
committed
optimize scripts and add autobuild scripts
1 parent 5adf576 commit 4660be0

File tree

9 files changed

+202
-34
lines changed

9 files changed

+202
-34
lines changed

Diff for: .github/workflows/auto-build-main.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Auto build image
2+
on:
3+
issue_comment:
4+
types:
5+
- created
6+
jobs:
7+
issue_comment:
8+
name: Auto build image
9+
if: startswith(github.event.comment.body, '/autobuild')
10+
runs-on: ubuntu-latest
11+
permissions:
12+
issues: write
13+
steps:
14+
15+
- name: Auto build image
16+
id: autobuild
17+
run: |
18+
commentbody="${{github.event.comment.body}}"
19+
commentbody=$(echo $commentbody | sed "s/\/imagebuild//g")
20+
sudo git clone https://github.com/sealerio/basefs.git && cd basefs
21+
sudo touch autobuild.log && sudo chmod 666 autobuild.log && sudo bash auto-build-main.sh --username="${{secrets.REGISTRY_USERNAME}}" --password="${{secrets.REGISTRY_PASSWORD}}" $commentbody > autobuild.log && cat autobuild.log
22+
echo "::set-output name=info::$(grep 'cri:' autobuild.log))"
23+
24+
- name: Success Commit
25+
uses: peter-evans/create-or-update-comment@v1
26+
with:
27+
issue-number: ${{ github.event.issue.number }}
28+
body: |
29+
${{ steps.autobuild.outputs.info }}

Diff for: auto-build-main.sh

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
for i in "$@"; do
6+
case $i in
7+
-c=* | --cri=*)
8+
cri="${i#*=}"
9+
if [ "$cri" != "docker" ] && [ "$cri" != "containerd" ]; then
10+
echo "Unsupported container runtime: ${cri}"
11+
exit 1
12+
fi
13+
shift # past argument=value
14+
;;
15+
-n=* | --buildName=*)
16+
buildName="${i#*=}"
17+
shift # past argument=value
18+
;;
19+
--platform=*)
20+
platform="${i#*=}"
21+
shift # past argument=value
22+
;;
23+
--push)
24+
push="true"
25+
shift # past argument=value
26+
;;
27+
-p=* | --password=*)
28+
password="${i#*=}"
29+
shift # past argument=value
30+
;;
31+
-u=* | --username=*)
32+
username="${i#*=}"
33+
shift # past argument=value
34+
;;
35+
--k8s-version=*)
36+
k8s_version="${i#*=}"
37+
shift # past argument=value
38+
;;
39+
-h | --help)
40+
echo "
41+
### Options
42+
--k8s-version set the kubernetes k8s_version of the Clusterimage, k8s_version must be greater than 1.13
43+
-c, --cri cri can be set to docker or containerd between kubernetes 1.20-1.24 versions
44+
-n, --buildName set build image name, default is 'registry.cn-qingdao.aliyuncs.com/sealer-io/kubernetes:${k8s_version}'
45+
--platform set the build mirror platform, the default is linux/amd64,linux/arm64
46+
--push push clusterimage after building the clusterimage. The image name must contain the full name of the repository, and use -u and -p to specify the username and password.
47+
-u, --username specify the user's username for pushing the Clusterimage
48+
-p, --password specify the user's password for pushing the Clusterimage
49+
-d, --debug show all script logs
50+
-h, --help help for auto build shell scripts"
51+
exit 0
52+
;;
53+
-d | --debug)
54+
set -x
55+
shift
56+
;;
57+
-*)
58+
echo "Unknown option $i"
59+
exit 1
60+
;;
61+
*) ;;
62+
63+
esac
64+
done
65+
66+
version_compare() { printf '%s\n%s\n' "$2" "$1" | sort -V -C; } ## version_compare $a $b: a>=b
67+
68+
ARCH=$(case "$(uname -m)" in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo "unsupported architecture" "$(uname -m)" && exit 1 ;; esac)
69+
70+
if [ "$k8s_version" = "" ]; then echo "pls use --k8s-version to set Clusterimage kubernetes version" && exit 1; else echo "$k8s_version" | grep "v" || k8s_version="v${k8s_version}"; fi
71+
#cri=$([[ -n "$cri" ]] && echo "$cri" || echo docker)
72+
cri=$( (version_compare "$k8s_version" "v1.24.0" && echo "containerd") || ([[ -n "$cri" ]] && echo "$cri" || echo "docker"))
73+
if [[ -z "$buildName" ]]; then
74+
buildName="docker.io/sealerio/kubernetes:${k8s_version}"
75+
if [[ "$cri" == "containerd" ]] && ! version_compare "$k8s_version" "v1.24.0"; then buildName=${buildName}-containerd; fi
76+
fi
77+
platform=$(if [[ -z "$platform" ]]; then echo "linux/arm64,linux/amd64"; else echo "$platform"; fi)
78+
echo "cri: ${cri}, kubernetes version: ${k8s_version}, build image name: ${buildName}"
79+
80+
kubeadmApiVersion=$( (version_compare "$k8s_version" "v1.23.0" && echo 'kubeadm.k8s.io\/v1beta3') || (version_compare "$k8s_version" "v1.15.0" && echo 'kubeadm.k8s.io\/v1beta2') ||
81+
(version_compare "$k8s_version" "v1.13.0" && echo 'kubeadm.k8s.io\/v1beta1') || (echo "Version must be greater than 1.13: ${k8s_version}" && exit 1))
82+
83+
workdir="$(mktemp -d auto-build-XXXXX)" && sudo cp -r context "${workdir}" && cd "${workdir}/context" && sudo cp -rf "${cri}"/* .
84+
85+
# shellcheck disable=SC1091
86+
sudo chmod +x version.sh download.sh && export kube_install_version="$k8s_version" && source version.sh
87+
./download.sh "${cri}"
88+
89+
sudo chmod +x amd64/bin/kube* && sudo chmod +x arm64/bin/kube*
90+
#Download the latest version of sealer
91+
sudo git clone https://github.com/sealerio/sealer && cd sealer && git checkout main && make build-in-docker && cp _output/bin/sealer/linux_amd64/sealer /usr/bin/ && cd ..
92+
sudo sed -i "s/v1.19.8/$k8s_version/g" rootfs/etc/kubeadm.yml ##change k8s_version
93+
if [[ "$cri" == "containerd" ]]; then sudo sed -i "s/\/var\/run\/dockershim.sock/\/run\/containerd\/containerd.sock/g" rootfs/etc/kubeadm.yml; fi
94+
sudo sed -i "s/kubeadm.k8s.io\/v1beta2/$kubeadmApiVersion/g" rootfs/etc/kubeadm.yml
95+
sudo ./"${ARCH}"/bin/kubeadm config images list --config "rootfs/etc/kubeadm.yml"
96+
sudo mkdir manifests
97+
sudo ./"${ARCH}"/bin/kubeadm config images list --config "rootfs/etc/kubeadm.yml" 2>/dev/null | sed "/WARNING/d" >>imageList
98+
if [ "$(sudo ./"${ARCH}"/bin/kubeadm config images list --config rootfs/etc/kubeadm.yml 2>/dev/null | grep -c "coredns/coredns")" -gt 0 ]; then sudo sed -i "s/#imageRepository/imageRepository/g" rootfs/etc/kubeadm.yml; fi
99+
sudo sed -i "s/k8s.gcr.io/sea.hub:5000/g" rootfs/etc/kubeadm.yml
100+
pauseImage=$(./"${ARCH}"/bin/kubeadm config images list --config "rootfs/etc/kubeadm.yml" 2>/dev/null | sed "/WARNING/d" | grep pause)
101+
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
102+
#sudo sed -i "s/v1.19.8/${k8s_version}/g" {arm64,amd64}/etc/Metadata
103+
##linux/arm64,linux/amd64
104+
sudo sealer build -t "docker.io/sealerio/kubernetes:${k8s_version}" -f Kubefile
105+
if [[ "$push" == "true" ]]; then
106+
if [[ -n "$username" ]] && [[ -n "$password" ]]; then
107+
sudo sealer login "$(echo "docker.io" | cut -d "/" -f1)" -u "${username}" -p "${password}"
108+
fi
109+
sudo sealer push "docker.io/sealerio/kubernetes:${k8s_version}"
110+
fi

Diff for: context/rootfs/scripts/docker.sh

+6-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
set -x
1717
set -e
1818

19-
scripts_path=$(cd `dirname $0`; pwd)
19+
# shellcheck disable=SC2046
20+
# shellcheck disable=SC2006
21+
scripts_path=$(cd `dirname "$0"`; pwd)
2022
image_dir="$scripts_path/../images"
2123
DOCKER_VERSION="19.03.14-sealer"
2224

25+
# shellcheck disable=SC1091
2326
get_distribution() {
2427
lsb_dist=""
2528
# Every system that we officially support has /etc/os-release
@@ -46,6 +49,7 @@ load_images() {
4649
done
4750
}
4851

52+
# shellcheck disable=SC2006
4953
check_docker_valid() {
5054
if ! docker info 2>&1; then
5155
panic "docker is not healthy: $(docker info 2>&1), please check"
@@ -58,7 +62,7 @@ check_docker_valid() {
5862
}
5963

6064
storage=${1:-/var/lib/docker}
61-
mkdir -p $storage
65+
mkdir -p "$storage"
6266
if ! utils_command_exists docker; then
6367
lsb_dist=$(get_distribution)
6468
lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
@@ -101,8 +105,6 @@ if ! utils_command_exists docker; then
101105
systemctl enable docker.service
102106
systemctl restart docker.service
103107
cp "${scripts_path}"/../etc/daemon.json /etc/docker
104-
mkdir -p /root/.docker/
105-
cp "${scripts_path}"/../etc/docker-cli-config.json /root/.docker/config.json
106108
if [[ -n $1 && -n $2 ]]; then
107109
sed -i "s/sea.hub:5000/$2:$3/g" /etc/docker/daemon.json
108110
fi

Diff for: context/rootfs/scripts/init-kube.sh

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/bin/bash
22

3-
scripts_path=$(cd `dirname $0`; pwd)
3+
# shellcheck disable=SC2046
4+
# shellcheck disable=SC2164
5+
# shellcheck disable=SC2006
6+
# shellcheck disable=SC1091
7+
scripts_path=$(cd `dirname "$0"`; pwd)
48
source "${scripts_path}"/utils.sh
59

610
set -x
@@ -56,4 +60,4 @@ copy_kubelet_service
5660
systemctl enable kubelet
5761

5862
# nvidia-docker.sh need set kubelet labels, it should be run after kubelet
59-
bash ${scripts_path}/nvidia-docker.sh || exit 1
63+
bash "${scripts_path}"/nvidia-docker.sh || exit 1

Diff for: context/rootfs/scripts/init-registry.sh

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
11
#!/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.
215

316
set -e
417
set -x
518
# prepare registry storage as directory
19+
# shellcheck disable=SC2046
620
cd $(dirname "$0")
721

22+
# shellcheck disable=SC2034
823
REGISTRY_PORT=${1-5000}
924
VOLUME=${2-/var/lib/registry}
10-
REGISTRY_DOMAIN=${3-sea.hub}
1125

1226
container=sealer-registry
1327
rootfs=$(dirname "$(pwd)")
1428
config="$rootfs/etc/registry_config.yml"
1529
htpasswd="$rootfs/etc/registry_htpasswd"
16-
certs_dir="$rootfs/certs"
1730
image_dir="$rootfs/images"
1831

1932
mkdir -p "$VOLUME" || true
2033

34+
# shellcheck disable=SC2106
2135
startRegistry() {
2236
n=1
2337
while (( n <= 3 ))
@@ -66,17 +80,17 @@ fi
6680
regArgs="-d --restart=always \
6781
--net=host \
6882
--name $container \
69-
-v $certs_dir:/certs \
7083
-v $VOLUME:/var/lib/registry \
71-
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/$REGISTRY_DOMAIN.crt \
72-
-e REGISTRY_HTTP_TLS_KEY=/certs/$REGISTRY_DOMAIN.key"
84+
-e REGISTRY_HTTP_DEBUG_ADDR=0.0.0.0:5001 \
85+
-e REGISTRY_HTTP_DEBUG_PROMETHEUS_ENABLED=true"
7386

87+
# shellcheck disable=SC2086
7488
if [ -f $config ]; then
7589
sed -i "s/5000/$1/g" $config
7690
regArgs="$regArgs \
7791
-v $config:/etc/docker/registry/config.yml"
7892
fi
79-
93+
# shellcheck disable=SC2086
8094
if [ -f $htpasswd ]; then
8195
docker run $regArgs \
8296
-v $htpasswd:/htpasswd \

Diff for: context/rootfs/scripts/init.sh

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,21 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
# shellcheck disable=SC2181
1617
STORAGE=${1:-/var/lib/docker}
1718
REGISTRY_DOMAIN=${2-sea.hub}
1819
REGISTRY_PORT=${3-5000}
1920

2021
# Install docker
2122
chmod a+x docker.sh
2223
#./docker.sh /var/docker/lib sealer.hub 5001
23-
bash docker.sh ${STORAGE} ${REGISTRY_DOMAIN} $REGISTRY_PORT
24+
bash docker.sh "${STORAGE}" "${REGISTRY_DOMAIN}" "$REGISTRY_PORT"
25+
if [ $? -ne 0 ]; then
26+
exit 1
27+
fi
2428

2529
chmod a+x init-kube.sh
26-
2730
bash init-kube.sh
31+
if [ $? -ne 0 ]; then
32+
exit 1
33+
fi

Diff for: context/rootfs/scripts/nvidia-docker.sh

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#!/bin/bash
22

3-
scripts_path=$(cd `dirname $0`; pwd)
3+
# shellcheck disable=SC2046
4+
# shellcheck disable=SC2164
5+
# shellcheck disable=SC2092
6+
# shellcheck disable=SC1102
7+
# shellcheck disable=SC2006
8+
# shellcheck disable=SC2005
9+
# shellcheck disable=SC2181
10+
# shellcheck disable=SC1091
11+
scripts_path=$(cd `dirname "$0"`; pwd)
412
source "${scripts_path}"/utils.sh
513

614
set -x
@@ -46,7 +54,7 @@ public::nvidia::enable_gpu_device_plugin() {
4654
}
4755

4856
kube::nvidia::detect_gpu(){
49-
tar -xvf ${scripts_path}/../tgz/nvidia.tgz -C ${scripts_path}/../rpm/
57+
tar -xvf "${scripts_path}"/../tgz/nvidia.tgz -C "${scripts_path}"/../rpm/
5058
kube::nvidia::setup_lspci
5159
lspci | grep -i nvidia > /dev/null 2>&1
5260
if [[ "$?" == "0" ]]; then
@@ -59,7 +67,7 @@ kube::nvidia::setup_lspci(){
5967
return
6068
fi
6169
utils_info "lspci command not exist, install it"
62-
rpm -ivh --force --nodeps ${RPM_DIR}/pciutils*.rpm
70+
rpm -ivh --force --nodeps "${RPM_DIR}"/pciutils*.rpm
6371
if [[ "$?" != "0" ]]; then
6472
panic "failed to install pciutils via command (rpm -ivh --force --nodeps ${RPM_DIR}/pciutils*.rpm) in dir ${PWD}, please run it for debug"
6573
fi
@@ -76,12 +84,13 @@ public::nvidia::install_nvidia_driver(){
7684
public::nvidia::install_nvidia_docker2(){
7785
sleep 3
7886
if `which nvidia-container-runtime > /dev/null 2>&1` && [ $(echo $((docker info | grep nvidia) | wc -l)) -gt 1 ] ; then
79-
utils_info 'nvidia-container-runtime is already insatlled'
87+
utils_info 'nvidia-container-runtime is already installed'
8088
return
8189
fi
8290
8391
# 1. Install nvidia-container-runtime
84-
if ! output=$(rpm -ivh --force --nodeps `ls ${RPM_DIR}/*.rpm` 2>&1);then
92+
# shellcheck disable=SC2046
93+
if ! output=$(rpm -ivh --force --nodeps `ls "${RPM_DIR}"/*.rpm` 2>&1);then
8594
panic "failed to install rpm, output:${output}, maybe your rpm db was broken, please see https://cloudlinux.zendesk.com/hc/en-us/articles/115004075294-Fix-rpmdb-Thread-died-in-Berkeley-DB-library for help"
8695
fi
8796
@@ -108,9 +117,9 @@ public::nvidia::install_nvidia_docker2(){
108117
# deploy nvidia plugin in static pod
109118
public::nvidia::deploy_static_pod() {
110119
mkdir -p /etc/kubernetes/manifests
111-
cp -f ${scripts_path}/../statics/nvidia-device-plugin.yml /etc/kubernetes/manifests/nvidia-device-plugin.yml
120+
cp -f "${scripts_path}"/../statics/nvidia-device-plugin.yml /etc/kubernetes/manifests/nvidia-device-plugin.yml
112121
113-
utils_info "nvidia-device-plugin yaml succefully deployed ..."
122+
utils_info "nvidia-device-plugin yaml successfully deployed ..."
114123
}
115124
116125
public::nvidia::enable_gpu_capability

Diff for: context/rootfs/scripts/uninstall-docker.sh

+2-12
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ systemctl stop docker
44
ip link delete docker0 type bridge || true
55
rm -rf /lib/systemd/system/docker.service
66
rm -rf /usr/lib/systemd/system/docker.service
7-
rm -rf /etc/docker/daemon.json
7+
rm -rf /etc/docker
88
systemctl daemon-reload
99

1010
rm -f /usr/bin/conntrack
11-
rm -f /usr/bin/kubelet-pre-start.sh
1211
rm -f /usr/bin/containerd
1312
rm -f /usr/bin/containerd-shim
1413
rm -f /usr/bin/containerd-shim-runc-v2
@@ -18,19 +17,10 @@ rm -f /usr/bin/docker
1817
rm -f /usr/bin/docker-init
1918
rm -f /usr/bin/docker-proxy
2019
rm -f /usr/bin/dockerd
21-
rm -f /usr/bin/kubeadm
22-
rm -f /usr/bin/kubectl
23-
rm -f /usr/bin/kubelet
2420
rm -f /usr/bin/rootlesskit
2521
rm -f /usr/bin/rootlesskit-docker-proxy
2622
rm -f /usr/bin/runc
2723
rm -f /usr/bin/vpnkit
2824
rm -f /usr/bin/containerd-rootless-setuptool.sh
2925
rm -f /usr/bin/containerd-rootless.sh
30-
rm -f /usr/bin/nerdctl
31-
32-
rm -f /etc/sysctl.d/k8s.conf
33-
rm -f /etc/systemd/system/kubelet.service
34-
rm -rf /etc/systemd/system/kubelet.service.d
35-
rm -rf /var/lib/kubelet/
36-
rm -f /var/lib/kubelet/config.yaml
26+
rm -f /usr/bin/nerdctl

0 commit comments

Comments
 (0)