Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

container_push: add skip_unchanged_digest attribute #1744

Merged

Conversation

sluongng
Copy link
Contributor

@sluongng sluongng commented Mar 2, 2021

Bring push-all on par with container_push in term of feature parity.

Generally --skip-unchanged-digest is a very useful flag to have. One can simply setup a release pipeline upon successful CI to just do bazel run <push-all-target> to push all container images (wrapped in a container bundle) at once.

By checking against upstream registry whether an existing digest already existed, we will only push images which were updated as the result of recent changes introduced to the repo.

The alternative solution is to calculate the SCM diff (git-diff) of the repo to deduce which bazel target were affected, query for container_push targets and bazel run each target 1-by-1, which is complicated to setup (especially when handling deleted code).


This PR added the ability to verify unchanged digest to bundle push (contrib/push-all) rule for convenience.

Without this, the ability to skip unchanged digest is exclusive to container_push and one would need something like https://github.com/atlassian/bazel-tools/tree/master/multirun to achieve the equivalent.

Caveats: when push-all with a container bundle that has duplicated images and push-all is set to run in parallel, the final result might be random. Use sequential push option if you think this is an issue.

Closes #1741

@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sluongng
To complete the pull request process, please assign smukherj1 after the PR has been reviewed.
You can assign the PR to them by writing /assign @smukherj1 in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sluongng
Copy link
Contributor Author

sluongng commented Mar 2, 2021

I did split this PR into 3 separate commits for easier review.

This closes #1741

@sluongng
Copy link
Contributor Author

sluongng commented Mar 3, 2021

/assign @smukherj1

@sluongng
Copy link
Contributor Author

@alexeagle it would be nice to get this reviewed / merge 🙏

@zoidyzoidzoid
Copy link
Contributor

Maybe splitting the commits into separate PRs will make it easier / safer to merge?

Copy link
Member

@pcj pcj left a comment

Choose a reason for hiding this comment

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

Thanks @sluongng this looks like a useful addition. I think it will need some documentation about the behaviour as it may surprise people when upgrading.

contrib/push-all.bzl Outdated Show resolved Hide resolved
@sluongng
Copy link
Contributor Author

sluongng commented Apr 1, 2021

Thanks @sluongng this looks like a useful addition. I think it will need some documentation about the behaviour as it may surprise people when upgrading.

@pcj hey, regarding documentation improvement, do you have any recommendation?

I look back at the change and see that:

  • This is not anyway breaking, all the current functionality remains to be the same
  • New feature skip_unchanged_digest was added with a default value set to False (disable) and accompanied with starlark doc.

Reviewing https://github.com/bazelbuild/rules_docker/search?q=push-all there is not a lot of other references that needed to be updated. 🤔 Am I missing a generated markdown somewhere?

@sluongng sluongng force-pushed the sluongngoc/push-all-check-digest branch from 8df4a3e to e4b13e9 Compare May 9, 2021 16:59
@sluongng
Copy link
Contributor Author

sluongng commented May 9, 2021

I just force pushed the PR to update according to feedback from Slack.

Changes from last round:

  1. Drop the cleanup commits, will be sending them as a separate PR.

The diff is now expected to be small without noise.

@sluongng sluongng force-pushed the sluongngoc/push-all-check-digest branch from e4b13e9 to 88901ee Compare May 9, 2021 17:03
@sluongng
Copy link
Contributor Author

@alexeagle ping

@sluongng
Copy link
Contributor Author

sluongng commented Dec 3, 2021

Rebase to origin/master + changed my email so that CLA passed

Add feature parity with container/push rule.

With such change, user can choose to push all containers in a bundle
without having to care whether a container was recently rebuilt or not.

The check will run against destination container registry to see whether the
digest has already existed prior to pushing. If disgest already exists,
image will not be pushed.
@sluongng sluongng force-pushed the sluongngoc/push-all-check-digest branch from ec2b3ee to 2059100 Compare December 3, 2021 10:04
@sluongng
Copy link
Contributor Author

sluongng commented Dec 3, 2021

Switched from using += ["element"] to list.append("elelement") to fix buildifier lint check

@alexeagle
Copy link
Collaborator

I think there's still a sharp edge here - if you use stamping, then the image will be different on every build regardless of code changes. So we might want to document it a bit more - but since I just changed the stamping logic to require explicit opt-in (either via stamp = always or --stamp) I'm not as concerned as I would have been previously.

@alexeagle alexeagle requested a review from pcj December 3, 2021 17:08
@sluongng
Copy link
Contributor Author

sluongng commented Dec 3, 2021

I think there's still a sharp edge here - if you use stamping, then the image will be different on every build regardless of code changes. So we might want to document it a bit more - but since I just changed the stamping logic to require explicit opt-in (either via stamp = always or --stamp) I'm not as concerned as I would have been previously.

The great thing about OCI format and container registry is that even with stamping, hopefully only the final image of the layer / the json manifest file / the final image tag in the sh_binary push script is affected content wise. In such cases, one should still be comfortable pushing all with minimal storage impacts onto the container registry.

Obviously keeping container images healthy by having re-useable layers will take some effort and not trivial, but it should be do-able if you set it up correctly.

@pcj pcj changed the title Sluongngoc/push all check digest container_push: add skip_unchanged_digest attribute Dec 3, 2021
@pcj
Copy link
Member

pcj commented Dec 3, 2021

Hi @sluongng, approving this. I think the doc on the attribute is enough documentation, though you probably didn't need to mention the default.

@alexeagle alexeagle merged commit cd6a32c into bazelbuild:master Dec 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

contrib/push-all.bzl should support skip_unchanged_digest
6 participants