Repository navigation
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 3 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 |
|---|---|---|
|
|
@@ -5,10 +5,25 @@ set -o pipefail | |
|
|
||
| script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | ||
| repo_root=${script_dir}/../../../ | ||
| iid_file="${repo_root}/build/clp-package-image.id" | ||
|
|
||
| # Remove the previous image to save space, but only after the build so its contents can be reused. | ||
| prev_image_id="" | ||
| if [[ -f "$iid_file" ]]; then | ||
| prev_image_id=$(cat "$iid_file") | ||
|
junhaoliao marked this conversation as resolved.
Resolved
|
||
| fi | ||
| cleanup() { | ||
|
Member
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. How about
Member
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. Can we move this function to the top of the file, just after the |
||
| if [[ -n "$prev_image_id" ]] && docker image inspect "$prev_image_id" >/dev/null 2>&1; then | ||
| echo "Removing previous image $prev_image_id" | ||
|
junhaoliao marked this conversation as resolved.
Resolved
|
||
| docker image remove "$prev_image_id" | ||
| fi | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| build_cmd=( | ||
| docker build | ||
| --tag "clp-package:dev" | ||
| --iidfile "$iid_file" | ||
| --tag "clp-package:dev-${USER}-$(date +%s)" | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
Member
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. If we tag with the current timestamp, then identical image builds will result in two different tags pointing at the same image. Besides the clutter, that also means that the image can't be removed without a force flag. Instead, can we replace the timestamp with the image ID? I know that will make it harder to tell what's a newer image based on the tag, but that information is available from Docker since it keeps track of the date an image was built.
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.
not sure if this behaviour is possible. if i understand correctly, every time we run
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. maybe i understood it wrong. do you mind giving more steps on how this can be reproduced?
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. my initial implementation of the unique id part was done with later i replaced that with the timestamp because it's less likely a user can build multiple build in a second. (can probably change it to nanoseconds
Member
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.
That's because
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. actually i do mean running the junhao@ASUS-X870E:~/workspace/2-clp/tools/docker-images/clp-package$ ./build.sh && echo '---' && cat /home/junhao/workspace/2-clp/build/clp-package-image.id && echo
[+] Building 0.9s (12/12) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 585B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:jammy 0.1s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [base 1/6] FROM docker.io/library/ubuntu:jammy@sha256:4e0171b9275e12d375863f2b3ae9ce00a4c53ddda176bd55868df97ac6f21a6e 0.0s
=> => resolve docker.io/library/ubuntu:jammy@sha256:4e0171b9275e12d375863f2b3ae9ce00a4c53ddda176bd55868df97ac6f21a6e 0.0s
=> [internal] load build context 0.6s
=> => transferring context: 2.24MB 0.6s
=> CACHED [base 2/6] WORKDIR /root 0.0s
=> CACHED [base 3/6] COPY ./tools/docker-images/clp-package/setup-scripts ./setup-scripts 0.0s
=> CACHED [base 4/6] RUN ./setup-scripts/install-prebuilt-packages.sh && rm -rf ./setup-scripts/ 0.0s
=> CACHED [base 5/6] RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 0.0s
=> CACHED [base 6/6] COPY ./build/clp-package /opt/clp 0.0s
=> CACHED [stage-1 1/1] COPY --from=base / / 0.0s
=> exporting to image 0.1s
=> => exporting layers 0.0s
=> => exporting manifest sha256:eb17ac6fd6ea60ce4eb1839a54f0bbc939b0d3dad201c2d9547d0b0ffd7fe2bf 0.0s
=> => exporting config sha256:41a6f9aae1dc947a3deeafcec0e82ab2891f2cb55ff0f9a3a0492cd5defd0739 0.0s
=> => exporting attestation manifest sha256:5cbe3ae1c541bb2237dbbb721e8635c31449bf9ef334bcbb691e98d4b882a168 0.0s
=> => exporting manifest list sha256:31e3696ede8077959e0dfe249f7be8caa42c12d2d351e0a93ba88f080b883e36 0.0s
=> => naming to docker.io/library/clp-package:dev-junhao-1759114001 0.0s
=> => unpacking to docker.io/library/clp-package:dev-junhao-1759114001 0.0s
Removing previous image sha256:754d92f3198297d74cae9ef9698f2d5f046392d6408158c4860ce820c7b08b17.
Untagged: clp-package:dev-junhao-1759113990
Deleted: sha256:754d92f3198297d74cae9ef9698f2d5f046392d6408158c4860ce820c7b08b17
---
sha256:31e3696ede8077959e0dfe249f7be8caa42c12d2d351e0a93ba88f080b883e36
junhao@ASUS-X870E:~/workspace/2-clp/tools/docker-images/clp-package$ ./build.sh && echo '---' && cat /home/junhao/workspace/2-clp/build/clp-package-image.id && echo
[+] Building 0.9s (12/12) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 585B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:jammy 0.1s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [base 1/6] FROM docker.io/library/ubuntu:jammy@sha256:4e0171b9275e12d375863f2b3ae9ce00a4c53ddda176bd55868df97ac6f21a6e 0.0s
=> => resolve docker.io/library/ubuntu:jammy@sha256:4e0171b9275e12d375863f2b3ae9ce00a4c53ddda176bd55868df97ac6f21a6e 0.0s
=> [internal] load build context 0.6s
=> => transferring context: 2.24MB 0.6s
=> CACHED [base 2/6] WORKDIR /root 0.0s
=> CACHED [base 3/6] COPY ./tools/docker-images/clp-package/setup-scripts ./setup-scripts 0.0s
=> CACHED [base 4/6] RUN ./setup-scripts/install-prebuilt-packages.sh && rm -rf ./setup-scripts/ 0.0s
=> CACHED [base 5/6] RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 0.0s
=> CACHED [base 6/6] COPY ./build/clp-package /opt/clp 0.0s
=> CACHED [stage-1 1/1] COPY --from=base / / 0.0s
=> exporting to image 0.1s
=> => exporting layers 0.0s
=> => exporting manifest sha256:eb17ac6fd6ea60ce4eb1839a54f0bbc939b0d3dad201c2d9547d0b0ffd7fe2bf 0.0s
=> => exporting config sha256:41a6f9aae1dc947a3deeafcec0e82ab2891f2cb55ff0f9a3a0492cd5defd0739 0.0s
=> => exporting attestation manifest sha256:262a3a97f6ac6ebe1264878a49027dd9382532eda8aa5b8386a8496acb684c5c 0.0s
=> => exporting manifest list sha256:fda46ace138ddb9700a1dbdaf26bbde1577dd1e15f7159d05858e9c6a8d7b245 0.0s
=> => naming to docker.io/library/clp-package:dev-junhao-1759114003 0.0s
=> => unpacking to docker.io/library/clp-package:dev-junhao-1759114003 0.0s
Removing previous image sha256:31e3696ede8077959e0dfe249f7be8caa42c12d2d351e0a93ba88f080b883e36.
Untagged: clp-package:dev-junhao-1759114001
Deleted: sha256:31e3696ede8077959e0dfe249f7be8caa42c12d2d351e0a93ba88f080b883e36
---
sha256:fda46ace138ddb9700a1dbdaf26bbde1577dd1e15f7159d05858e9c6a8d7b245
junhao@ASUS-X870E:~/workspace/2-clp/tools/docker-images/clp-package$ ./build.sh && echo '---' && cat /home/junhao/workspace/2-clp/build/clp-package-image.id && echo
[+] Building 0.9s (12/12) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 585B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:jammy 0.1s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [base 1/6] FROM docker.io/library/ubuntu:jammy@sha256:4e0171b9275e12d375863f2b3ae9ce00a4c53ddda176bd55868df97ac6f21a6e 0.0s
=> => resolve docker.io/library/ubuntu:jammy@sha256:4e0171b9275e12d375863f2b3ae9ce00a4c53ddda176bd55868df97ac6f21a6e 0.0s
=> [internal] load build context 0.6s
=> => transferring context: 2.24MB 0.6s
=> CACHED [base 2/6] WORKDIR /root 0.0s
=> CACHED [base 3/6] COPY ./tools/docker-images/clp-package/setup-scripts ./setup-scripts 0.0s
=> CACHED [base 4/6] RUN ./setup-scripts/install-prebuilt-packages.sh && rm -rf ./setup-scripts/ 0.0s
=> CACHED [base 5/6] RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 0.0s
=> CACHED [base 6/6] COPY ./build/clp-package /opt/clp 0.0s
=> CACHED [stage-1 1/1] COPY --from=base / / 0.0s
=> exporting to image 0.1s
=> => exporting layers 0.0s
=> => exporting manifest sha256:eb17ac6fd6ea60ce4eb1839a54f0bbc939b0d3dad201c2d9547d0b0ffd7fe2bf 0.0s
=> => exporting config sha256:41a6f9aae1dc947a3deeafcec0e82ab2891f2cb55ff0f9a3a0492cd5defd0739 0.0s
=> => exporting attestation manifest sha256:e1d31873b43c7ec6bcdeb4112671c6daf21b02b4019c1d40b6de746717c6d816 0.0s
=> => exporting manifest list sha256:b3a0bfc056f542a868cd1845256543dd585864fe0ca8d934f6a398bc07b52151 0.0s
=> => naming to docker.io/library/clp-package:dev-junhao-1759114005 0.0s
=> => unpacking to docker.io/library/clp-package:dev-junhao-1759114005 0.0s
Removing previous image sha256:fda46ace138ddb9700a1dbdaf26bbde1577dd1e15f7159d05858e9c6a8d7b245.
Untagged: clp-package:dev-junhao-1759114003
Deleted: sha256:fda46ace138ddb9700a1dbdaf26bbde1577dd1e15f7159d05858e9c6a8d7b245
---
sha256:b3a0bfc056f542a868cd1845256543dd585864fe0ca8d934f6a398bc07b52151
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. discussed offline - it appears that the above script generates a different hash every time only when Docker Desktop Windows + WSL is used. with a native Docker Engine installed inside WSL, the hash is consistent across docker build if the content inside a few facts:
how about this:
Member
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. At step (3), it's possible two concurrent builds on the system create an image with tag
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. let me implement the proposal and monkey test a bit to see if there are issues. i could be wrong about how
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.
i have tested the script that's been pushed and didn't find any awkward issue, either with Docker Desktop or native Docker. |
||
| "$repo_root" | ||
| --file "${script_dir}/Dockerfile" | ||
| ) | ||
|
Comment on lines
30
to
35
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. 🧹 Nitpick | 🔵 Trivial Confirm intended builder: buildx vs classic build. PR text mentions buildx, but this uses 🤖 Prompt for AI Agents
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.
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. @junhaoliao Thank you for the clarification and the reference! You're absolutely right - since Docker Engine 23.0, I appreciate you providing the documentation link to confirm this behavior change. The script is appropriately using 🐰💡 ✏️ Learnings added
🧠 Learnings used
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. @kirkrodrigues i realise we don't really mention any docker version in our dev docs (we do mention docker in the userquick start guide, though we don't say the version still). if that's not intentionally left out, maybe we should specify the version in our dev docs as well?
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.
Member
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. Yeah, we should specify the version we require. I just don't know what version that is right now.
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. it might be time consuming to figure out the exact version for the feature / syntax we use. maybe we can just take the latest version and put that into the docs? at least we can be sure that's a version we have validated
Member
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. Generally, we support up to 2 years of backwards compatibility with OSes. Perhaps we can do the same for Docker?
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. https://containerd.io/releases/ 's LTS version is now i installed these versions on my machine and tested things fine: sudo apt-get install -y \
docker-ce=5:27.0.3-1~ubuntu.22.04~jammy \
docker-ce-cli=5:27.0.3-1~ubuntu.22.04~jammy \
containerd.io=1.7.18-1 \
docker-buildx-plugin=0.15.1-1~ubuntu.22.04~jammy \
docker-compose-plugin=2.28.1-1~ubuntu.22.04~jammy |
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.