Skip to content

Commit

Permalink
justfile: Truncate container tag string if too long (2nd attempt)
Browse files Browse the repository at this point in the history
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: b88ec42 ("Build system")
Signed-off-by: Quentin Monnet <[email protected]>
  • Loading branch information
qmonnet authored and daniel-noland committed Nov 9, 2024
1 parent b93d145 commit 782d9b3
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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("%+")
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 782d9b3

Please sign in to comment.