-
Notifications
You must be signed in to change notification settings - Fork 83
feat(docker): Generate unique tag for each clp-package dev image build to avoid conflicts on shared hosts. #1335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
653cdd7
0c8c699
d79cb5f
49f3822
e0dc40f
ec09d98
a2a8f08
7a05377
be5a517
0e2667c
aa4919f
94a8523
c9d9959
074650c
2b73559
fba7d3b
c778427
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,17 +3,38 @@ | |
| set -eu | ||
| set -o pipefail | ||
|
|
||
| remove_temp_file_and_prev_image() { | ||
| rm -f "$temp_iid_file" | ||
|
|
||
| [[ -z "$prev_image_id" || "$prev_image_id" == "$new_image_id" ]] && return | ||
|
|
||
| if docker image inspect "$prev_image_id" >/dev/null 2>&1; then | ||
| echo "Removing previous image $prev_image_id." | ||
| docker image remove "$prev_image_id" | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The image might fail to be removed because some running container might still be referencing it, which causes a non-zero exit code in the script. When the image fails to be removed, we should either exit gracefully (with 0) with a warning message printed, or the caller should gracefully handle the non-exit code. Currently, the caller (the docker-images.yaml taskfile) doesn't handle this --- when the script fails, any commands following the script call (e.g., to copy the unique image id file into @coderabbitai create an issue to track this
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: Length of output: 42 @junhaoliao I've created issue #1370 to track this: #1370 The issue documents the problem where |
||
| fi | ||
| } | ||
| trap remove_temp_file_and_prev_image EXIT | ||
|
|
||
| script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | ||
| repo_root=${script_dir}/../../../ | ||
| repo_root="${script_dir}/../../../" | ||
| iid_file="${repo_root}/build/clp-package-image.id" | ||
|
|
||
| prev_image_id="" | ||
| if [[ -f "$iid_file" ]]; then | ||
| prev_image_id=$(<"$iid_file") | ||
| fi | ||
|
|
||
| temp_iid_file="$(mktemp)" | ||
| new_image_id="" | ||
|
|
||
| build_cmd=( | ||
| docker build | ||
| --tag "clp-package:dev" | ||
| --iidfile "$temp_iid_file" | ||
| "$repo_root" | ||
| --file "${script_dir}/Dockerfile" | ||
| ) | ||
|
|
||
| if command -v git >/dev/null && git -C "$script_dir" rev-parse --is-inside-work-tree >/dev/null ; | ||
| if command -v git >/dev/null && git -C "$script_dir" rev-parse --is-inside-work-tree >/dev/null; | ||
| then | ||
| build_cmd+=( | ||
| --label "org.opencontainers.image.revision=$(git -C "$script_dir" rev-parse HEAD)" | ||
|
|
@@ -22,3 +43,13 @@ then | |
| fi | ||
|
|
||
| "${build_cmd[@]}" | ||
|
|
||
| if [[ -s "$temp_iid_file" ]]; then | ||
| new_image_id="$(<"$temp_iid_file")" | ||
| echo "$new_image_id" > "$iid_file" | ||
|
|
||
| user="${USER:-$(id -un 2>/dev/null || whoami 2>/dev/null || echo unknown)}" | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's one edge case we missed to handle - When the username cannot be found on the system (e.g., the username is not specified in @coderabbitai create an issue to track this
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: Length of output: 42 @junhaoliao I've created issue #1371 to track this edge case: #1371 The issue documents the scenario where the |
||
| short_id="${new_image_id#sha256:}" | ||
| short_id="${short_id:0:4}" | ||
| docker tag "$new_image_id" "clp-package:dev-${user}-${short_id}" | ||
| fi | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update documentation to reflect the new image tagging scheme.
According to the PR summary, the build process now generates unique identifiers to avoid overwriting older builds on shared machines. The AI summary mentions tagging as
clp-package:dev-${USER}-${short_id}, but this line still states the image will be namedclp-package:dev.Please update this documentation to:
image.idfile mentioned in the PR summary)🤖 Prompt for AI Agents