-
-
Notifications
You must be signed in to change notification settings - Fork 587
Support for specifying image platform #342
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
Conversation
|
Hi @amitsaha, thanks for this contribution. It LGTM, although I'd like to see a test if possible. I'm currently checking if github actions provide support for ARM so that we are able to run tests on ARM. Could you also check it please? |
Sure, so it looks like github actions can run tests on arm64 as explained here. Regarding the test, sure i am happy to. I am thinking around the testing strategy though. My current use case is i specified a x86-64 image for my Macbook M1 - and it works because of the emulation that M1 has. If we test x86-64 as the image platform, it can only succeed on a x86-64 build host. Similarly for the arm64 image. Here we really want to ensure that the |
|
I also realised, this only works for images which are to be pulled. For existing images, the platform option is not accounted for. I will push an update once i have got it working. In fact, that may mean we can test this in a nice way as well. |
docker.go
Outdated
| } | ||
|
|
||
| var tag string | ||
| customPlatform := req.ImagePlatform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super NIT: wdyt about saving this variable and directly use req.ImagePlatform elsewhere? Therefore the code itself will be self-contained: I had to double check that the customPlatform variable was in fact initialised with the requested one.
|
@amitsaha could you take a look at the test failures? 🙏 I think we are close to merge :) |
|
Hi @mdelapenya thanks. Pushed a fix. |
|
looking at the test failures: Is this something you folks have seen before? |
|
No, I haven't that error before in this test suite. Although the error is familiar to me when dealing with multi-platform support: can we ensure that the container uses the same platform (AMD Vs ARM) as the underlying CI machine? 🤷♀️ |
I thought that was the default behavior? I will have a look. |
19868c4 to
826e159
Compare
|
@mdelapenya Fetching upstream master and then rebased fixed the test run. 🤞 let's see how the CI run goes. |
mdelapenya
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a few comments, but other than that, this LGTM. Waiting for last minute feedback to approve it.
Thank you for your work here!!
docker_test.go
Outdated
| } | ||
|
|
||
| func TestContainerCustomPlatformImage(t *testing.T) { | ||
| t.Run("Use a custom image platform", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wdyt about renaming the test case? Because windows/arm12 is not a valid platform, I guess that even if running the tests on a Windows ARM machine, this will fail, right?
| t.Run("Use a custom image platform", func(t *testing.T) { | |
| t.Run("Use an invalid custom image platform", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mdelapenya this was my not so optimal attempt to test the functionality i am adding. I used windows/arm12 since that's a non-existent image platform so I expect the test to errror out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wdyt about Use a non-existent custom image platform then?
My intention here is to make the test super explicit to casual readers, specially on failures
docker_test.go
Outdated
| defer c.Terminate(context.Background()) | ||
| } | ||
| if err == nil { | ||
| t.Fatalf("Expected non-nil error") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the test expects to raise an error, I would log it with more information:
| t.Fatalf("Expected non-nil error") | |
| t.Fatalf("Expected non-nil error when using an invalid platform: 'windows/arm12'") |
Maybe extracting the platform to a variable to be reused in this message? wdyt?
Codecov Report
@@ Coverage Diff @@
## master #342 +/- ##
==========================================
+ Coverage 61.32% 61.90% +0.57%
==========================================
Files 15 15
Lines 993 1008 +15
==========================================
+ Hits 609 624 +15
- Misses 292 293 +1
+ Partials 92 91 -1
Continue to review full report at Codecov.
|
docker_test.go
Outdated
| t.Fatalf("Expected non-nil error") | ||
| t.Fatalf("Expected an error containing failed to create container: Error response from daemon") | ||
| } | ||
| expectedErrorMsgSubstring := "image with reference redis:latest was found but does not match the specified platform" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm, not sure about this new verification. Will that message change between Docker versions? If you see it convenient, I'm OK with it too, but I'd like to make sure we are not adding flakiness because of specific message formats.
if err == nil {
t.Fatalf("Expected non-nil error with a non-existent platform: %s", nonExistentPlatform)
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a good idea. done.
mdelapenya
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for your patience while reviewing it!
|
Just a gentle reminder on this one - thanks. |
|
@gianarb what are your thoughts on this one? Testing in ARM is indeed a thing nowadays. Could you take a look? 🙏 |
|
I feel like I would like to know how java handles that! @bsideup any tip for us?! How do you do multi arch in java? |
|
Hey @gianarb and @mdelapenya, |
|
It seems to me that the Java client by default will aim to pull the image of the same platform as the docker daemon and then fallback to x86 if that fails? Essentially, you are not exposing the image platform spec to the consumer of the library? Would it possible to get a resolution on this soon please? |
| customOS = strings.Split(req.ImagePlatform, "/")[0] | ||
| customArch = strings.Split(req.ImagePlatform, "/")[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is correct, as all platforms are formed by a string in this format: "os/arch"
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A platform may also have 3 parts (os/arch/variant) in some cases. It's probably safest to use containerd's platforms.Parse func for this.
|
Any possibility to get this merged soon? This is necessary in some common scenarios (i.e. running the |
|
I've issued #395 to try and help things move along here - I'm easy with either PR being merged (I needed the changes regardless, so I figured I might as well issue a PR if the commit's in my fork anyway!) |
This pull request adds support for specifying a platform of the image to fetch. Equivalent to
docker run --platform ...