diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7e0a886c1c8eb799449f9593d6323de937b1cea5..afbfaa7c22aed2a31b256ff27ab9dc45a1224ae0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -61,6 +61,20 @@ docker_store_images_changes: refs: - tags - master +# TODO(Corne): Remove this job after it has run once +docker_build_image_all: + extends: .base_docker_images + script: + - bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh lofar-device-base $tag + - bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh elk $tag + - bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh elk-configure-host $tag + - bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh grafana $tag + - bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh prometheus $tag + - bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh lofar-device-base $tag + - bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh jupyter $tag + - bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh itango $tag + - bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh integration-test $tag + - bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh tango-prometheus-exporter $tag docker_build_image_elk: extends: .base_docker_images only: @@ -90,14 +104,14 @@ docker_build_image_prometheus: script: # Do not remove 'bash' or statement will be ignored by primitive docker shell - bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh prometheus $tag -#docker_build_image_docker-compose_itango: -# extends: .base_docker_images -# only: -# changes: -# - docker-compose/itango.yml -# script: -# # Do not remove 'bash' or statement will be ignored by primitive docker shell -# - bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh itango +docker_build_image_itango: + extends: .base_docker_images + only: + changes: + - docker-compose/itango.yml + script: +# Do not remove 'bash' or statement will be ignored by primitive docker shell + - bash $CI_PROJECT_DIR/sbin/tag_and_push_docker_image.sh itango $tag docker_build_image_grafana: extends: .base_docker_images only: diff --git a/sbin/tag_and_push_docker_image.sh b/sbin/tag_and_push_docker_image.sh index 661ad31583fabebdc31dd68c9000576a96fc7a4f..484b1d6818691ad61a9d222a27f00a4415e005f1 100755 --- a/sbin/tag_and_push_docker_image.sh +++ b/sbin/tag_and_push_docker_image.sh @@ -39,14 +39,13 @@ fi # Tuple of images and queries to detect changes # TODO(Corne): Have this list generated from the .yml files LOCAL_IMAGES=( - "elk" "elk-configure-host" "grafana" "prometheus" "lofar-device-base" + "elk elk" "elk-configure-host elk-configure-host" "grafana grafana" + "prometheus prometheus" "lofar-device-base lofar-device-base" + "jupyter docker-compose_jupyter" "itango docker-compose_itango" + "integration-test docker-compose_integration-test" + "tango-prometheus-exporter docker-compose_tango-prometheus-exporter" ) -# TBD TODO(Corne): Verify using these images as cache works -# "docker-compose_jupyter" "docker-compose_integration-test" -# "docker-compose_itango" "docker-compose_tango-prometheus-exporter" -#) - # If first argument set run second stage, determine LOCAL_IMAGE to build and # push from the argument if [ ! -z "${1+x}" ] && [ "${1}" != "pull" ]; then @@ -57,16 +56,20 @@ if [ ! -z "${1+x}" ] && [ "${1}" != "pull" ]; then exit 1 fi - # Set the tag variable + # Set the tag and image variable, variables $1 and $2 are shadowed later + local_image="${1}" tag="${2}" cd "${LOFAR20_DIR}/docker-compose" || exit 1 # Loop through images and find the specified one for image in "${LOCAL_IMAGES[@]}"; do - if [ "${1}" == "${image}" ]; then - echo "Building image for ${image} container" - local_url="${LOCAL_DOCKER_REGISTRY_HOST}/${LOCAL_DOCKER_REGISTRY_USER}/${image}" + # Set, splits tuple into $1 and $2. this shadows previous variables + # shellcheck disable=SC2086 + set -- $image + if [ "${local_image}" == "${1}" ]; then + echo "Building image for ${1} container" + local_url="${LOCAL_DOCKER_REGISTRY_HOST}/${LOCAL_DOCKER_REGISTRY_USER}/${2}" # If tag is not latest, than it is not a tagged master build and we can # pull the latest image as cache. @@ -74,8 +77,8 @@ if [ ! -z "${1+x}" ] && [ "${1}" != "pull" ]; then docker pull "${local_url}:latest" fi - make build "${image}" - docker tag "${image}" "${local_url}:${tag}" + make build "${1}" + docker tag "${2}" "${local_url}:${tag}" docker push "${local_url}:${tag}" fi done