Skip to content

feat: support for mounting images #3044

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

Merged
merged 11 commits into from
Apr 25, 2025

Conversation

mdelapenya
Copy link
Member

@mdelapenya mdelapenya commented Mar 18, 2025

What does this PR do?

This PR updates the code for mounting images, creating a new mount type for Images, and adding the types and methods needed to implement it.

A new optional Validator interface has been added, in order to verify that the subpaths from the Image Mount are not absolute, which is a requirement from the Docker spec.

Unit tests have been added to cover the different use cases:

  • creation of image mounts
  • preparation of the mounts
  • validation of the image mounts

A functional options to be consumed by modules has been added, so they can simply mount the file system of another image with that option. An example for the Ollama module has been added too: a first container loads an LLM, the container is committed to a different image, and a second container mounts that image, resulting in having the LLM already loaded.

It's IMPORTANT to notice that the image mount capabilities are only available if the underlying container runtime supports it. Docker v28 does it.

Why is it important?

Consume new features from the Docker engine!

Follow-ups

I do not like the code for mounting volumes and tmpfs, as it's hard to follow, and in my opinion there are too many abstractions. So I'd advocate for starting a discussion on how to do a hard refactor for that part.

@mdelapenya mdelapenya requested a review from a team as a code owner March 18, 2025 12:55
@mdelapenya mdelapenya added feature New functionality or new behaviors on the existing one breaking change Causing compatibility issues. labels Mar 18, 2025
@mdelapenya mdelapenya self-assigned this Mar 18, 2025
@mdelapenya mdelapenya changed the title feat: support for mounting images feat!: support for mounting images Mar 18, 2025
Copy link

netlify bot commented Mar 18, 2025

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 2d4c316
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/680b490b68cef100085a58be
😎 Deploy Preview https://deploy-preview-3044--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -85,6 +100,40 @@ func (s DockerTmpfsMountSource) GetTmpfsOptions() *mount.TmpfsOptions {
return s.TmpfsOptions
}

