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

build: cache invalidation improvements #19617

Merged
merged 2 commits into from
Mar 13, 2024
Merged

Conversation

dvdksn
Copy link
Collaborator

@dvdksn dvdksn commented Mar 13, 2024

Description

Improve documentation about how cache invalidation works for build.
Add a dedicated page describing invalidation.
Add a section about how cache invalidation works with secrets/how to force cache invalidation with build args.

main diff is here:

https://github.com/docker/docs/pull/19617/files#diff-1ca9cf4d42edf044da91b28c0c19f3dc4b07b1fca8bb2cc91dd1aa1d9c11a4b4R61-R79

Related issues

docker/build-push-action#1050 (comment)

Reviews

  • Technical review
  • Editorial review
  • Product review

Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
@dvdksn dvdksn requested a review from crazy-max as a code owner March 13, 2024 13:44
@github-actions github-actions bot added the area/build Relates to Dockerfiles or docker build command label Mar 13, 2024
Copy link

netlify bot commented Mar 13, 2024

Deploy Preview for docsdocker ready!

Name Link
🔨 Latest commit 3fc37c7
🔍 Latest deploy log https://app.netlify.com/sites/docsdocker/deploys/65f1c8013d36910008f348b2
😎 Deploy Preview https://deploy-preview-19617--docsdocker.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

in your Debian-based image to the latest version:

```dockerfile
RUN apt-get update && apt-get upgrade -y
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is recommended to upgrade all packages (cc @tianon). Can you put an example with a simple package like curl?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe also switch to Alpine based image that has packages updated more often than Debian based distro.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Switched to apk and curl for this one

- Make sure that a layer before it has changed
- Clear the build cache ahead of the build using
[`docker builder prune`](../../reference/cli/docker/builder/prune.md).
- Use the `--no-cache` CLI flag or specify the `no-cache` property in the [Bake file](../bake/reference.md#targetno-cache).
Copy link
Member

Choose a reason for hiding this comment

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

We should talk also about --no-cache-filter case like we do in buildx repo for mod-outdated:

In this case we don't want to cache this specific stage because we always want to RUN.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a --no-cache-filter example, let me know what you think.

@dvdksn dvdksn force-pushed the cache-invalidation branch from 357944f to 699739c Compare March 13, 2024 15:09

```dockerfile
FROM alpine:{{% param "example_alpine_version" %}} AS install
RUN apk add install
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
RUN apk add install
RUN apk add curl

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Lol

Comment on lines 45 to 46
Suppose you have a step in your Dockerfile to upgrade all the software packages
in your Debian-based image to the latest version:
Copy link
Member

Choose a reason for hiding this comment

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

need changes now that we use alpine and install curl

Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
@dvdksn dvdksn force-pushed the cache-invalidation branch from 699739c to 3fc37c7 Compare March 13, 2024 15:36
Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

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

:shipit:

@dvdksn dvdksn merged commit 1ced970 into docker:main Mar 13, 2024
9 checks passed
@dvdksn dvdksn deleted the cache-invalidation branch March 13, 2024 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build Relates to Dockerfiles or docker build command
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants