-
-
Notifications
You must be signed in to change notification settings - Fork 547
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
Conversation
✅ Deploy Preview for testcontainers-go ready!
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 { |
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.
what about just ImageMountSource
?
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 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
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'd go with the simple naming too.
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.
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 { |
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'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 { |
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.
Agreed there must be a simpler abstraction for this seems there's multiple layers just adding complexity.
* 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)
@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. |
I'm merging this one, as interesting to have it for the next release. |
* 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) ...
* 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) ...
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:
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.