// DockerImageMountSource is a mount source for an image
type DockerImageMountSource struct {
Copy link
Member

Choose a reason for hiding this comment

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

what about just ImageMountSource?

Copy link
Member Author

Choose a reason for hiding this comment

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

I used this for keeping consistency with the existing types. As mentioned in the follow-ups section:

I do not like the code for mounting volumes and tmpfs, as it's hard to follow, and in my opinion there are too many abstractions. So I'd advocate for starting a discussion on how to do a hard refactor for that part.

So I'm open to start a rewrite of that layer

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd go with the simple naming too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed there must be a simpler abstraction for this seems there's multiple layers just adding complexity.

* main:
  chore(deps): bump golang.org/x/net from 0.23.0 to 0.36.0 in /modules/dynamodb (testcontainers#3059)
  chore(deps): bump github.com/magiconair/properties from 1.8.7 to 1.8.9 (testcontainers#3057)
  chore(deps): bump golangci/golangci-lint-action from 6.3.0 to 6.5.2 (testcontainers#3052)
  chore(deps): bump golang.org/x/sys from 0.28.0 to 0.31.0 (testcontainers#3056)
  chore(deps): bump actions/setup-go from 5.3.0 to 5.4.0 (testcontainers#3054)
  chore(deps): bump golang.org/x/net in /modules/scylladb (testcontainers#3058)
  chore(deps): bump github/codeql-action from 3.28.11 to 3.28.12 (testcontainers#3053)
  chore(deps): bump golang.org/x/net in /modules/databend (testcontainers#3055)
  feat(azure)!: add Azurite, EventHubs and ServiceBus in the new Azure module, deprecating the old Azurite module (testcontainers#3008)
  fix: update script path in chmod
  fix: update sonar script path (testcontainers#3045)
  chore(ci): manage Sonar projects from Github actions (testcontainers#3039)
  chore(deps): bump github.com/docker/buildx in /modules/compose (testcontainers#3043)
@@ -85,6 +100,40 @@ func (s DockerTmpfsMountSource) GetTmpfsOptions() *mount.TmpfsOptions {
return s.TmpfsOptions
}

// DockerImageMountSource is a mount source for an image
type DockerImageMountSource struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd go with the simple naming too.

@@ -85,6 +100,40 @@ func (s DockerTmpfsMountSource) GetTmpfsOptions() *mount.TmpfsOptions {
return s.TmpfsOptions
}

// DockerImageMountSource is a mount source for an image
type DockerImageMountSource struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed there must be a simpler abstraction for this seems there's multiple layers just adding complexity.

@mdelapenya mdelapenya removed the breaking change Causing compatibility issues. label Mar 28, 2025
@mdelapenya mdelapenya changed the title feat!: support for mounting images feat: support for mounting images Mar 28, 2025
* main:
  fix: skip nil strategies in wait.ForAll (testcontainers#3032)
  chore: prepare for next minor development cycle (0.37.0)
  chore: use new version (v0.36.0) in modules and examples
  chore: dockerise docs build (testcontainers#3060)
@mdelapenya mdelapenya requested a review from stevenh March 28, 2025 12:20
@mdelapenya
Copy link
Member Author

@stevenh @eddumelendez I acknowledge that the names used in this PR could be better, but they are consistent with the existing types. As mentioned above I'm open to start a full-rewrite of this part, from scratch.

In the meantime, I think this is good to go for the next release.

@mdelapenya
Copy link
Member Author

I'm merging this one, as interesting to have it for the next release.

@mdelapenya mdelapenya merged commit 224da6d into testcontainers:main Apr 25, 2025
391 of 392 checks passed
@mdelapenya mdelapenya deleted the mount-image branch April 25, 2025 10:20
mdelapenya added a commit to waroir20/testcontainers-go that referenced this pull request May 7, 2025
* main: (76 commits)
  chore(deps): bump mkdocs-include-markdown-plugin from 6.2.2 to 7.1.5 (testcontainers#3137)
  chore(deps): bump github.com/shirou/gopsutil/v4 from 4.25.1 to 4.25.4 (testcontainers#3133)
  chore(deps): bump github.com/docker/docker from 28.0.1+incompatible to 28.1.1+incompatible (testcontainers#3152)
  feat(memcached): add memcached module (testcontainers#3132)
  fix(etcd): single node etcd cluster access (testcontainers#3149)
  feat(valkey): add TLS support for Valkey (testcontainers#3131)
  fix(dockermodelrunner): wait for the model to be pulled (testcontainers#3125)
  fix(localstack): remove checksum before parsing version (testcontainers#3130)
  fix(dockermodelrunner): dependency with socat
  chore: prepare for next minor development cycle (0.38.0)
  chore: use new version (v0.37.0) in modules and examples
  fix: handle stopped containers more gracefully when reuse is enabled (testcontainers#3062)
  feat(gcloud): add option to run firestore in datastore mode (testcontainers#3009)
  feat: support for mounting images (testcontainers#3044)
  chore(ci): close PR if it was sent from main (testcontainers#3123)
  feat: add `WithReuseByName` for modifying Generic Container Requests (testcontainers#3064)
  chore(deps): bump github/codeql-action from 3.28.15 to 3.28.16 (testcontainers#3120)
  chore(deps): bump mkdocs-include-markdown-plugin from 6.2.2 to 7.1.5 (testcontainers#3119)
  chore(deps): bump github.com/magiconair/properties from 1.8.9 to 1.8.10 (testcontainers#3118)
  chore(ci): exclude more files for a full-blown build (testcontainers#3122)
  ...
mdelapenya added a commit to CTrando/testcontainers-go that referenced this pull request May 7, 2025
* main: (302 commits)
  chore(deps): bump mkdocs-include-markdown-plugin from 6.2.2 to 7.1.5 (testcontainers#3137)
  chore(deps): bump github.com/shirou/gopsutil/v4 from 4.25.1 to 4.25.4 (testcontainers#3133)
  chore(deps): bump github.com/docker/docker from 28.0.1+incompatible to 28.1.1+incompatible (testcontainers#3152)
  feat(memcached): add memcached module (testcontainers#3132)
  fix(etcd): single node etcd cluster access (testcontainers#3149)
  feat(valkey): add TLS support for Valkey (testcontainers#3131)
  fix(dockermodelrunner): wait for the model to be pulled (testcontainers#3125)
  fix(localstack): remove checksum before parsing version (testcontainers#3130)
  fix(dockermodelrunner): dependency with socat
  chore: prepare for next minor development cycle (0.38.0)
  chore: use new version (v0.37.0) in modules and examples
  fix: handle stopped containers more gracefully when reuse is enabled (testcontainers#3062)
  feat(gcloud): add option to run firestore in datastore mode (testcontainers#3009)
  feat: support for mounting images (testcontainers#3044)
  chore(ci): close PR if it was sent from main (testcontainers#3123)
  feat: add `WithReuseByName` for modifying Generic Container Requests (testcontainers#3064)
  chore(deps): bump github/codeql-action from 3.28.15 to 3.28.16 (testcontainers#3120)
  chore(deps): bump mkdocs-include-markdown-plugin from 6.2.2 to 7.1.5 (testcontainers#3119)
  chore(deps): bump github.com/magiconair/properties from 1.8.9 to 1.8.10 (testcontainers#3118)
  chore(ci): exclude more files for a full-blown build (testcontainers#3122)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or new behaviors on the existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants