Closed GrabbenD closed 1 year ago
I'll check this.
@GrabbenD For case 1.
The last step needs to be executed before it can be squash, following change was done intentionally here: https://github.com/containers/buildah/pull/4013
You can have a workaround by including a dummy last step and it will cache pacman
line correctly.
FROM archlinux AS rootfs
RUN pacman --noconfirm -Syu htop
RUN echo do-nothing
For case 2.
Cache matching works on history since first line is changed and is using different base, it will never match the cache ( this is expected behavior ) if you wanna cache deps I'd suggest exploring RUN --mount=type=cache
which is a feature built for this use-case itself.
I hope above answers your question. Please feel free to re-open or comment if something is unanswered.
Seems like I'm still experiencing this issue
Case 1 / Problem 1 (from original post)
You can have a workaround by including a dummy last step and it will cache pacman line correctly.
This doesn't work with multi-stage builds (which uses COPY --from=rootfs /mnt /
). I've tried using the echo before FROM
in the second stage and after COPY
Case 2 / Problem 2 (from original post)
I'd suggest exploring RUN --mount=type=cache
Sorry, I should have mentioned that the use-case is for OSTree and the idea is to have the:
rootfs
into /mnt
.scratch
image and COPY --from=rootfs /mnt /
(It's enough to use COPY --from=rootfs / /
like I've done above to reproduce this)
Edit: My bad. --squash
doesn't allow layer caching and the proposed workaround works as intended when using: --squash-all --layers
Issue Description
Problems:
Problem 1) layer cache with
--squash-all --layers
never works if Containerfile doesn't useCOPY --from
instruction.Example: this will rebuild every time (cache starts working if FROM/COPY lines are uncommented below):
Containerfile.base
Command:
$ time sh -c 'podman build -f Containerfile.base -t localhost/base --squash-all --layers'
Problem 2) layer cache
--squash-all --layers
breaks for the 2nd image (which uses 1st image as base) if the 1st image is rebuilt even though the 1st image was built from cache.Example: this sequence of commands will trigger rebuild for 2nd image every time (I don't have any workaround):
Containerfile.base
Containerfile.host
Commands:
time sh -c 'podman build -f Containerfile.base -t localhost/base --squash-all --layers && podman build -f Containerfile.host -t localhost/host --squash-all --layers'
Steps to reproduce the issue
Describe the results you received
Describe the results you expected
--squash-all --layers
shouldn't requireCOPY --from
to workpodman info output
Podman in a container
No
Privileged Or Rootless
Privileged
Upstream Latest Release
Yes
Additional environment details
N/A
Additional information
N/A