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

Specify platform as linux/${ARCH} when cross-building docker images #2503

Merged
merged 2 commits into from
Dec 6, 2023

Conversation

hairyhum
Copy link
Contributor

Change Overview

When using arch specific dockerfiles it's also necessary to specify --platform flag. Otherwise dockerx can build arm image with x86_64 binaries, which may not work properly in deployment.

Pull request type

Please check the type of change your PR introduces:

  • 🚧 Work in Progress
  • 🌈 Refactoring (no functional changes, no api changes)
  • 🐹 Trivial/Minor
  • 🐛 Bugfix
  • 🌻 Feature
  • 🗺️ Documentation
  • 🤖 Test

Issues

Test Plan

  • 💪 Manual
  • ⚡ Unit test
  • 💚 E2E

To test run on arm64 arch (M1/M2 mac):

make build-controller
make release-controller VERSION=test_arch

Then check produced image:

docker image inspect kanisterio/controller:test_arch  | grep architecture

Without changes:

"architecture": "aarch64",

With changes

"architecture": "x86_64",

To run full test follow the steps in #2091

@infraq infraq added this to In Progress in Kanister Nov 30, 2023
docker run --rm ${mount_cmd} \
--platform linux/${ARCH}\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also have a way to override default linux os with something like ${OS} ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but do we anticipate that somebody ever changes base image in the dockerfile? Is there any use-case for that?

When using arch specific dockerfiles it's also necessary to specify `--platform`
flag. Otherwise dockerx can build arm image with x86_64 binaries, which may not
work properly in deployment.
@@ -66,5 +71,5 @@ sed \
-e "s|ARG_ARCH|${ARCH}|g" \
-e "s|ARG_SOURCE_BIN|${SOURCE_BIN}|g" \
Dockerfile.in > .dockerfile-${ARCH}
docker buildx build --push --pull --sbom=true ${baseimagearg:-} --build-arg kanister_version=${VERSION} -t ${IMAGE}:${VERSION} -f .dockerfile-${ARCH} .
docker buildx build --push --pull --sbom=true ${baseimagearg:-} --build-arg kanister_version=${VERSION} -t ${IMAGE}:${VERSION} --platform linux/${ARCH} -f .dockerfile-${ARCH} .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for @PrasadG193: We should make the SBOM flag configurable. --sbom={ENABLE_SBOM} or something like that. The packaging will fail if someone doesn't have the correct buildkit enabled.

Kanister automation moved this from In Progress to Reviewer approved Dec 5, 2023
@hairyhum hairyhum added the kueue label Dec 6, 2023
@mergify mergify bot merged commit 2756ffb into master Dec 6, 2023
15 checks passed
Kanister automation moved this from Reviewer approved to Done Dec 6, 2023
@mergify mergify bot deleted the build-image-arch branch December 6, 2023 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

[BUG] Kanister controller images built on Mac M1s do not work.
3 participants