From 602bfb1660f5a0a3b8cdae11d4637d60398bf5b3 Mon Sep 17 00:00:00 2001 From: Jessica Wagantall Date: Wed, 29 May 2019 17:43:45 -0700 Subject: [PATCH 1/1] Update docker scripts - docker-build: Allow DOCKER_ARGS to be empty. This is not a required parameter, it can be empty. - docker-get-git-describe: Remove container reference. The CONTAINER_PUSH_REGISTRY already gets added in the docker-push script. No need to add it again. Only process the tag variable. - docker-get-yaml-tag: Rename image_name to image_build_tag to match docker-get-git-describe. Add missing "DOCKER_NAME" in the DOCKER_IMAGE. Only process the tag variable. - docker-push: Update the correct image name and tag in the push command. Change-Id: Ic3aad7ae0f87b589ce5d57f6848f7e8e75f9b71e Signed-off-by: Jessica Wagantall --- jjb/lf-docker-jobs.yaml | 9 ++++++--- .../notes/update-docker-scripts-5d89bbc89103e7f6.yaml | 15 +++++++++++++++ shell/docker-build.sh | 8 +++++--- shell/docker-get-git-describe.sh | 8 +++----- shell/docker-get-yaml-tag.sh | 8 ++++---- shell/docker-push.sh | 6 ++++-- 6 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 releasenotes/notes/update-docker-scripts-5d89bbc89103e7f6.yaml diff --git a/jjb/lf-docker-jobs.yaml b/jjb/lf-docker-jobs.yaml index 220c2252..9b8b7314 100644 --- a/jjb/lf-docker-jobs.yaml +++ b/jjb/lf-docker-jobs.yaml @@ -10,7 +10,6 @@ builders: - inject: properties-content: | - DOCKER_NAME={docker-name} DOCKER_ROOT={docker-root} - conditional-step: condition-kind: regex-match @@ -37,8 +36,10 @@ - inject: properties-content: | DOCKER_ARGS={docker-build-args} + DOCKER_NAME={docker-name} DOCKER_ROOT={docker-root} CONTAINER_PULL_REGISTRY={container-public-registry} + CONTAINER_PUSH_REGISTRY={container-push-registry} - shell: !include-raw-escape: - ../shell/docker-build.sh @@ -137,12 +138,13 @@ - shell: '{pre_docker_build_script}' - lf-docker-get-container-tag: docker-use-params-from: '{docker-use-params-from}' - docker-name: '{docker-name}' docker-root: '{docker-root}' - lf-docker-build: docker-build-args: '{docker-build-args}' + docker-name: '{docker-name}' docker-root: '{docker-root}' container-public-registry: '{container-public-registry}' + container-push-registry: '{container-push-registry}' - shell: '{post_docker_build_script}' - lf-provide-maven-settings-cleanup @@ -173,12 +175,13 @@ - shell: '{pre_docker_build_script}' - lf-docker-get-container-tag: docker-use-params-from: '{docker-use-params-from}' - docker-name: '{docker-name}' docker-root: '{docker-root}' - lf-docker-build: docker-build-args: '{docker-build-args}' + docker-name: '{docker-name}' docker-root: '{docker-root}' container-public-registry: '{container-public-registry}' + container-push-registry: '{container-push-registry}' - shell: '{post_docker_build_script}' # Provided all steps have already passed, push the docker image - lf-docker-push: diff --git a/releasenotes/notes/update-docker-scripts-5d89bbc89103e7f6.yaml b/releasenotes/notes/update-docker-scripts-5d89bbc89103e7f6.yaml new file mode 100644 index 00000000..fa8953f6 --- /dev/null +++ b/releasenotes/notes/update-docker-scripts-5d89bbc89103e7f6.yaml @@ -0,0 +1,15 @@ +--- +fixes: + - | + Allow DOCKER_ARGS to be empty in docker-build.sh. This is not a + required parameter, it can be empty. + + Remove container reference in docker-get-git-describe.sh. The + CONTAINER_PUSH_REGISTRY already gets added in the docker-push script. + No need to add it again. + + Rename image_name to image_build_tag in docker-get-yaml-tag to match + docker-get-git-describe. Add missing "DOCKER_NAME" in the DOCKER_IMAGE. + + docker-get-git-describe.sh and docker-get-yaml-tag.sh should only export + the tag variable. Let docker-build.sh process DOCKER_NAME diff --git a/shell/docker-build.sh b/shell/docker-build.sh index 982a61f5..e7730586 100644 --- a/shell/docker-build.sh +++ b/shell/docker-build.sh @@ -12,8 +12,10 @@ echo "---> docker-build.sh" # Docker image build script set -eu -o pipefail - +echo "---> Building image: $CONTAINER_PUSH_REGISTRY/$DOCKER_NAME:$DOCKER_IMAGE_TAG" cd "$DOCKER_ROOT" -# DOCKER_IMAGE variable gets constructed after lf-docker-get-container-tag builder step +# DOCKER_IMAGE_TAG variable gets constructed after lf-docker-get-container-tag builder step # is executed. It constructs the image name and the appropriate tag in the same varaiable. -docker build "$DOCKER_ARGS" . -t "$DOCKER_IMAGE" | tee "$WORKSPACE/docker_build_log.txt" +docker_build_command="docker build ${DOCKER_ARGS:-} -t "$CONTAINER_PUSH_REGISTRY/$DOCKER_NAME:$DOCKER_IMAGE_TAG" ." +echo $docker_build_command +eval $docker_build_command | tee "$WORKSPACE/docker_build_log.txt" diff --git a/shell/docker-get-git-describe.sh b/shell/docker-get-git-describe.sh index 326f41a3..c1a3d21e 100644 --- a/shell/docker-get-git-describe.sh +++ b/shell/docker-get-git-describe.sh @@ -21,10 +21,8 @@ if [ -z "$image_build_tag" ] then echo "git describe returned an empty value, make sure a version tag is applied" exit 1 -else - image_name="$CONTAINER_PUSH_REGISTRY/$DOCKER_NAME:$image_build_tag" fi - -# Write DOCKER_IMAGE information to a file so it can be injected into the +echo "---> Tag found: $image_build_tag" +# Write DOCKER_IMAGE_TAG information to a file so it can be injected into the # environment for following steps -echo "DOCKER_IMAGE=$image_name" >> "$WORKSPACE/env_docker_inject.txt" +echo "DOCKER_IMAGE_TAG=$image_build_tag" >> "$WORKSPACE/env_docker_inject.txt" diff --git a/shell/docker-get-yaml-tag.sh b/shell/docker-get-yaml-tag.sh index 2a1bbdc6..8b0e16ee 100644 --- a/shell/docker-get-yaml-tag.sh +++ b/shell/docker-get-yaml-tag.sh @@ -18,12 +18,12 @@ container_tag_file=container-tag.yaml if [ -f "$container_tag_file" ] then - image_name=$(yq -r .tag "$container_tag_file") + image_build_tag=$(yq -r .tag "$container_tag_file") else echo "$container_tag_file file not found. Make sure this file exists." exit 1 fi - -# Write DOCKER_IMAGE information to a file so it can be injected into the +echo "---> Tag found: $image_build_tag" +# Write DOCKER_IMAGE_TAG information to a file so it can be injected into the # environment for following steps -echo "DOCKER_IMAGE=$image_name" >> "$WORKSPACE/env_docker_inject.txt" +echo "DOCKER_IMAGE_TAG=$image_build_tag" >> "$WORKSPACE/env_docker_inject.txt" diff --git a/shell/docker-push.sh b/shell/docker-push.sh index 83996fab..b04f71d4 100644 --- a/shell/docker-push.sh +++ b/shell/docker-push.sh @@ -13,5 +13,7 @@ echo "---> docker-push.sh" # Ensure we fail the job if any steps fail set -ue -o pipefail - -docker push "$CONTAINER_PUSH_REGISTRY/$DOCKER_IMAGE" +echo "---> Pushing image: $CONTAINER_PUSH_REGISTRY/$DOCKER_NAME:$DOCKER_IMAGE_TAG" +docker_push_command="docker push "$CONTAINER_PUSH_REGISTRY/$DOCKER_NAME:$DOCKER_IMAGE_TAG"" +echo $docker_push_command +eval $docker_push_command -- 2.16.6