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 uses cache despite ENV being set to differing ARG value #5501

Open
anarazel opened this issue May 1, 2024 · 1 comment
Open

Build uses cache despite ENV being set to differing ARG value #5501

anarazel opened this issue May 1, 2024 · 1 comment

Comments

@anarazel
Copy link

anarazel commented May 1, 2024

Hi,

Description

When an ENV variable is set to a value from ARG and ENV is not subsequently used in a RUN or such, buildah does not invalidate the cache. Instead an older cache entry, with the wrong ENV value is used. This does not happen if the ARG or ENV is used in a subsequent RUN step.

Repro

Dockerfile content

FROM debian:stable

ARG counter
ENV something=$counter

Execute the following a few times:

counter=$counter || 1;  counter=$(($counter + 1)); buildah build --layers --build-arg counter=$counter --tag testme . && echo expected counter value: $counter, is $(podman run --rm -it testme sh -c 'echo $something')

This will build an image with an increasing value for counter and print the value of $something. The use of podman here is just for brevity's sake.

Describe the results you received:

The first run is as expected:

STEP 1/3: FROM debian:stable
STEP 2/3: ARG counter
--> c9ceef6f746e
STEP 3/3: ENV something=$counter
COMMIT testme
--> e06fc858d20a
Successfully tagged localhost/testme:latest
e06fc858d20aedee6acfa73a67323d22f7def3544624f183fa9b72250b977a8c
expected counter value: 1, is 1

but the second run reuses the prior image:

STEP 1/3: FROM debian:stable
STEP 2/3: ARG counter
--> Using cache c9ceef6f746eb9fe78b011cf4314a0554e41e4036541fd4f46baa7dd0edede94
--> c9ceef6f746e
STEP 3/3: ENV something=$counter
--> Using cache e06fc858d20aedee6acfa73a67323d22f7def3544624f183fa9b72250b977a8c
COMMIT testme
--> e06fc858d20a
Successfully tagged localhost/testme:latest
e06fc858d20aedee6acfa73a67323d22f7def3544624f183fa9b72250b977a8c
expected counter value: 2, is 1

Note that the resulting image ID is the same.

Describe the results you expected:

The second run should not have reused the cached image. I.e. instead of expected counter value: 2, is 1, the output should have been expected counter value: 2, is 2.

If I add

RUN echo $counter

or

RUN echo $something

to the tail of the Dockerfile, the issue does not occur.

Output of rpm -q buildah or apt list buildah:

buildah/experimental,now 1.34.0+ds1-2 amd64 [installed]
buildah/unstable 1.33.7+ds1-1 i386

Reproduces with both of the above.

Output of buildah version:

Version:         1.34.0
Go Version:      go1.21.6
Image Spec:      1.1.0-rc.5
Runtime Spec:    1.1.0
CNI Spec:        1.0.0
libcni Version:  
image Version:   5.29.2
Git Commit:      
Built:           Wed Dec 31 16:00:00 1969
OS/Arch:         linux/amd64
BuildPlatform:   linux/amd64

Output of uname -a:

Linux awork3 6.8.5-andres-00001-g9cb0ad7b5fbd #81 SMP PREEMPT_DYNAMIC Thu Apr 11 09:42:31 PDT 2024 x86_64 GNU/Linux

Greetings,

Andres

@traceypooh
Copy link

I'm seeing this, too, in debian bookworm, podman v4.3.1
(and it's mangling my conversion at archive.org from docker to podman for self-hosted gitlab runner)

FROM busybox

ARG NUM	
ENV NUM=${NUM}

ENTRYPOINT echo is $NUM
N=1; podman build -t nix$N --build-arg NUM=$N .
N=2; podman build -t nix$N --build-arg NUM=$N .

podman run nix1
is 1

podman run nix2
is 1

latter should be is 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants