From ab9f9daba5674784c685befe9f6b64feff3da779 Mon Sep 17 00:00:00 2001 From: lukken <lukken@astron.nl> Date: Tue, 7 Dec 2021 09:50:03 +0000 Subject: [PATCH] L2SS-205: Address some feedback on patch --- .gitlab-ci.yml | 7 +--- docker-compose/Makefile | 3 +- sbin/tag_and_push_docker_image.sh | 58 +++++++++++++++++++++++++------ 3 files changed, 50 insertions(+), 18 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 88929fb36..4cb3b5415 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -49,7 +49,7 @@ stages: .base_docker_store_images: extends: .base_docker_images script: -# Do not remove 'bash' or statem ent will be ignored by primitive docker shell +# Do not remove 'bash' or statement will be ignored by primitive docker shell - bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh docker_store_images_master_tag: extends: .base_docker_store_images @@ -347,7 +347,6 @@ integration_test_docker: tag="$CI_COMMIT_REF_SLUG" echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag" fi - - echo $tag - apk add --update make bash docker-compose - apk add --update bind-tools - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY @@ -367,10 +366,6 @@ integration_test_docker: - chmod u+x $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh # Do not remove 'bash' or statement will be ignored by primitive docker shell - bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh pull $tag -# TODO(Corne): Remove me - - echo $tag - - docker image ls - - docker ps # Allow integration test to execute - chmod u+x $CI_PROJECT_DIR/sbin/run_integration_test.sh # Do not remove 'bash' or statement will be ignored by primitive docker shell diff --git a/docker-compose/Makefile b/docker-compose/Makefile index 71ce66e7f..6c6e3c888 100644 --- a/docker-compose/Makefile +++ b/docker-compose/Makefile @@ -33,6 +33,8 @@ else ifeq (stop,$(firstword $(MAKECMDGOALS))) SERVICE_TARGET = true else ifeq (restart,$(firstword $(MAKECMDGOALS))) SERVICE_TARGET = true +else ifeq (up,$(firstword $(MAKECMDGOALS))) + SERVICE_TARGET = true else ifeq (build,$(firstword $(MAKECMDGOALS))) SERVICE_TARGET = true else ifeq (build-nocache,$(firstword $(MAKECMDGOALS))) @@ -169,7 +171,6 @@ bootstrap: pull build # first start, initialise from scratch start: up ## start a service (usage: make start <servicename>) if [ $(UNAME_S) = Linux ]; then touch ~/.Xauthority; chmod a+r ~/.Xauthority; fi - echo "TEST COMMANDLINE: $(DOCKER_COMPOSE_ARGS) docker-compose $(COMPOSE_FILE_ARGS) start $(SERVICE)" $(DOCKER_COMPOSE_ARGS) docker-compose $(COMPOSE_FILE_ARGS) start $(SERVICE) stop: ## stop a service (usage: make stop <servicename>) diff --git a/sbin/tag_and_push_docker_image.sh b/sbin/tag_and_push_docker_image.sh index 814c51649..a6c250c03 100755 --- a/sbin/tag_and_push_docker_image.sh +++ b/sbin/tag_and_push_docker_image.sh @@ -1,5 +1,45 @@ #!/bin/bash -e +function usage { + echo "./$(basename $0) + no arguments, downloads remote images and pushes these to ASTRON registry. + The versions downloaded are controlled by the docker-compose/.env file" + echo "" + echo "./$(basename $0) -h + displays this help message" + echo "" + echo "./$(basename $0) <docker service name> <tag> + downloads latest version of image from the ASTRON registry, builds the + specified service and pushes the image with the specified tag to the + ASTRON registry" + echo "" + echo "./$(basename $0) pull <tag> + downloads all images for the integration test with the specified tag + falling back to 'latest' if unavailable. Should neither exist on the + ASTRON registry the script will exit 1. The images are retagged to match + the output of docker-compose." +} + +# list of arguments expected in the input +optstring=":h" + +while getopts ${optstring} arg; do + case ${arg} in + h) + usage + exit 0 + ;; + :) + echo "$0: Must supply an argument to -$OPTARG." >&2 + exit 1 + ;; + ?) + echo "Invalid option: -${OPTARG}." + exit 2 + ;; + esac +done + if [ -z "${LOFAR20_DIR+x}" ]; then echo "LOFAR20_DIR not set, did you forget to source lofar20rc.sh?" exit 1 @@ -8,13 +48,12 @@ fi # shellcheck disable=SC1090 . "${LOFAR20_DIR}/docker-compose/.env" || exit 1 -# Array of tuples separated by space inside double quotes -# These images are downloaded from a remote registry and pushed locally +# List of images and their tag REMOTE_IMAGES=( - "tango-dsconfig ${TANGO_DSCONFIG_VERSION}" "tango-java ${TANGO_JAVA_VERSION}" - "tango-itango ${TANGO_ITANGO_VERSION}" "tango-pogo ${TANGO_POGO_VERSION}" - "tango-cpp ${TANGO_CPP_VERSION}" "tango-db ${TANGO_DB_VERSION}" - "tango-dsconfig ${TANGO_DSCONFIG_VERSION}" "tango-rest ${TANGO_REST_VERSION}" + "tango-dsconfig:${TANGO_DSCONFIG_VERSION}" "tango-java:${TANGO_JAVA_VERSION}" + "tango-itango:${TANGO_ITANGO_VERSION}" "tango-pogo:${TANGO_POGO_VERSION}" + "tango-cpp:${TANGO_CPP_VERSION}" "tango-db:${TANGO_DB_VERSION}" + "tango-dsconfig:${TANGO_DSCONFIG_VERSION}" "tango-rest:${TANGO_REST_VERSION}" ) # If first argument of bash script not set run first stage @@ -23,11 +62,8 @@ if [ -z "${1+x}" ]; then # Iterate over al the REMOTE_IMAGES and pull them from remote and push local for image in "${REMOTE_IMAGES[@]}"; do - # Set, splits tuple into $1 and $2 - # shellcheck disable=SC2086 - set -- $image - remote_url="${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}-${1}:${2}" - local_url="${LOCAL_DOCKER_REGISTRY_HOST}/${LOCAL_DOCKER_REGISTRY_USER}/${1}:${2}" + remote_url="${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}-${image}" + local_url="${LOCAL_DOCKER_REGISTRY_HOST}/${LOCAL_DOCKER_REGISTRY_USER}/${image}" docker pull "${remote_url}" docker tag "${remote_url}" "${local_url}" docker push "${local_url}" -- GitLab