common icon indicating copy to clipboard operation
common copied to clipboard

Containerfile.5.md should document "magic" build-args

Open cevich opened this issue 1 year ago • 2 comments

Podman and buildah (I believe) both support similar/same set of automatic build-args as in the Docker documentation (I'm guessing, so maybe not all are supported?):

  • TARGETPLATFORM - platform of the build result. Eg linux/amd64, linux/arm/v7, windows/amd64.
  • TARGETOS - OS component of TARGETPLATFORM
  • TARGETARCH - architecture component of TARGETPLATFORM
  • TARGETVARIANT - variant component of TARGETPLATFORM
  • BUILDPLATFORM - platform of the node performing the build.
  • BUILDOS - OS component of BUILDPLATFORM
  • BUILDARCH - architecture component of BUILDPLATFORM
  • BUILDVARIANT - variant component of BUILDPLATFORM

In either case, some/all of these should be documented in the Containerfile man page. There are many situations where (esp) knowing (for example) the BUILDARCH is useful in RUN commands. Importantly because it's golang-flavored and difficult to access elsewhere (i.e. uname -m is different).

cevich avatar Mar 26 '24 18:03 cevich

Interested in opening a PR?

rhatdan avatar Mar 27 '24 10:03 rhatdan

I must admit I'm tempted to, I'm simply afraid I may not be able to get to it soon-ish. I'll put it on my TODO list, but if anybody else is inspired to fix this they should go ahead.

cevich avatar Mar 27 '24 18:03 cevich

Update: Don't bother trying to reference any of these build args in podman or buildah. Tested with podman 4.9.4 and 5.1.1, neither work. Example Containerfile:

FROM registry.fedoraproject.org/fedora-minimal:latest
ENV TARGETPLATFORM=${TARGETPLATFORM} \
    TARGETOS=${TARGETOS} \
    TARGETARCH=${TARGETARCH} \
    TARGETVARIANT=${TARGETVARIANT} \
    BUILDPLATFORM=${BUILDPLATFORM} \
    BUILDOS=${BUILDOS} \
    BUILDARCH=${BUILDARCH} \
    BUILDVARIANT=${BUILDVARIANT}
RUN printenv

Tested with a regular build and a --manifest=XYZ build including multiple platforms.

cevich avatar Jul 10 '24 14:07 cevich