Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shellcheck for docker swarm scripts. #246

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions docker-swarm/almalinux-8/build-vespanode-baselinebase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

DEBUG_IMAGE=false

args=`getopt d $*`
args=$(getopt d "$@")
# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
echo "Usage: build-vespanode-baselinebase.sh [-d]" 1>&2
exit 1
fi
# shellcheck disable=SC2086
set -- $args
while :; do
case "$1" in
Expand Down Expand Up @@ -43,24 +45,24 @@ fi
CONTAINER_NAME=$USER-build-vespanode-baselinebase-almalinux-8
BASELINEBASE_NAME=$USER-vespanode-baselinebase-almalinux-8

docker stop $CONTAINER_NAME
docker container rm $CONTAINER_NAME
docker stop "$CONTAINER_NAME"
docker container rm "$CONTAINER_NAME"

if docker run \
--name $CONTAINER_NAME \
--env RUBYLIB=/home/$USER/git/system-test/lib:/home/$USER/git/system-test/tests \
--env USER=$USER \
--env VESPA_HOME=/home/$USER/vespa \
--env VESPA_SYSTEM_TEST_HOME=/home/$USER/git/system-test \
--name "$CONTAINER_NAME" \
--env RUBYLIB="/home/$USER/git/system-test/lib:/home/$USER/git/system-test/tests" \
--env USER="$USER" \
--env VESPA_HOME=/home/"$USER"/vespa \
--env VESPA_SYSTEM_TEST_HOME=/home/"$USER"/git/system-test \
--env VESPA_SYSTEM_TEST_USE_TLS=true \
--env VESPA_USER=$USER \
$DEVIMAGE \
--env VESPA_USER="$USER" \
"$DEVIMAGE" \
bash -cxe "(groupadd -g $(id -g) $(id -gn) || true) && useradd -M -g $(id -g) -u $(id -u) -c 'vespanode user' $USER && mkdir /home/$USER && chown $(id -u):$(id -g) /home/$USER && echo '$USER ALL=(ALL) NOPASSWD: ALL' >>/etc/sudoers"
then
echo "Created user $USER"
docker commit --change "USER $USER" --change "WORKDIR /home/$USER" $CONTAINER_NAME $BASELINEBASE_NAME
docker commit --change "USER $USER" --change "WORKDIR /home/$USER" "$CONTAINER_NAME" "$BASELINEBASE_NAME"
else
echo "Failed creating user $USER" 1>&2
exit 1
fi
docker container rm $CONTAINER_NAME
docker container rm "$CONTAINER_NAME"
2 changes: 2 additions & 0 deletions docker-swarm/almalinux-8/build-vespanode-in-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ rsync -aHvSx --delete /mnt/.m2/ .m2/

set +x
set +e
# shellcheck disable=SC1091
. ./.bash_profile
# shellcheck disable=SC1091
test -f .bashrc && . ./.bashrc
set -e
set -x
Expand Down
26 changes: 14 additions & 12 deletions docker-swarm/almalinux-8/build-vespanode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
VOLUME=
buildmode=normal

args=`getopt m:v: $*`
args=$(getopt m:v: "$@")
# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
echo "Usage: build-vespanode.sh [-m (normal|baseline|fixup)] [-v homevolume]" 1>&2
exit 1
fi
# shellcheck disable=SC2086
set -- $args
while :; do
case "$1" in
Expand All @@ -30,15 +32,15 @@ then
exit 1
fi

. $(dirname $0)/vespanode-common.sh
. "$(dirname "$0")"/vespanode-common.sh

if test -z "$VOLUME"
then
VOLUME=$VESPA_DEV_VOLUME
fi

