buildah: Build cache is not reused when overriding ARG with ENV in Dockerfile

First reported in: https://github.com/containers/libpod/issues/4312 by @JoshuaWatt

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind bug

Description

Following an ARG statement with an ENV statement that sets the same variable in a Dockerfile doesn’t allow the build cache to be reused.

Steps to reproduce the issue:

Consider the following simple Dockerfile:

FROM ubuntu:bionic
ARG FOO
ENV FOO=bat
RUN echo "Hello" >> word.txt

Run the following two build commands:

$ podman build --build-arg FOO=1
$ podman build --build-arg FOO=2

The second command should fully reuse the build cache from the first and not actually rebuild any part of the image, and the resulting image IDs should be the same

Describe the results you received: When the image is built with two different --build-arg FOO=... arguments under podman:

$ podman build . --build-arg FOO=1
STEP 1: FROM ubuntu:bionic
STEP 2: ARG FOO
a865f9caabda5040e7a262a5818b326843affa94a1b12bace0cdb85b0547a9b9
STEP 3: ENV FOO=bat
7a37a23803ca31464738d92b000cb9e566065f7f7c836d5eb3ac36707e0a8c48
STEP 4: RUN echo "Hello" >> word.txt
STEP 5: COMMIT
f6e1e1d1f40ec7aa236520b004a0b1567883016687c3ce3181004e67ab850ebd

$ podman build . --build-arg FOO=2
STEP 1: FROM ubuntu:bionic
STEP 2: ARG FOO
--> Using cache a865f9caabda5040e7a262a5818b326843affa94a1b12bace0cdb85b0547a9b9
STEP 3: ENV FOO=bat
--> Using cache 7a37a23803ca31464738d92b000cb9e566065f7f7c836d5eb3ac36707e0a8c48
STEP 4: RUN echo "Hello" >> word.txt
STEP 5: COMMIT
96136c36089c5780e7bce89f32aa918482ed1ee0123cbf20abcce063901f2cf8

Note that the resulting image IDs differ

Describe the results you expected:

When the image is built with two different --build-arg FOO=... arguments under docker:

$ docker build . --build-arg FOO=1
Sending build context to Docker daemon  15.87kB
Step 1/4 : FROM ubuntu:bionic
 ---> 2ca708c1c9cc
Step 2/4 : ARG FOO
 ---> Running in 27af63ed2d56
Removing intermediate container 27af63ed2d56
 ---> 6018f52966f2
Step 3/4 : ENV FOO=bat
 ---> Running in a0dbd4ecf112
Removing intermediate container a0dbd4ecf112
 ---> 6c2e2a15a489
Step 4/4 : RUN echo "Hello" >> word.txt
 ---> Running in 3dc22a00447b
Removing intermediate container 3dc22a00447b
 ---> 62906d53f743
Successfully built 62906d53f743

$ docker build . --build-arg FOO=2
Sending build context to Docker daemon  15.87kB
Step 1/4 : FROM ubuntu:bionic
 ---> 2ca708c1c9cc
Step 2/4 : ARG FOO
 ---> Using cache
 ---> 6018f52966f2
Step 3/4 : ENV FOO=bat
 ---> Using cache
 ---> 6c2e2a15a489
Step 4/4 : RUN echo "Hello" >> word.txt
 ---> Using cache
 ---> 62906d53f743
Successfully built 62906d53f743

Note that the resulting image IDs are the same

Additional information you deem important (e.g. issue happens only occasionally): The behavior of the build cache in Docker when an ENV overrides an ARG is described here: https://docs.docker.com/engine/reference/builder/#impact-on-build-caching

Output of podman version:

Version:            1.5.1
RemoteAPI Version:  1
Go Version:         go1.12.7
OS/Arch:            linux/amd64

Output of podman info --debug:

debug:
  compiler: gc
  git commit: ""
  go version: go1.12.7
  podman version: 1.5.1
host:
  BuildahVersion: 1.10.1
  Conmon:
    package: podman-1.5.1-3.fc30.x86_64
    path: /usr/libexec/podman/conmon
    version: 'conmon version 2.0.0, commit: d728afa06cd2df86a27f32a4692c7099a56acc97-dirty'
  Distribution:
    distribution: fedora
    version: "30"
  MemFree: 1666191360
  MemTotal: 16768450560
  OCIRuntime:
    package: containerd.io-1.2.6-3.3.fc30.x86_64
    path: /usr/bin/runc
    version: |-
      runc version 1.0.0-rc8
      commit: 425e105d5a03fabd737a126ad93d62a9eeede87f
      spec: 1.0.1-dev
  SwapFree: 134306942976
  SwapTotal: 137438949376
  arch: amd64
  cpus: 8
  eventlogger: journald
  hostname: ola-842mrw1
  kernel: 5.2.17-200.fc30.x86_64
  os: linux
  rootless: true
  uptime: 576h 53m 58.68s (Approximately 24.00 days)
registries:
  blocked: null
  insecure: null
  search:
  - docker.io
  - registry.fedoraproject.org
  - quay.io
  - registry.access.redhat.com
  - registry.centos.org
store:
  ConfigFile: /home/wattj/.config/containers/storage.conf
  ContainerStore:
    number: 0
  GraphDriverName: overlay
  GraphOptions:
  - overlay.mount_program=/usr/bin/fuse-overlayfs
  GraphRoot: /home/wattj/.local/share/containers/storage
  GraphStatus:
    Backing Filesystem: extfs
    Native Overlay Diff: "false"
    Supports d_type: "true"
    Using metacopy: "false"
  ImageStore:
    number: 18
  RunRoot: /run/user/9542
  VolumePath: /home/wattj/.local/share/containers/storage/volumes

Package info (e.g. output of rpm -q podman or apt list podman):

podman-1.5.1-3.fc30.x86_64

Additional environment details (AWS, VirtualBox, physical, etc.):

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 4
  • Comments: 29 (12 by maintainers)

Most upvoted comments

I didn’t think we used a cache when we weren’t using --layers, so you’d need to use buildah build --layers or podman build, where --layers is the default.

@spgennard no update yet. WIll try to carve out some time.