buildah icon indicating copy to clipboard operation
buildah copied to clipboard

Changing ENV via ARG does not break cache

Open mccare opened this issue 1 year ago • 2 comments

Description

Follow up to #5095.

Changing an ARG that is used in a later ENV statement will not break the cache. The issue was reported in #5095. The argument it was closed was that buildkit behaves the same way. In my testing buildkit has fixed or is not showing this behaviour any more.

Steps to reproduce the issue:

FROM busybox

ARG STAGE
ENV STAGE=$STAGE
podman build --build-arg STAGE=stage1 . -t envtest
podman build --build-arg STAGE=stage2 . -t envtest

both hashes are the same. When running the container after each command (podman run --rm -it envtest and then env) it will show the STAGE environment as being "stage1" and not change to stage2

When running with buildkit v0.12.3 (which is packaged in my Docker on Mac installation):

docker buildx build --build-arg STAGE=stage1 --load .
docker buildx build --build-arg STAGE=stage2 --load .

This will produce two different hashes and when running the containers in between they will have the correct STAGE environment variable value.

Describe the results you received:

STAGE environment variable does not change between the container builds.

Describe the results you expected:

STAGE environment variable

Output of podman version if reporting a podman build issue:

host:
  arch: arm64
  buildahVersion: 1.36.0-dev
  cgroupControllers:
  - cpu
  - io
  - memory
  - pids
  cgroupManager: systemd
  cgroupVersion: v2
  conmon:
    package: conmon-2.1.10-1.fc40.aarch64
    path: /usr/bin/conmon
    version: 'conmon version 2.1.10, commit: '
  cpuUtilization:
    idlePercent: 98.98
    systemPercent: 0.55
    userPercent: 0.47
  cpus: 5
Client:       Podman Engine
Version:      5.1.0
API Version:  5.1.0
Go Version:   go1.22.3
Git Commit:   4e9486dbc63c24bfe109066abbb54d5d8dc2489e
Built:        Wed May 29 20:52:05 2024
OS/Arch:      darwin/arm64

Server:       Podman Engine
Version:      5.1.0-dev-c9808e7ed
API Version:  5.1.0-dev-c9808e7ed
Go Version:   go1.22.2
Built:        Mon May 13 02:00:00 2024
OS/Arch:      linux/arm64

mccare avatar Jun 07 '24 07:06 mccare

A friendly reminder that this issue had no activity for 30 days.

github-actions[bot] avatar Jul 08 '24 00:07 github-actions[bot]

Same here, I had to handle image versioning and exec in image displaying the same version, thus this quite simple solution:

ARG APP_VERSION
# exec uses the env var to display the version
ENV APP_VERSION=${APP_VERSION}

Not working with buildah unless I invalidate the cache manually...

gautaz avatar Sep 24 '24 07:09 gautaz

A friendly reminder that this issue had no activity for 30 days.

github-actions[bot] avatar Oct 26 '24 00:10 github-actions[bot]