Skip to content
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

ci: Prune only docker images built for current build #11222

Merged
merged 2 commits into from Apr 30, 2020
Merged

Conversation

nebril
Copy link
Member

@nebril nebril commented Apr 29, 2020

This PR should fix GKE builds failures happening on docker build stage (we are concurrently building and image and pruning images aggresively, this change makes the build clean up after itself).

@nebril nebril requested review from a team as code owners April 29, 2020 13:51
@maintainer-s-little-helper
Copy link

Please set the appropriate release note label.

@nebril
Copy link
Member Author

nebril commented Apr 29, 2020

test-me-please

@coveralls
Copy link

coveralls commented Apr 29, 2020

Coverage Status

Coverage decreased (-0.001%) to 44.601% when pulling 580c030 on pr/fix-docker-prune into 4e17dfe on master.

Makefile Outdated
@@ -226,6 +226,7 @@ docker-image-no-clean: GIT_VERSION
--build-arg LOCKDEBUG=${LOCKDEBUG} \
--build-arg V=${V} \
--build-arg LIBNETWORK_PLUGIN=${LIBNETWORK_PLUGIN} \
--build-arg CILIUM_SHA=$$(cat GIT_VERSION | cut -d" " -f1 | tr -d '\n') \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be set with docker build --label in stead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you what you are looking for is $(GIT_VERSION), it should be set already. And let's not invent a new name, just call it git_version or cilium_git_version.
I'd just use the whole string, i.e. --label "cilium_git_version=$(GIT_VERSION)", or otherwise --label "cilium_git_version=$(firstword $(GIT_VERSION))" if you prefer to use just the short commit hash.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot use --label here, because it only labels the final image. We want to label intermediate images too so we know which ones to prune.

Good catch with firstword usage, I didn't know I can use it like that, will change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, seems suboptimal but acceptable :)

@@ -12,3 +12,5 @@ docker tag cilium/operator:$2 $1/cilium/operator:$2
docker push $1/cilium/cilium:$2
docker push $1/cilium/cilium-dev:$2
docker push $1/cilium/operator:$2

docker image prune -f --all --filter "label=cilium-sha=$(cat GIT_VERSION | cut -d' ' -f1 | tr -d '\n')"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cilium_git_version="$(cat GIT_VERSION)"
docker image prune -f --all --filter "label=cilium_git_version=${cilium_git_version%% *}"`

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't get this to work locally in zsh and bash :/ , it seems like a magic bash variable expansion, but I am not sure how this works.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the typo, I fixed it now for the record, and thanks for accepting this suggestions :)

Copy link
Contributor

@errordeveloper errordeveloper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few nits that would make it simpler :)

@@ -21,4 +21,3 @@ docker push $1/cilium/cilium:$2
docker push $1/cilium/cilium-dev:$2
docker push $1/cilium/operator:$2

docker image prune -f --all --filter "until=-6h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not change it to docker image prune --force --filter "until=-6h" , so we keep cleaning the dangling images (surely there will be some of those).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because this deletes intermediate docker images while other build is running and causes docker build to fail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I was thinking that the 6h window should actually prevent that, or does it not work as intended? Maybe we could extend the window?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So my theory on what is happening here is that

  • a build (A) downloads base images for intermediate images and carries on with the build
  • 6 hours pass, other build (B) starts
  • intermediate images are based on existing over 6h old images
  • other build (C) runs "docker image prune" and deletes the base image causing build B to fail

docker apparently doesn't protect images used in multi-stage builds, so we need to work around that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... but that's based on having ran this script --all, so it was actually deleting every single image that wasn't used by a container. I think if we remove --all, we would make different observations, however some of what you said would stand anyway.
Anyway, let's just go ahead with your change, and I'd rather spend time discussing how we can evolve some of this.

Copy link
Member

@aanm aanm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing else from my side besides what Ilya point it out.

@nebril nebril force-pushed the pr/fix-docker-prune branch 2 times, most recently from e9dc0b4 to c4e8407 Compare April 29, 2020 17:39
@nebril
Copy link
Member Author

nebril commented Apr 29, 2020

@errordeveloper please re-review

@nebril
Copy link
Member Author

nebril commented Apr 29, 2020

test-me-please

@qmonnet
Copy link
Member

qmonnet commented Apr 30, 2020

Ginkgo hit #11213

test-focus K8sFQDNTest Restart Cilium validate that FQDN is still working

@qmonnet
Copy link
Member

qmonnet commented Apr 30, 2020

Conflict in Makefile on $(CONTAINER_ENGINE_FULL) which has been replaced, can you please rebase?

@qmonnet qmonnet added the dont-merge/needs-rebase This PR needs to be rebased because it has merge conflicts. label Apr 30, 2020
Copy link
Contributor

@errordeveloper errordeveloper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it will fix the underlying problem we are having at the moment, so LGMT =)

Signed-off-by: Maciej Kwiek <maciej@isovalent.com>
Signed-off-by: Maciej Kwiek <maciej@isovalent.com>
@nebril
Copy link
Member Author

nebril commented Apr 30, 2020

test-me-please

@nebril
Copy link
Member Author

nebril commented Apr 30, 2020

restart-ginkgo

@nebril
Copy link
Member Author

nebril commented Apr 30, 2020

test-with-kernel

@nebril
Copy link
Member Author

nebril commented Apr 30, 2020

This change only fixes things if other PRs rebase on top of it, so I am going to merge it with GKE build failing

@nebril nebril merged commit 7a9629d into master Apr 30, 2020
1.8.0 automation moved this from In progress to Merged Apr 30, 2020
@nebril nebril deleted the pr/fix-docker-prune branch April 30, 2020 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dont-merge/needs-rebase This PR needs to be rebased because it has merge conflicts. release-note/ci This PR makes changes to the CI.
Projects
No open projects
1.8.0
  
Merged
Development

Successfully merging this pull request may close these issues.

None yet

6 participants