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

When creating a buildpack with docker buildx --platform linux/arm64 pack does not set the architecture #2079

Closed
jericop opened this issue Feb 25, 2024 · 5 comments · Fixed by #2086
Assignees
Labels
status/ready Issue ready to be worked on. type/bug Issue that reports an unexpected behaviour.
Milestone

Comments

@jericop
Copy link
Contributor

jericop commented Feb 25, 2024

Summary

The following occurs when running pack from a dockerfile using docker buildx build. When creating a buildpack with pack buildpack package the architecture is always an empty string, regardless of the architecture you run on.

This issue is similar to #1958, except that it affects pack buildpack package instead of pack builder create.

Reproduction

Note that docker needs to be configured to build multi-arch images for this to work as described here.

Steps
  1. Create the following dockerfile in a directory.
FROM buildpacksio/pack as pack

FROM bitnami/git
USER root
WORKDIR /workspace

COPY --from=pack /usr/local/bin/pack /usr/local/bin/pack

RUN <<RUN_EOF

image_arch=amd64
if [ $(arch) = "aarch64" ]; then
  image_arch=arm64
fi

git clone --depth 1 --branch main https://github.com/buildpacks/samples.git

pack buildpack package ttl.sh/jericop-hello-world-buildpack:${image_arch} --publish \
  --path samples/buildpacks/hello-world

RUN_EOF

  1. Run the following docker buildx command to create and publish buildpacks to ttl.sh, an ephemeral registry.
docker buildx build --platform linux/amd64,linux/arm64 .
  1. Inspect the image config with crane to confirm the architecture is an empty string.
➜  pack-arch-issue crane ls ttl.sh/jericop-hello-world-buildpack
amd64
arm64
➜  pack-arch-issue crane config ttl.sh/jericop-hello-world-buildpack:amd64 | jq .architecture
""
➜  pack-arch-issue crane config ttl.sh/jericop-hello-world-buildpack:arm64 | jq .architecture
""
➜  pack-arch-issue 
Current behavior

The architecture is empty, which prevents building multi-arch images without modifying the image or doing some docker manifest magic.

Expected behavior

The architecture should match the architecture that pack is running on.


Environment

pack info
Pack:
  Version:  0.33.2+git-f2cffc4.build-5562
  OS/Arch:  darwin/amd64

Default Lifecycle Version:  0.18.5

Supported Platform APIs:  0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.10, 0.11, 0.12
docker info
Client:
 Version:    25.0.3
Server:
 Server Version: 25.0.3

@jericop jericop added type/bug Issue that reports an unexpected behaviour. status/triage Issue or PR that requires contributor attention. labels Feb 25, 2024
@jericop jericop self-assigned this Feb 25, 2024
@jericop
Copy link
Contributor Author

jericop commented Feb 27, 2024

I believe this change also addresses #1968, which was fixed by adding retry logic.

@jjbustamante jjbustamante added status/ready Issue ready to be worked on. and removed status/triage Issue or PR that requires contributor attention. labels Mar 4, 2024
@WYGIN
Copy link
Contributor

WYGIN commented Mar 4, 2024

I will take this issue, as I already did some changes in imgutil related to it :)

@jericop
Copy link
Contributor Author

jericop commented Mar 4, 2024

@WYGIN I have a pull request with changes and unit tests already here. Maybe we can figure out how to merge the changes together.

@jjbustamante jjbustamante added this to the 0.34.0 milestone Apr 3, 2024
@jjbustamante
Copy link
Member

jjbustamante commented May 8, 2024

@jericop

We are working to include #2086 into pack 0.34.0 that PR should fix this issue! I think we can close #2080 in favor on that one.

@jjbustamante
Copy link
Member

With the implementation of RFC 0128 you don't need to use docker buildx to create a multi-platform buildpack package.

From your Dockerfile configuration, you just need to do is:

pack buildpack package ttl.sh/jericop-hello-world-buildpack:${image_arch} --publish \
  --path samples/buildpacks/hello-world \
  --target linux/amd64 \
  --target linux/arm64 

and pack will create the manifests with the correct os and architecture.

Using the binary from the open PR I did this:

> $PACK_BINARY buildpack package ttl.sh/jjbustamante-hello-world-buildpack:${image_arch} --publish --path samples/buildpacks/hello-world --targe
t linux/amd64 --target linux/arm64
Successfully pushed manifest list ttl.sh/jjbustamante-hello-world-buildpack: to registry
Successfully published package ttl.sh/jjbustamante-hello-world-buildpack: and saved to registry

# Inspect the Index
> crane manifest  ttl.sh/jjbustamante-hello-world-buildpack | jq .
{
  "schemaVersion": 2,
  "mediaType": "application/vnd.oci.image.index.v1+json",
  "manifests": [
    {
      "mediaType": "application/vnd.oci.image.manifest.v1+json",
      "size": 402,
      "digest": "sha256:46ee213ae13e9e33a486f95780bdd09cda71955bcb55d4ceffe423265c752e3f",
      "platform": {
        "architecture": "amd64",
        "os": "linux"
      }
    },
    {
      "mediaType": "application/vnd.oci.image.manifest.v1+json",
      "size": 402,
      "digest": "sha256:11d69032ed77c74be777d081321af19617fb1acd660f02b01f7ec46b85481130",
      "platform": {
        "architecture": "arm64",
        "os": "linux"
      }
    }
  ]
}

# Inspecting each digest

> crane config ttl.sh/jjbustamante-hello-world-buildpack@sha256:11d69032ed77c74be777d081321af19617fb1acd660f02b01f7ec46b85481130 | jq .architecture
"arm64"

> crane config ttl.sh/jjbustamante-hello-world-buildpack@sha256:46ee213ae13e9e33a486f95780bdd09cda71955bcb55d4ceffe423265c752e3f | jq .architecture
"amd64

I think this is the expected output, right? docker buildx was used to deal with the Image Index creation 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/ready Issue ready to be worked on. type/bug Issue that reports an unexpected behaviour.
Projects
None yet
3 participants