From 782d9b347e46ae971587dfa85ed5d1f115c4bc9d Mon Sep 17 00:00:00 2001 From: Quentin Monnet Date: Sat, 9 Nov 2024 01:49:50 +0000 Subject: [PATCH] justfile: Truncate container tag string if too long (2nd attempt) Containers' tags can't be longer than 128 characters. Sometimes CI generates tags that are longer than this (thanks Dependabot for the extra-long branch names). Make sure we don't break docker builds by having bash truncate the string if necessary - everywhere we need it. Fixes: b88ec42c3115 ("Build system") Signed-off-by: Quentin Monnet --- justfile | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/justfile b/justfile index 2c9be0c9..1383fd06 100644 --- a/justfile +++ b/justfile @@ -84,6 +84,9 @@ _clean := ``` _slug := (if _clean == "clean" { "" } else { "dirty-_-" }) + _branch +# Define a function to truncate long lines to the limit for containers tags +_define_truncate128 := 'truncate128() { printf -- "%s" "${1::128}" ; }' + # The time of the build (in iso8601 utc) _build_time := datetime_utc("%+") @@ -360,6 +363,7 @@ sterile-build: (sterile "_network=none" "cargo" "--locked" "build" ("--profile=" [script] build-container: sterile-build {{ _just_debuggable_ }} + {{ _define_truncate128 }} declare build_date build_date="$(date --utc --iso-8601=date --date="{{ _build_time }}")" declare -r build_date @@ -374,40 +378,41 @@ build-container: sterile-build --label "build.date=${build_date}" \ --label "build.timestamp={{ _build_time }}" \ --label "build.time_epoch=${build_time_epoch}" \ - --tag "{{ _container_repo }}:${build_date}.{{ _slug }}.{{ target }}.{{ profile }}.{{ _commit }}" \ + --tag "{{ _container_repo }}:$(truncate128 "${build_date}.{{ _slug }}.{{ target }}.{{ profile }}.{{ _commit }}")" \ --build-arg ARTIFACT="artifact/{{ target }}/{{ profile }}/scratch" \ . sudo -E docker tag \ - "{{ _container_repo }}:${build_date}.{{ _slug }}.{{ target }}.{{ profile }}.{{ _commit }}" \ - "{{ _container_repo }}:{{ _slug }}.{{ target }}.{{ profile }}.{{ _commit }}" + "{{ _container_repo }}:$(truncate128 "${build_date}.{{ _slug }}.{{ target }}.{{ profile }}.{{ _commit }}")" \ + "{{ _container_repo }}:$(truncate128 "{{ _slug }}.{{ target }}.{{ profile }}.{{ _commit }}")" sudo -E docker tag \ - "{{ _container_repo }}:${build_date}.{{ _slug }}.{{ target }}.{{ profile }}.{{ _commit }}" \ - "{{ _container_repo }}:{{ _slug }}.{{ target }}.{{ profile }}" + "{{ _container_repo }}:$(truncate128 "${build_date}.{{ _slug }}.{{ target }}.{{ profile }}.{{ _commit }}")" \ + "{{ _container_repo }}:$(truncate128 "{{ _slug }}.{{ target }}.{{ profile }}")" if [ "{{ target }}" = "x86_64-unknown-linux-gnu" ]; then sudo -E docker tag \ - "{{ _container_repo }}:${build_date}.{{ _slug }}.{{ target }}.{{ profile }}.{{ _commit }}" \ - "{{ _container_repo }}:{{ _slug }}.{{ profile }}" + "{{ _container_repo }}:$(truncate128 "${build_date}.{{ _slug }}.{{ target }}.{{ profile }}.{{ _commit }}")" \ + "{{ _container_repo }}:$(truncate128 "{{ _slug }}.{{ profile }}")" fi if [ "{{ target }}" = "x86_64-unknown-linux-gnu" ] && [ "{{ profile }}" = "release" ]; then sudo -E docker tag \ - "{{ _container_repo }}:${build_date}.{{ _slug }}.{{ target }}.{{ profile }}.{{ _commit }}" \ - "{{ _container_repo }}:{{ _slug }}" + "{{ _container_repo }}:$(truncate128 "${build_date}.{{ _slug }}.{{ target }}.{{ profile }}.{{ _commit }}")" \ + "{{ _container_repo }}:$(truncate128 "{{ _slug }}")" fi # Build and push containers [script] push-container: build-container + {{ _define_truncate128 }} declare build_date build_date="$(date --utc --iso-8601=date --date="{{ _build_time }}")" declare -r build_date - sudo -E docker push "{{ _container_repo }}:${build_date}.{{ _slug }}.{{ target }}.{{ profile }}.{{ _commit }}" - sudo -E docker push "{{ _container_repo }}:{{ _slug }}.{{ target }}.{{ profile }}.{{ _commit }}" + sudo -E docker push "{{ _container_repo }}:$(truncate128 "${build_date}.{{ _slug }}.{{ target }}.{{ profile }}.{{ _commit }}")" + sudo -E docker push "{{ _container_repo }}:$(truncate128 "{{ _slug }}.{{ target }}.{{ profile }}.{{ _commit }}")" if [ "{{ target }}" = "x86_64-unknown-linux-gnu" ]; then - sudo -E docker push "{{ _container_repo }}:{{ _slug }}.{{ profile }}" + sudo -E docker push "{{ _container_repo }}:$(truncate128 "{{ _slug }}.{{ profile }}")" fi if [ "{{ target }}" = "x86_64-unknown-linux-gnu" ] && [ "{{ profile }}" = "release" ]; then - sudo -E docker push "{{ _container_repo }}:{{ _slug }}" + sudo -E docker push "{{ _container_repo }}:$(truncate128 "{{ _slug }}")" fi # Run the tests (with nextest)