summaryrefslogtreecommitdiff
path: root/start-container-docker.sh
diff options
context:
space:
mode:
authorDavid Spickett <david.spickett@linaro.org>2020-04-30 10:55:15 +0100
committerDavid Spickett <david.spickett@linaro.org>2020-04-30 11:05:22 +0100
commitb687c959bda4ad66a6ea330682ba8e1745ff38b7 (patch)
treeddf4461ca193d822c78585604d3be43ecd53dd7f /start-container-docker.sh
parent9f60d3366e38cefa3085610b4ef2bb03558d9d0d (diff)
start-container-docker.sh
Fix shellcheck warnings. Don't change the usage of DOCKER, as we rely on it splitting on space to get the correct commands. Add shebang and disable unused var warning for generated container.sh script. Change-Id: Ia4617f6eeaec4de507adbcf106f7272d246cc217
Diffstat (limited to 'start-container-docker.sh')
-rwxr-xr-xstart-container-docker.sh22
1 files changed, 16 insertions, 6 deletions
diff --git a/start-container-docker.sh b/start-container-docker.sh
index ff98d563..62761f54 100755
--- a/start-container-docker.sh
+++ b/start-container-docker.sh
@@ -1,6 +1,7 @@
#!/bin/bash
set -e -o pipefail
+# shellcheck source=jenkins-helpers.sh
. "$(dirname $0)"/jenkins-helpers.sh
# Start a local docker instance with the requested arch and distro
@@ -157,7 +158,7 @@ if $dryrun; then
dryruncmd="echo"
fi
-if [ x"$node" = x"" -a x"$session_host" = x"" -a x"$label" != x"" ]; then
+if [ x"$node" = x"" ] && [ x"$session_host" = x"" ] && [ x"$label" != x"" ]; then
node=$(print_node_with_least_containers "$label")
if [ x"$node" = x"" ]; then
echo "ERROR: Cannot find node for $label"
@@ -197,7 +198,7 @@ if [ x"$session_name" = x ]; then
# Set the default session_name, using BUILD_NUMBER and JOB_NAME,
# as set by Jenkins.
# shellcheck disable=SC2153
- if [ "x$BUILD_NUMBER" != "x" -a "x$JOB_NAME" != "x" ]; then
+ if [ "x$BUILD_NUMBER" != "x" ] && [ "x$JOB_NAME" != "x" ]; then
session_name="$BUILD_NUMBER-$JOB_NAME"
else
session_name="$USER-$(date +%Y%m%d-%H_%M_%S)"
@@ -214,6 +215,11 @@ image=linaro/ci-${container_arch}-tcwg-build-ubuntu:${distro}
# Avoid connexion sharing because of race conditions with parallel
# builds
SSH="ssh -S none"
+# Note that when we use this we *want* it to split on spaces
+# So that the shell runs:
+# foo bar docker <...>
+# Instead of:
+# "foo bar docker" <...>
DOCKER="$dryruncmd $SSH $session_host docker"
$DOCKER pull $image || ssh_error $?
@@ -242,7 +248,7 @@ if [ x"${JOB_NAME:+set}" = x"set" ]; then
job_name="$JOB_NAME"
fi
-bind_mounts=($(print_bind_mounts "$task" "$SSH $session_host"))
+IFS=" " read -r -a bind_mounts <<< "$(print_bind_mounts "$task" "$SSH $session_host")"
docker_root=""
if $SSH $session_host test -f "/.dockerenv" \
@@ -278,7 +284,7 @@ for bind_mount in "${bind_mounts[@]}"; do
bind_mounts_opt=("${bind_mounts_opt[@]}" "-v" "$dir:$bind_mount")
done
-volume_mounts=($(print_volume_mounts "$job_name" "-$container_arch-$distro"))
+IFS=" " read -r -a volume_mounts <<< "$(print_volume_mounts "$job_name" "-$container_arch-$distro")"
for mount in "${volume_mounts[@]}"; do
bind_mounts_opt=("${bind_mounts_opt[@]}" "-v" "$mount")
done
@@ -293,12 +299,13 @@ done
cpuset_opt="--cpuset-cpus 0-$(($nproc - 1))"
echo "DEBUG: starting docker on $session_host from $(hostname), date $(date)"
+# shellcheck disable=SC2206
docker_run=($DOCKER run --name $session_name -dtP \
"${bind_mounts_opt[@]}" \
${SECURITY} \
${memory_opt} \
- --pids-limit=${pids} \
- --cpu-shares=${cpus} \
+ "--pids-limit=${pids}" \
+ "--cpu-shares=${cpus}" \
$cpuset_opt \
${docker_opts} \
$image) || ssh_error $?
@@ -374,6 +381,9 @@ fi
exec 1>&3 2>&4
cat <<EOF
+#!/bin/bash
+# The vars are used when this script is sourced
+# shellcheck disable=SC2034
# v1 interface
CONTAINER="${dryruncmd} $SSH -p ${session_port} ${user}${session_host}"
CONTAINER_CLEANUP="${CONTAINER_CLEANUP}; if $cleanup_lock; then $SSH $session_host flock $WORKSPACE/.lock rm $WORKSPACE/.lock; fi"