Skip to content

Commit

Permalink
optimize rootfs scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevent-fei committed Dec 5, 2022
1 parent 52ffd31 commit 94f8f8c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 16 deletions.
6 changes: 4 additions & 2 deletions context/rootfs/scripts/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ set -x
set -e

# shellcheck disable=SC2046
scripts_path=$(cd `dirname $0`; pwd)
# shellcheck disable=SC2006
scripts_path=$(cd `dirname "$0"`; pwd)
image_dir="$scripts_path/../images"
DOCKER_VERSION="19.03.14-sealer"

Expand Down Expand Up @@ -47,6 +48,7 @@ load_images() {
done
}

# shellcheck disable=SC2006
check_docker_valid() {
if ! docker info 2>&1; then
panic "docker is not healthy: $(docker info 2>&1), please check"
Expand All @@ -59,7 +61,7 @@ check_docker_valid() {
}

storage=${1:-/var/lib/docker}
mkdir -p $storage
mkdir -p "$storage"
if ! utils_command_exists docker; then
lsb_dist=$(get_distribution)
lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
Expand Down
5 changes: 3 additions & 2 deletions context/rootfs/scripts/init-kube.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

# shellcheck disable=SC2046
# shellcheck disable=SC2164
scripts_path=$(cd `dirname $0`; pwd)
# shellcheck disable=SC2006
scripts_path=$(cd `dirname "$0"`; pwd)
source "${scripts_path}"/utils.sh

set -x
Expand Down Expand Up @@ -58,4 +59,4 @@ copy_kubelet_service
systemctl enable kubelet

# nvidia-docker.sh need set kubelet labels, it should be run after kubelet
bash ${scripts_path}/nvidia-docker.sh || exit 1
bash "${scripts_path}"/nvidia-docker.sh || exit 1
11 changes: 6 additions & 5 deletions context/rootfs/scripts/init-registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,21 @@ regArgs="-d --restart=always \
-e REGISTRY_HTTP_DEBUG_ADDR=0.0.0.0:5001 \
-e REGISTRY_HTTP_DEBUG_PROMETHEUS_ENABLED=true"

if [ -f $config ]; then
sed -i "s/5000/$1/g" $config
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
docker run $regArgs \
# 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
docker run "$regArgs" registry:2.7.1 || startRegistry
fi

check_registry
3 changes: 2 additions & 1 deletion context/rootfs/scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

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

# Install docker
chmod a+x docker.sh
#./docker.sh /var/docker/lib sealer.hub 5001
bash docker.sh ${STORAGE} ${REGISTRY_DOMAIN} $REGISTRY_PORT
bash docker.sh "${STORAGE}" "${REGISTRY_DOMAIN}" "$REGISTRY_PORT"
if [ $? -ne 0 ]; then
exit 1
fi
Expand Down
15 changes: 9 additions & 6 deletions context/rootfs/scripts/nvidia-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
# shellcheck disable=SC2164
# shellcheck disable=SC2092
# shellcheck disable=SC1102
scripts_path=$(cd `dirname $0`; pwd)
# shellcheck disable=SC2006
# shellcheck disable=SC2005
# shellcheck disable=SC2181
scripts_path=$(cd `dirname "$0"`; pwd)
source "${scripts_path}"/utils.sh

set -x
Expand Down Expand Up @@ -50,7 +53,7 @@ public::nvidia::enable_gpu_device_plugin() {
}

kube::nvidia::detect_gpu(){
tar -xvf ${scripts_path}/../tgz/nvidia.tgz -C ${scripts_path}/../rpm/
tar -xvf "${scripts_path}"/../tgz/nvidia.tgz -C ${scripts_path}/../rpm/
kube::nvidia::setup_lspci
lspci | grep -i nvidia > /dev/null 2>&1
if [[ "$?" == "0" ]]; then
Expand Down Expand Up @@ -80,13 +83,13 @@ public::nvidia::install_nvidia_driver(){
public::nvidia::install_nvidia_docker2(){
sleep 3
if `which nvidia-container-runtime > /dev/null 2>&1` && [ $(echo $((docker info | grep nvidia) | wc -l)) -gt 1 ] ; then
utils_info 'nvidia-container-runtime is already insatlled'
utils_info 'nvidia-container-runtime is already installed'
return
fi
# 1. Install nvidia-container-runtime
# shellcheck disable=SC2046
if ! output=$(rpm -ivh --force --nodeps `ls ${RPM_DIR}/*.rpm` 2>&1);then
if ! output=$(rpm -ivh --force --nodeps `ls "${RPM_DIR}"/*.rpm` 2>&1);then
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"
fi
Expand All @@ -113,9 +116,9 @@ public::nvidia::install_nvidia_docker2(){
# deploy nvidia plugin in static pod
public::nvidia::deploy_static_pod() {
mkdir -p /etc/kubernetes/manifests
cp -f ${scripts_path}/../statics/nvidia-device-plugin.yml /etc/kubernetes/manifests/nvidia-device-plugin.yml
cp -f "${scripts_path}"/../statics/nvidia-device-plugin.yml /etc/kubernetes/manifests/nvidia-device-plugin.yml
utils_info "nvidia-device-plugin yaml succefully deployed ..."
utils_info "nvidia-device-plugin yaml successfully deployed ..."
}
public::nvidia::enable_gpu_capability
Expand Down
2 changes: 2 additions & 0 deletions context/rootfs/scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# shellcheck disable=SC2145
# shellcheck disable=SC2155
# shellcheck disable=SC2126
# shellcheck disable=SC2002
utils_version_ge() {
test "$(echo "$@" | tr ' ' '\n' | sort -rV | head -n 1)" == "$1"
}
Expand Down

0 comments on commit 94f8f8c

Please sign in to comment.