This is an automated email from the ASF dual-hosted git repository.

areusch pushed a commit to branch areusch/freeze-dependencies
in repository https://gitbox.apache.org/repos/asf/tvm.git

commit 129164b67bdfc713b00fc13dd3bb81ce9407e572
Author: Andrew Reusch <[email protected]>
AuthorDate: Tue May 17 16:51:35 2022 -0700

    escape image name
---
 Jenkinsfile            |  8 ++++++--
 docker/build.sh        | 12 +++++-------
 jenkins/Jenkinsfile.j2 |  6 +++++-
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/Jenkinsfile b/Jenkinsfile
index d7642bd515..b2b774927a 100755
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -45,7 +45,7 @@
 // 'python3 jenkins/generate.py'
 // Note: This timestamp is here to ensure that updates to the Jenkinsfile are
 // always rebased on main before merging:
-// Generated at 2022-05-17T13:48:28.023057
+// Generated at 2022-05-17T16:51:28.353553
 
 import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
 // NOTE: these lines are scanned by docker/dev_common.sh. Please update the 
regex as needed. -->
@@ -379,7 +379,11 @@ def build_image(image_name) {
     returnStdout: true,
     script: 'git log -1 --format=\'%h\''
   ).trim()
-  def full_name = 
"${image_name}:${env.BRANCH_NAME}-${hash}-${env.BUILD_NUMBER}"
+  def full_name = sh(
+    returnStdout: true,
+    script: "echo -n 
'${image_name}:${env.BRANCH_NAME}-${hash}-${env.BUILD_NUMBER}' | python3 -c 
'import sys; import urllib.parse; print(urllib.parse.quote(sys.stdin.read(), 
safe=\"\").lower())' | tr % -",
+    label: 'Compute image name',
+  )
   unpack_lib("python-lockfiles", "docker/python/build/**")
   sh(
     script: "${docker_build} ${image_name} --spec ${full_name}",
diff --git a/docker/build.sh b/docker/build.sh
index ee09c5a01e..76534fa2df 100755
--- a/docker/build.sh
+++ b/docker/build.sh
@@ -166,27 +166,25 @@ function upsearch () {
 # commas (,) and equal signs (=), which are not valid inside docker image 
names.
 # Convert to all lower-case, as per requirement of Docker image names
 function sanitize_docker_name() {
-    echo "$@" | sed -e 's/=/_/g' -e 's/,/-/g' -e 's/\//-/g' | tr '[:upper:]' 
'[:lower:]'
+    echo -n "$@" | python3 -c 'import sys; import urllib.parse; 
print(urllib.parse.quote(sys.stdin.read(), safe="").lower())' | tr % -
 }
 
 # Set up WORKSPACE and BUILD_TAG. Jenkins will set them for you or we pick
 # reasonable defaults if you run it outside of Jenkins.
 WORKSPACE="${WORKSPACE:-${SCRIPT_DIR}/../}"
-BUILD_TAG=$(echo "${BUILD_TAG:-tvm}" | sed 's/-/--/g' | sed 's/%/-/g')
+BUILD_TAG=$(sanitize_docker_name "${BUILD_TAG:-tvm}")
 
 # Determine the docker image name
-DOCKER_IMG_NAME=$(echo "${BUILD_TAG}.${CONTAINER_TYPE}" | sanitize_docker_name)
-DOCKER_IMAGE_TAG=$(echo "${DOCKER_IMAGE_TAG:-latest}" | sanitize_docker_name)
+DOCKER_IMG_NAME=${BUILD_TAG}.$(sanitize_docker_name "${CONTAINER_TYPE}")
+DOCKER_IMAGE_TAG=$(sanitize_docker_name "${DOCKER_IMAGE_TAG:-latest}")
 
 # Compose the full image spec with "name:tag" e.g. "tvm.ci_cpu:v0.03"
 DOCKER_IMG_SPEC="${DOCKER_IMG_NAME}:${DOCKER_IMAGE_TAG}"
 
 if [[ -n ${OVERRIDE_IMAGE_SPEC+x} ]]; then
-    DOCKER_IMG_SPEC=$(echo "$OVERRIDE_IMAGE_SPEC" | sanitize_docker_name)
+    DOCKER_IMG_SPEC="${OVERRIDE_IMAGE_SPEC}" #$(sanitize_docker_name 
"$OVERRIDE_IMAGE_SPEC")
 fi
 
-DOCKER_IMG_SPEC=
-
 # Print arguments.
 echo "WORKSPACE: ${WORKSPACE}"
 echo "CI_DOCKER_EXTRA_PARAMS: ${CI_DOCKER_EXTRA_PARAMS[@]}"
diff --git a/jenkins/Jenkinsfile.j2 b/jenkins/Jenkinsfile.j2
index 9521c0969c..432c8b94b5 100644
--- a/jenkins/Jenkinsfile.j2
+++ b/jenkins/Jenkinsfile.j2
@@ -296,7 +296,11 @@ def build_image(image_name) {
     returnStdout: true,
     script: 'git log -1 --format=\'%h\''
   ).trim()
-  def full_name = 
"${image_name}:${env.BRANCH_NAME}-${hash}-${env.BUILD_NUMBER}"
+  def full_name = sh(
+    returnStdout: true,
+    script: "echo -n 
'${image_name}:${env.BRANCH_NAME}-${hash}-${env.BUILD_NUMBER}' | python3 -c 
'import sys; import urllib.parse; print(urllib.parse.quote(sys.stdin.read(), 
safe=\"\").lower())' | tr % -",
+    label: 'Compute image name',
+  )
   unpack_lib("python-lockfiles", "docker/python/build/**")
   sh(
     script: "${docker_build} ${image_name} --spec ${full_name}",

Reply via email to