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

Allow for optionally passing options to #remove #31

Merged

Conversation

HeyNonster
Copy link
Contributor

@HeyNonster HeyNonster commented Dec 8, 2023

The Docker::Container remove method in docker-api conditionally accepts a hash of options

Furthermore, removing a docker container, by default, will not remove the volumes unless you pass v: true as a parameter.

Without the ability to pass v: true we can end up with many dangling volumes that take up disk space.

This commit adds an optional hash argument to the DockerContainer #remove method, it defaults to an empty hash.

To assist with tests I've also added:

  • DockerContainer#mounts method which returns an array of the mount hashes from the container #info
  • DockerContainer#mount_names which returns an array of the mount names (ids)

Not changed but perhaps good to discuss: should remove also remove the volumes by default?

@HeyNonster HeyNonster force-pushed the nony--pass-in-options-to-remove branch from 65601e8 to 1be8365 Compare December 8, 2023 09:01
@HeyNonster HeyNonster marked this pull request as ready for review December 8, 2023 09:02
@HeyNonster HeyNonster changed the title Allow for optionally passing options to .remove Allow for optionally passing options to #remove Dec 8, 2023
@guilleiguaran
Copy link
Member

@HeyNonster hi! can you run rake standard:fix locally so the code style is fixed automatically to follow StandardRB?

The `Docker::Container` `remove` method in [docker-api conditionally accepts a hash of
options](https://github.com/upserve/docker-api/blob/6f7b7cd2b790ec0ca69f805d72ae0c504c8b2f49/lib/docker/container.rb#L248)

Furthermore, removing a docker container, by default, will [not remove the volumes](https://docs.docker.com/engine/api/v1.43/#tag/Container/operation/ContainerDelete)
unless you pass `v: true` as a parameter.

Without the ability to pass `v: true` we can end up with many dangling
volumes that take up disk space.

This commit adds an optional hash argument to the `DockerContainer`
`#remove` method, it defaults to an empty hash.

To assist with tests I've also added:
  - `DockerContainer#mounts` method which returns an array of the mount
  hashes from the container `#info`
  - `DockerContainer#mount_names` which returns an array of the mount
  names (ids)
@HeyNonster HeyNonster force-pushed the nony--pass-in-options-to-remove branch from 1be8365 to bb66e6d Compare December 12, 2023 08:38
@HeyNonster
Copy link
Contributor Author

@HeyNonster hi! can you run rake standard:fix locally so the code style is fixed automatically to follow StandardRB?

@guilleiguaran Done! :)

@HeyNonster
Copy link
Contributor Author

Seems to all be passing except for the timeout issue that's also present on the main branch! :)

@guilleiguaran guilleiguaran merged commit ee68f9f into testcontainers:main Dec 13, 2023
18 of 19 checks passed
@guilleiguaran
Copy link
Member

@HeyNonster thanks!!! I'll fix the timeout issue later this week (or feel free to send a PR for it if you have some spare time :D)

@HeyNonster
Copy link
Contributor Author

@HeyNonster thanks!!! I'll fix the timeout issue later this week (or feel free to send a PR for it if you have some spare time :D)

@guilleiguaran You probably already saw this, but: #32 🙂

HeyNonster added a commit to HeyNonster/testcontainers-ruby that referenced this pull request Dec 14, 2023
The [Docker ImageCreate](https://docs.docker.com/engine/api/v1.43/#tag/Image/operation/ImageCreate)
api accepts a variety of parameters.

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 testcontainers#31.
HeyNonster added a commit to HeyNonster/testcontainers-ruby that referenced this pull request Dec 14, 2023
The [Docker ImageCreate](https://docs.docker.com/engine/api/v1.43/#tag/Image/operation/ImageCreate)
api accepts a variety of parameters.

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 testcontainers#31.
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.

2 participants