case "$VOLUME" in
/*) if test -d $VOLUME -a -d $VOLUME/git/system-test -a -d $VOLUME/bin -a -d $VOLUME/vespa
/*) if test -d "$VOLUME" -a -d "$VOLUME"/git/system-test -a -d "$VOLUME"/bin -a -d "$VOLUME"/vespa
then
:
else
Expand All @@ -49,7 +51,7 @@ case "$VOLUME" in
found=false
for v in ${VOLUMELIST}
do
test $v = $VOLUME && found=true
test "$v" = "$VOLUME" && found=true
done
if $found
then
Expand All @@ -71,22 +73,22 @@ BUILD_CONTAINER_NAME=$USER-build-vespanode-almalinux-8-$$

echo "Making vespanode image"

docker stop $BUILD_CONTAINER_NAME || true
docker container rm $BUILD_CONTAINER_NAME || true
docker stop "$BUILD_CONTAINER_NAME" || true
docker container rm "$BUILD_CONTAINER_NAME" || true

if docker run \
--name $BUILD_CONTAINER_NAME \
-v ${VOLUME}:/mnt \
-v $(pwd):/mnt2 \
${DOCKER_IMAGE} \
--name "$BUILD_CONTAINER_NAME" \
-v "${VOLUME}":/mnt \
-v "$(pwd)":/mnt2 \
"${DOCKER_IMAGE}" \
/mnt2/build-vespanode-in-container.sh
then
echo "Made vespanode image"
docker commit \
--change "ENV VESPA_TLS_CONFIG_FILE=/home/$USER/vespa/conf/vespa/tls/tls_config.json" \
--change 'CMD [ "bash", "-lc", "bin/run-vespanode.sh" ]' \
$BUILD_CONTAINER_NAME $DOCKER_NEW_IMAGE
"$BUILD_CONTAINER_NAME" "$DOCKER_NEW_IMAGE"
else
echo "Failed creating vespanode image"
fi
docker container rm $BUILD_CONTAINER_NAME
docker container rm "$BUILD_CONTAINER_NAME"
4 changes: 2 additions & 2 deletions docker-swarm/almalinux-8/disable-vespanode-host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ node=$1
NODELIST=$(docker node ls --format '{{.Hostname}}' | tr '\n' ' ')

for checknode in $NODELIST; do
if test $checknode = $node
if test "$checknode" = "$node"
then
docker node update --label-rm enable-$USER-vespanode $node
docker node update --label-rm enable-"$USER"-vespanode "$node"
exit 0
fi
done
Expand Down
5 changes: 3 additions & 2 deletions docker-swarm/almalinux-8/distribute-vespanode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

host=$1
DOCKER_IMAGE=$2
. $(dirname $0)/vespanode-common.sh
ssh -a $SSH_REGISTRY_TUNNEL_ARG -o ExitOnForwardFailure=yes $host bash -lc "'git/docker-image-dev/docker-swarm/almalinux-8/download-vespanode.sh $DOCKER_IMAGE $TUNNELED_REGISTRY'"
. "$(dirname "$0")"/vespanode-common.sh
# shellcheck disable=SC2086
ssh -a $SSH_REGISTRY_TUNNEL_ARG -o ExitOnForwardFailure=yes "$host" bash -lc "'git/docker-image-dev/docker-swarm/almalinux-8/download-vespanode.sh $DOCKER_IMAGE $TUNNELED_REGISTRY'"
8 changes: 4 additions & 4 deletions docker-swarm/almalinux-8/download-vespanode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ TUNNELED_REGISTRY=$2
if test -z "$TUNNELED_REGISTRY"
then
# No tunneling, use local registry
. $(dirname $0)/vespanode-common.sh
. "$(dirname "$0")"/vespanode-common.sh
TUNNELED_REGISTRY=$LOCAL_REGISTRY
fi
echo "Downloading vespanode image ${DOCKER_IMAGE} on $(hostname)"
docker pull ${TUNNELED_REGISTRY}/${DOCKER_IMAGE}
docker tag ${TUNNELED_REGISTRY}/${DOCKER_IMAGE} ${DOCKER_IMAGE}
docker image rm ${TUNNELED_REGISTRY}/${DOCKER_IMAGE}
docker pull "${TUNNELED_REGISTRY}/${DOCKER_IMAGE}"
docker tag "${TUNNELED_REGISTRY}/${DOCKER_IMAGE}" "${DOCKER_IMAGE}"
docker image rm "${TUNNELED_REGISTRY}/${DOCKER_IMAGE}"
4 changes: 2 additions & 2 deletions docker-swarm/almalinux-8/enable-vespanode-host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ node=$1
NODELIST=$(docker node ls --format '{{.Hostname}}' | tr '\n' ' ')

for checknode in $NODELIST; do
if test $checknode = $node
if test "$checknode" = "$node"
then
docker node update --label-add enable-$USER-vespanode=true $node
docker node update --label-add enable-"$USER"-vespanode=true "$node"
exit 0
fi
done
Expand Down
8 changes: 4 additions & 4 deletions docker-swarm/almalinux-8/remove-vespanode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

DOCKER_IMAGE=$1
. $(dirname $0)/vespanode-common.sh
. "$(dirname "$0")"/vespanode-common.sh
echo "Removing vespanode image ${DOCKER_IMAGE} on $(hostname)"
docker image rm ${TUNNELED_REGISTRY}/${DOCKER_IMAGE}
docker image rm ${LOCAL_REGISTRY}/${DOCKER_IMAGE}
docker image rm ${DOCKER_IMAGE}
docker image rm "${TUNNELED_REGISTRY}/${DOCKER_IMAGE}"
docker image rm "${LOCAL_REGISTRY}/${DOCKER_IMAGE}"
docker image rm "${DOCKER_IMAGE}"
true
3 changes: 2 additions & 1 deletion docker-swarm/almalinux-8/run-all-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ SERVICE_RAMDISK="--service-ramdisk"
SERVICE_RESERVE_MEMORY="--service-reserve-memory 9GB"
TEST_SELECTION=""

$HOME/git/system-test/bin/run-tests-on-swarm.sh -i $USER-vespanode-almalinux-8 -n $NUMNODES $SERVICE_CONSTRAINT $SERVICE_RAMDISK $SERVICE_RESERVE_MEMORY --resultdir $(pwd)/systemtests-swarm -c -d 5 $TEST_SELECTION
# shellcheck disable=SC2086
"$HOME"/git/system-test/bin/run-tests-on-swarm.sh -i "$USER"-vespanode-almalinux-8 -n "$NUMNODES" $SERVICE_CONSTRAINT $SERVICE_RAMDISK $SERVICE_RESERVE_MEMORY --resultdir "$(pwd)"/systemtests-swarm -c -d 5 $TEST_SELECTION
3 changes: 2 additions & 1 deletion docker-swarm/almalinux-8/run-basic-search-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ SERVICE_RAMDISK="--service-ramdisk"
SERVICE_RESERVE_MEMORY="--service-reserve-memory 6GB"
TEST_SELECTION="--file search/basicsearch/basic_search.rb"

$HOME/git/system-test/bin/run-tests-on-swarm.sh -i $USER-vespanode-almalinux-8 -n $NUMNODES $SERVICE_CONSTRAINT $SERVICE_RAMDISK $SERVICE_RESERVE_MEMORY --resultdir $(pwd)/systemtests-swarm -c -d 5 $TEST_SELECTION
# shellcheck disable=SC2086
"$HOME"/git/system-test/bin/run-tests-on-swarm.sh -i "$USER"-vespanode-almalinux-8 -n "$NUMNODES" $SERVICE_CONSTRAINT $SERVICE_RAMDISK $SERVICE_RESERVE_MEMORY --resultdir "$(pwd)"/systemtests-swarm -c -d 5 $TEST_SELECTION
3 changes: 2 additions & 1 deletion docker-swarm/almalinux-8/run-feed-block-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ SERVICE_RAMDISK="--service-ramdisk"
SERVICE_RESERVE_MEMORY="--service-reserve-memory 6GB"
TEST_SELECTION="--file search/feed_block/feed_block.rb --file search/feed_block/feed_block_disk_two_nodes.rb --file search/feed_block/feed_block_shared_disk_two_nodes.rb"

$HOME/git/system-test/bin/run-tests-on-swarm.sh -i $USER-vespanode-almalinux-8 -n $NUMNODES $SERVICE_CONSTRAINT $SERVICE_RAMDISK $SERVICE_RESERVE_MEMORY --resultdir $(pwd)/systemtests-swarm -c -d 5 $TEST_SELECTION
# shellcheck disable=SC2086
"$HOME"/git/system-test/bin/run-tests-on-swarm.sh -i "$USER"-vespanode-almalinux-8 -n "$NUMNODES" $SERVICE_CONSTRAINT $SERVICE_RAMDISK $SERVICE_RESERVE_MEMORY --resultdir "$(pwd)"/systemtests-swarm -c -d 5 $TEST_SELECTION
3 changes: 2 additions & 1 deletion docker-swarm/almalinux-8/run-resize-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ SERVICE_RAMDISK="--service-ramdisk"
SERVICE_RESERVE_MEMORY="--service-reserve-memory 6GB"
TEST_SELECTION="--file search/resize/resize.rb"

$HOME/git/system-test/bin/run-tests-on-swarm.sh -i $USER-vespanode-almalinux-8 -n $NUMNODES $SERVICE_CONSTRAINT $SERVICE_RAMDISK $SERVICE_RESERVE_MEMORY --resultdir $(pwd)/systemtests-swarm -c -d 5 $TEST_SELECTION
# shellcheck disable=SC2086
"$HOME"/git/system-test/bin/run-tests-on-swarm.sh -i "$USER"-vespanode-almalinux-8 -n "$NUMNODES" $SERVICE_CONSTRAINT $SERVICE_RAMDISK $SERVICE_RESERVE_MEMORY --resultdir "$(pwd)"/systemtests-swarm -c -d 5 $TEST_SELECTION
8 changes: 4 additions & 4 deletions docker-swarm/almalinux-8/run-vespanode-registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ then
echo "registry:2 docker image is missing." 1>&2
exit 1
fi
. $(dirname $0)/vespanode-common.sh
. "$(dirname "$0")"/vespanode-common.sh
CONTAINER_NAME=$USER-vespanode-registry
VOLUME_NAME=${CONTAINER_NAME}
docker container stop ${CONTAINER_NAME}
docker container rm ${CONTAINER_NAME}
docker run -d -p ${LOCAL_REGISTRY}:5000 -v ${VOLUME_NAME}:/var/lib/registry --name ${CONTAINER_NAME} registry:2
docker container stop "${CONTAINER_NAME}"
docker container rm "${CONTAINER_NAME}"
docker run -d -p "${LOCAL_REGISTRY}:5000" -v "${VOLUME_NAME}":/var/lib/registry --name "${CONTAINER_NAME}" registry:2
9 changes: 5 additions & 4 deletions docker-swarm/almalinux-8/run-vespanode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ if sudo -n echo non-interactive sudo works
then
fixup_owner()
{
sudo -n chown $(id -u):$(id -g) $1
sudo -n chown "$(id -u):$(id -g)" "$1"
}
else
fixup_owner()
{
echo no fixup owner for $1 due to non-interactive sudo not working
echo "no fixup owner for $1 due to non-interactive sudo not working"
}
fi

fixup_dir()
{
test -O $1 || fixup_owner $1
test -O $1 && chmod $2 $1
test -O "$1" || fixup_owner "$1"
test -O "$1" && chmod "$2" "$1"
}

# Workaround for tmpfs-mode not working for docker service mounts.
Expand All @@ -41,4 +41,5 @@ fixup_dir vespa/var/zookeeper 1777
# If vespa/var/db/vespa is tmpfs mounted then create logcontrol directory
mkdir -p vespa/var/db/vespa/logcontrol

# shellcheck disable=SC2086
nodeserver.sh $NODE_SERVER_OPTS
2 changes: 1 addition & 1 deletion docker-swarm/almalinux-8/stop-tests-on-swarm.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

$HOME/git/system-test/bin/run-tests-on-swarm.sh --stop
"$HOME"/git/system-test/bin/run-tests-on-swarm.sh --stop
8 changes: 4 additions & 4 deletions docker-swarm/almalinux-8/upload-vespanode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

DOCKER_IMAGE=$1
. $(dirname $0)/vespanode-common.sh
. "$(dirname "$0")"/vespanode-common.sh
echo "Uploading vespanode image ${DOCKER_IMAGE} on $(hostname)"
docker tag ${DOCKER_IMAGE} ${LOCAL_REGISTRY}/${DOCKER_IMAGE}
docker push ${LOCAL_REGISTRY}/${DOCKER_IMAGE}
docker image rm ${LOCAL_REGISTRY}/${DOCKER_IMAGE}
docker tag "${DOCKER_IMAGE}" "${LOCAL_REGISTRY}/${DOCKER_IMAGE}"
docker push "${LOCAL_REGISTRY}/${DOCKER_IMAGE}"
docker image rm "${LOCAL_REGISTRY}/${DOCKER_IMAGE}"
10 changes: 7 additions & 3 deletions docker-swarm/almalinux-8/vespanode-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

# Sample settings
if test -d $HOME/volumes/vespa-dev-almalinux-8
if test -d "$HOME"/volumes/vespa-dev-almalinux-8
then
# shellcheck disable=SC2034
VESPA_DEV_VOLUME=$HOME/volumes/vespa-dev-almalinux-8
else
# shellcheck disable=SC2034
VESPA_DEV_VOLUME=volume-vespa-dev-almalinux-8
fi
VESPANODE_IMAGE_SUFFIX=almalinux-8
LOCAL_REGISTRY_PORT=5000
TUNNELED_REGISTRY_PORT=5000
LOCAL_REGISTRY=127.0.0.1:$LOCAL_REGISTRY_PORT
TUNNELED_REGISTRY=127.0.0.1:$TUNNELED_REGISTRY_PORT
# shellcheck disable=SC2034
SSH_REGISTRY_TUNNEL_ARG="-R $TUNNELED_REGISTRY:$LOCAL_REGISTRY"

# Pick up overrides
for overrides_file in $HOME/.vespa-docker-image-dev-swarm-settings $HOME/.vespa-docker-image-dev-swarm-settings-$VESPANODE_IMAGE_SUFFIX
for overrides_file in "$HOME"/.vespa-docker-image-dev-swarm-settings "$HOME"/.vespa-docker-image-dev-swarm-settings-"$VESPANODE_IMAGE_SUFFIX"
do
test -x $overrides_file && . $overrides_file
# shellcheck disable=SC1090
test -x "$overrides_file" && . "$overrides_file"
done
true