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

Incompatibility with Podman: "attempted to redefine 'BUILDPLATFORM'" Error in Multi-Stage Build #120

Closed
frobware opened this issue Sep 2, 2024 · 0 comments · Fixed by #121
Assignees
Milestone

Comments

@frobware
Copy link
Contributor

frobware commented Sep 2, 2024

I'm encountering an issue when building the bpfman-operator and bpfman-agent image using Podman. The build fails with the following error message:

% make build-images
Adding GOCACHE volume mount /home/aim/.cache/go-build:/root/.cache/go-build.
podman version
Client:       Podman Engine
Version:      5.2.1
API Version:  5.2.1
Go Version:   go1.22.5
Built:        Wed Aug 14 01:00:00 2024
OS/Arch:      linux/amd64
podman buildx build --load -t quay.io/bpfman/bpfman-operator:latest \
  --build-arg TARGETPLATFORM=linux/amd64 \
  --build-arg TARGETARCH=amd64 \
  --build-arg BUILDPLATFORM=linux/amd64 \
  --volume "/home/aim/.cache/go-build:/root/.cache/go-build:z" \
  -f Containerfile.bpfman-operator .
Error: reading multiple stages: attempted to redefine "BUILDPLATFORM": invalid argument

This issue arises due to the redefinition of the BUILDPLATFORM argument in the Containerfile.bpfman-operator (and in Containerfile.bpfman-agent. The Containerfile* currently defines ARG BUILDPLATFORM twice: once globally at the top of the file and again within the bpfman-operator-build stage. While Docker allows this without issue, Podman is stricter about argument redefinition, resulting in a build failure.

Steps to Reproduce:

  1. Use Podman version 5.2.1 (or similar).
  2. Run make build-images OCI_BIN=podman.
  3. The build fails with the error mentioned above.

If I use docker the build completes OK:

% make build-images OCI_BIN=docker
docker version
Client: Docker Engine - Community
 Version:           27.1.2
 API version:       1.46
 Go version:        go1.21.13
 Git commit:        d01f264
 Built:             Mon Aug 12 11:52:28 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          27.1.2
  API version:      1.46 (minimum version 1.24)
  Go version:       go1.21.13
  Git commit:       f9522e5
  Built:            Mon Aug 12 11:50:46 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.20
  GitCommit:        8fc6bcff51318944179630522a095cc9dbf9f353
 runc:
  Version:          1.1.13
  GitCommit:        v1.1.13-0-g58aa920
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
docker buildx build --load -t quay.io/bpfman/bpfman-operator:latest \
  --build-arg TARGETPLATFORM=linux/amd64 \
  --build-arg TARGETARCH=amd64 \
  --build-arg BUILDPLATFORM=linux/amd64 \
   \
  -f Containerfile.bpfman-operator .
[+] Building 0.5s (3/4)                                                                                                                                           docker-container:admiring_germain
 => [internal] load build definition from Containerfile.bpfman-operator                                                                                                                        0.0s
 => => transferring dockerfile: 2.17kB                                                                                                                                                         0.0s
 => WARN: RedundantTargetPlatform: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior (line 33)                                               0.0s
 => [internal] load metadata for quay.io/fedora/fedora-minimal:latest                                                                                                                          0.4s
 => [internal] load metadata for docker.io/library/golang:1.22                                                                                                                                 0.4s
 => [auth] library/golang:pull token for registry-1.docker.io   
...                        

Expected Behaviour:

The image should build successfully without errors, as it does when using Docker.

Proposed Solution:

To resolve this issue, I suggest removing the global ARG BUILDPLATFORM=linux/amd64 declaration at the top of the Containerfile.bpfman-{agent,operator}. This will allow the build process to pass in the BUILDPLATFORM value as needed without causing a conflict.

@github-project-automation github-project-automation bot moved this to 🆕 New in bpfman Sep 2, 2024
frobware added a commit to frobware/bpfman-operator that referenced this issue Sep 2, 2024
Removed the hardcoded `ARG BUILDPLATFORM=linux/amd64` from
`Containerfile.bpfman-agent` and `Containerfile.bpfman-operator`.

This change addresses an issue where Podman fails to build the images if
`BUILDPLATFORM` is redefined. By removing the redefinition, the build
process is made compatible with Podman.

This change remains compatible with Docker, which is more lenient with
ARG redefinitions.

Fixes: bpfman#120

Signed-off-by: Andrew McDermott <[email protected]>
@frobware frobware self-assigned this Sep 2, 2024
frobware added a commit to frobware/bpfman-operator that referenced this issue Sep 2, 2024
Removed the hardcoded `ARG BUILDPLATFORM=linux/amd64` from
`Containerfile.bpfman-agent` and `Containerfile.bpfman-operator`.

This change addresses an issue where Podman fails to build the images if
`BUILDPLATFORM` is redefined. By removing the redefinition, the build
process is made compatible with Podman.

This change remains compatible with Docker, which is more lenient with
ARG redefinitions.

Fixes: bpfman#120

Signed-off-by: Andrew McDermott <[email protected]>
frobware added a commit to frobware/bpfman-operator that referenced this issue Sep 3, 2024
Removed the hardcoded `ARG BUILDPLATFORM=linux/amd64` from
`Containerfile.bpfman-agent` and `Containerfile.bpfman-operator`.

This change addresses an issue where Podman fails to build the images if
`BUILDPLATFORM` is redefined. By removing the redefinition, the build
process is made compatible with Podman.

This change remains compatible with Docker, which is more lenient with
ARG redefinitions.

Fixes: bpfman#120

Signed-off-by: Andrew McDermott <[email protected]>
frobware added a commit to frobware/bpfman-operator that referenced this issue Sep 3, 2024
Removed the hardcoded `ARG BUILDPLATFORM=linux/amd64` from
`Containerfile.bpfman-agent` and `Containerfile.bpfman-operator`.

This change addresses an issue where Podman fails to build the images if
`BUILDPLATFORM` is redefined. By removing the redefinition, the build
process is made compatible with Podman.

This change remains compatible with Docker, which is more lenient with
ARG redefinitions.

Fixes: bpfman#120

Signed-off-by: Andrew McDermott <[email protected]>
frobware added a commit to frobware/bpfman-operator that referenced this issue Sep 5, 2024
Removed the hardcoded `ARG BUILDPLATFORM=linux/amd64` from
`Containerfile.bpfman-agent{.openshift}` and
`Containerfile.bpfman-operator{.openshift}`.

This change addresses an issue where Podman fails to build the images if
`BUILDPLATFORM` is redefined. By removing the redefinition, the build
process is made compatible with Podman.

This change remains compatible with Docker, which is more lenient with
ARG redefinitions.

Fixes: bpfman#120

Signed-off-by: Andrew McDermott <[email protected]>
@anfredette anfredette added this to the Q3-2024 milestone Sep 5, 2024
frobware added a commit to frobware/bpfman-operator that referenced this issue Sep 5, 2024
Removed the hardcoded `ARG BUILDPLATFORM=linux/amd64` from
`Containerfile.bpfman-agent{.openshift}` and
`Containerfile.bpfman-operator{.openshift}`.

This change addresses an issue where Podman fails to build the images if
`BUILDPLATFORM` is redefined. By removing the redefinition, the build
process is made compatible with Podman.

This change remains compatible with Docker, which is more lenient with
ARG redefinitions.

Fixes: bpfman#120

Signed-off-by: Andrew McDermott <[email protected]>
frobware added a commit to frobware/bpfman-operator that referenced this issue Sep 6, 2024
Removed the hardcoded `ARG BUILDPLATFORM=linux/amd64` from
`Containerfile.bpfman-agent{.openshift}` and
`Containerfile.bpfman-operator{.openshift}`.

This change addresses an issue where Podman fails to build the images if
`BUILDPLATFORM` is redefined. By removing the redefinition, the build
process is made compatible with Podman.

This change remains compatible with Docker, which is more lenient with
ARG redefinitions.

Fixes: bpfman#120

Signed-off-by: Andrew McDermott <[email protected]>
frobware added a commit to frobware/bpfman-operator that referenced this issue Sep 6, 2024
Removed the hardcoded `ARG BUILDPLATFORM=linux/amd64` from
`Containerfile.bpfman-agent{.openshift}` and
`Containerfile.bpfman-operator{.openshift}`.

This change addresses an issue where Podman fails to build the images if
`BUILDPLATFORM` is redefined. By removing the redefinition, the build
process is made compatible with Podman.

This change remains compatible with Docker.

Fixes: bpfman#120

Signed-off-by: Andrew McDermott <[email protected]>
@mergify mergify bot closed this as completed in #121 Sep 6, 2024
@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Done in bpfman Sep 6, 2024
msherif1234 pushed a commit to msherif1234/bpfman-operator that referenced this issue Dec 17, 2024
…s/ocp-bpfman-agent

chore(deps): update ocp-bpfman-agent to 47580b4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants