testcontainers / testcontainers-ruby

Testcontainers for Ruby
MIT License
124 stars 17 forks source link

Allow passing options to `Docker::Image.create` #33

Closed HeyNonster closed 10 months ago

HeyNonster commented 10 months ago

The Docker ImageCreate api accepts a variety of parameters, you can pass those arguments in a hash as the first argument to Docker:Image.create

For the platform behavior, there is default behavior which is notable:

Default: ""

When used in combination with the fromImage option, the daemon checks if the given image is present
in the local image cache with the given OS and Architecture, and otherwise attempts to pull the image. 
If the option is not set, the host's native OS and Architecture are used.
...

Because it defauilts to the host's native architecture, it will attempt to pull images matching that architecture and raises not found if an image of that architecture doesn't exist. This can be a problem when, for example, attempting to pull a mysql image on Mx Macs. Testcontainers::DockerContainer.create('mysql:5.7') will fail because, as of this writing, arm images are not created for mysql:5.7.

The solution to this is to pass platform: 'linux/amd64' to Docker::Image.create. This tells Docker we specifically want a image for that architecture (Rosetta on Mac OS X can run linux/amd64 images).

This commit adds an optional image_create_options kwarg to DockerContainer#initialize that defaults to an empty hash. This kwarg allows for us to pass create parameters to Docker::Image.create.

I've also added a NotFoundError class because it seems that the convention is to wrap dependency errors in a Textcontainers error class.

Updates the readme, including a readme addition to explain the changes in #31.

HeyNonster commented 10 months ago

MySQL module failure should be solved by #32.

The Redpanda tests failure seems unrelated?

guilleiguaran commented 10 months ago

@HeyNonster thanks, I need to check the Redpanda tests since those fail from time to time