Skip to content

Commit c189282

Browse files
committed
optimize rootfs scripts
1 parent 5adf576 commit c189282

File tree

7 files changed

+68
-32
lines changed

7 files changed

+68
-32
lines changed

context/rootfs/scripts/docker.sh

Lines changed: 6 additions & 2 deletions
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:]')"

context/rootfs/scripts/init-kube.sh

Lines changed: 6 additions & 2 deletions
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

context/rootfs/scripts/init-registry.sh

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
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}
1025
REGISTRY_DOMAIN=${3-sea.hub}
@@ -18,6 +33,7 @@ image_dir="$rootfs/images"
1833

1934
mkdir -p "$VOLUME" || true
2035

36+
# shellcheck disable=SC2106
2137
startRegistry() {
2238
n=1
2339
while (( n <= 3 ))
@@ -69,22 +85,25 @@ regArgs="-d --restart=always \
6985
-v $certs_dir:/certs \
7086
-v $VOLUME:/var/lib/registry \
7187
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/$REGISTRY_DOMAIN.crt \
72-
-e REGISTRY_HTTP_TLS_KEY=/certs/$REGISTRY_DOMAIN.key"
88+
-e REGISTRY_HTTP_TLS_KEY=/certs/$REGISTRY_DOMAIN.key \
89+
-e REGISTRY_HTTP_DEBUG_ADDR=0.0.0.0:5001 \
90+
-e REGISTRY_HTTP_DEBUG_PROMETHEUS_ENABLED=true"
7391

74-
if [ -f $config ]; then
75-
sed -i "s/5000/$1/g" $config
92+
if [ -f "$config" ]; then
93+
sed -i "s/5000/$1/g" "$config"
7694
regArgs="$regArgs \
7795
-v $config:/etc/docker/registry/config.yml"
7896
fi
7997

80-
if [ -f $htpasswd ]; then
81-
docker run $regArgs \
98+
# shellcheck disable=SC2086
99+
if [ -f "$htpasswd" ]; then
100+
docker run "$regArgs" \
82101
-v $htpasswd:/htpasswd \
83102
-e REGISTRY_AUTH=htpasswd \
84103
-e REGISTRY_AUTH_HTPASSWD_PATH=/htpasswd \
85104
-e REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm" registry:2.7.1 || startRegistry
86105
else
87-
docker run $regArgs registry:2.7.1 || startRegistry
106+
docker run "$regArgs" registry:2.7.1 || startRegistry
88107
fi
89108

90109
check_registry

context/rootfs/scripts/init.sh

Lines changed: 8 additions & 2 deletions
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

context/rootfs/scripts/nvidia-docker.sh

Lines changed: 16 additions & 7 deletions
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

context/rootfs/scripts/uninstall-docker.sh

Lines changed: 2 additions & 12 deletions
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

context/rootfs/scripts/utils.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/bin/bash
22

3+
# shellcheck disable=SC2145
4+
# shellcheck disable=SC2155
5+
# shellcheck disable=SC2126
6+
# shellcheck disable=SC2002
37
utils_version_ge() {
48
test "$(echo "$@" | tr ' ' '\n' | sort -rV | head -n 1)" == "$1"
59
}
@@ -59,7 +63,7 @@ utils_os_env() {
5963
elif [ "$anolis" == 1 ];then
6064
export OS="Anolis"
6165
else
62-
panic "unkown os... exit"
66+
panic "unknown os... exit"
6367
fi
6468

6569
case "$OS" in

0 commit comments

Comments
 (0)