Skip to content

Commit c279f8f

Browse files
committed
Pass stack version as argument to image fetch function
This script reads and modifies environment variables for the processes it controls. This commit changes the way the `pull_docker_snapshot` function references variables. Specifically, we now explicitly pass arguments that are *not* managed as environment variables by the script as explicit parameters to the script instead of looking them up from global scope. The pattern this attempts to acheive is that the only thing looked up from global scope in a function is an argument that is actively being managed by the environment such that it remains consistent across any sub processes spawned by the shell script.
1 parent 9757da9 commit c279f8f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

docker-setup.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ set -e
66

77
pull_docker_snapshot() {
88
project="${1?project name required}"
9+
stack_version="${2?stack version required}"
910
local docker_image="docker.elastic.co/${project}/${project}${DISTRIBUTION_SUFFIX}:${ELASTIC_STACK_VERSION}"
1011
echo "Pulling $docker_image"
1112
if docker pull "$docker_image" ; then
1213
echo "docker pull successful"
1314
else
14-
case "$ELASTIC_STACK_VERSION_ARG" in
15+
case $stack_version in
1516
"8.previous"|"8.current"|"8.next")
1617
exit 1
1718
;;
@@ -30,7 +31,7 @@ if [ -z "${ELASTIC_STACK_VERSION}" ]; then
3031
exit 1
3132
fi
3233

33-
# save the original arg if needed
34+
# save the original unmodified string to pass to pull_docker_snapshot
3435
ELASTIC_STACK_VERSION_ARG="$ELASTIC_STACK_VERSION"
3536

3637
echo "Fetching versions from $VERSION_URL"
@@ -63,7 +64,7 @@ export DISTRIBUTION_SUFFIX
6364
echo "Testing against version: $ELASTIC_STACK_VERSION (distribution: ${DISTRIBUTION:-"default"})"
6465

6566
if [[ "$ELASTIC_STACK_VERSION" = *"-SNAPSHOT" ]]; then
66-
pull_docker_snapshot "logstash"
67+
pull_docker_snapshot "logstash" $ELASTIC_STACK_VERSION_ARG
6768
fi
6869

6970
if [ -f Gemfile.lock ]; then

0 commit comments

Comments
 (0)