Skip to content

Conversation

@amitsaha
Copy link

@amitsaha amitsaha commented Aug 7, 2021

This pull request adds support for specifying a platform of the image to fetch. Equivalent to docker run --platform ...

@mdelapenya
Copy link
Member

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?

@amitsaha
Copy link
Author

amitsaha commented Aug 8, 2021

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 ImagePlatform is propagated to the code that calls out to the docker API. So perhaps we can test that instead of creating a real container which i am not sure is possible given the above explanation.

@amitsaha
Copy link
Author

amitsaha commented Aug 8, 2021

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.

@amitsaha amitsaha changed the title Support for specifying image platform WIP: Support for specifying image platform Aug 8, 2021
docker.go Outdated
}

var tag string
customPlatform := req.ImagePlatform
Copy link
Member

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.

@mdelapenya
Copy link
Member

@amitsaha could you take a look at the test failures? 🙏 I think we are close to merge :)

@amitsaha amitsaha changed the title WIP: Support for specifying image platform Support for specifying image platform Aug 15, 2021
@amitsaha
Copy link
Author

Hi @mdelapenya thanks. Pushed a fix.

@amitsaha
Copy link
Author

amitsaha commented Aug 17, 2021

looking at the test failures:

2021/08/16 22:55:00 Waiting for container id acae21f20ba8 image: rabbitmq:management-alpine
    network_test.go:99: failed to start container: /bin/sh command not executable

Is this something you folks have seen before?

@mdelapenya
Copy link
Member

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? 🤷‍♀️

@amitsaha
Copy link
Author

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.

@amitsaha
Copy link
Author

amitsaha commented Aug 18, 2021

@mdelapenya Fetching upstream master and then rebased fixed the test run. 🤞 let's see how the CI run goes.

Copy link
Member

@mdelapenya mdelapenya left a 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) {
Copy link
Member

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?

Suggested change
t.Run("Use a custom image platform", func(t *testing.T) {
t.Run("Use an invalid custom image platform", func(t *testing.T) {

Copy link
Author

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.

Copy link
Member

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")
Copy link
Member

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:

Suggested change
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
Copy link

codecov bot commented Aug 18, 2021

Codecov Report

Merging #342 (dcd0372) into master (5963181) will increase coverage by 0.57%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
container.go 85.29% <ø> (ø)
docker.go 64.70% <100.00%> (+1.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5963181...dcd0372. Read the comment docs.

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"
Copy link
Member

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)
}

Copy link
Author

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.

Copy link
Member

@mdelapenya mdelapenya left a 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!

@mdelapenya mdelapenya requested a review from gianarb August 19, 2021 10:34
@amitsaha
Copy link
Author

Just a gentle reminder on this one - thanks.

@mdelapenya
Copy link
Member

@gianarb what are your thoughts on this one? Testing in ARM is indeed a thing nowadays. Could you take a look? 🙏

@gianarb
Copy link
Member

gianarb commented Oct 22, 2021

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?
Thanks

@bsideup
Copy link
Member

bsideup commented Oct 22, 2021

@amitsaha
Copy link
Author

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?

Comment on lines +614 to +615
customOS = strings.Split(req.ImagePlatform, "/")[0]
customArch = strings.Split(req.ImagePlatform, "/")[1]
Copy link
Member

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"

👍

Copy link
Contributor

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.

@hairyhenderson
Copy link
Contributor

Any possibility to get this merged soon? This is necessary in some common scenarios (i.e. running the mysql:5.7 image, which isn't available for arm64 yet)

@hairyhenderson
Copy link
Contributor

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!)

@mdelapenya
Copy link
Member

I think we can close this one, given #395 was merged

Thanks @amitsaha for bringing the seed for this feature!

@mdelapenya mdelapenya closed this Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants