Update docker scripts 86/15786/12 v0.38.1
authorJessica Wagantall <jwagantall@linuxfoundation.org>
Thu, 30 May 2019 00:43:45 +0000 (17:43 -0700)
committerJessica Wagantall <jwagantall@linuxfoundation.org>
Fri, 31 May 2019 17:55:39 +0000 (10:55 -0700)
- 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 <jwagantall@linuxfoundation.org>
jjb/lf-docker-jobs.yaml
releasenotes/notes/update-docker-scripts-5d89bbc89103e7f6.yaml [new file with mode: 0644]
shell/docker-build.sh
shell/docker-get-git-describe.sh
shell/docker-get-yaml-tag.sh
shell/docker-push.sh

index 220c225..9b8b731 100644 (file)
@@ -10,7 +10,6 @@
     builders:
       - inject:
           properties-content: |
-            DOCKER_NAME={docker-name}
             DOCKER_ROOT={docker-root}
       - conditional-step:
           condition-kind: regex-match
       - 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
 
       - 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
 
       - 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 (file)
index 0000000..fa8953f
--- /dev/null
@@ -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
index 982a61f..e773058 100644 (file)
@@ -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"
index 326f41a..c1a3d21 100644 (file)
@@ -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"
index 2a1bbdc..8b0e16e 100644 (file)
@@ -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"
index 83996fa..b04f71d 100644 (file)
@@ -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