-
-
Notifications
You must be signed in to change notification settings - Fork 511
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
First implementation of DockerRegitry module #1165
First implementation of DockerRegitry module #1165
Conversation
✅ Deploy Preview for testcontainers-go ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
5e5b445
to
98072f6
Compare
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.
Great contribution! Not sure if you already took a look at the existing tests including an authenticated docker registry (please see https://github.com/testcontainers/testcontainers-go/blob/main/docker_auth_test.go#L240), which I think it could be a great addition to this module, something like adding a customizer for WithAuthentication
or similar.
Wdyt?
Not to mention that we could eventually merge this PR at this state, without the authentication, and create a follow-up PR with that work. At the end of the day, the module won't be available until the next release |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
68403a3
to
61ff364
Compare
Hi @davidesalerno did you take a look at my comment here #1165 (review)? |
Yes, I've just added a customizer to support an authenticated registry but I'm having some issue in testing it due to issu #279. Could you help me in test that is working making this unit test working? |
return &DockerRegistryContainer{Container: container}, nil | ||
} | ||
|
||
func WithAuthentication(dockerAuthConfig string) testcontainers.CustomizeRequestOption { |
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.
Let's define the expectations on how to use this module: that would a user expect if the registry runs with authentication?
- should it be possible to pass an arbitrary
htpassw
file? See https://github.com/testcontainers/testcontainers-go/blob/main/testdata/auth/htpasswd - should it be possible to load/push images to it?
I'd try to start with a container request like the one in this test: https://github.com/testcontainers/testcontainers-go/blob/main/docker_auth_test.go#L275-L299, allowing customising the auth file.
Then, the test for the module should check that's is posible to log in into that registry.
Does it make sense to you?
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.
Yes it is making sense to me.
Do we want also a realm as a parameter?
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 do not have a strong opinion... I think we can start simple, and iterate with a follow-up PR for the realm if you want. Or if you see it important, add it here. What is your preference? At the same time, if you consider it important for users of the module, then we can include it since the beginning.
Signed-off-by: Davide Salerno <[email protected]>
df08171
to
9a5ef0d
Compare
Signed-off-by: Davide Salerno <[email protected]>
9a5ef0d
to
3811c5b
Compare
Signed-off-by: Davide Salerno <[email protected]>
Signed-off-by: Davide Salerno <[email protected]>
Signed-off-by: Davide Salerno <[email protected]>
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
@@ -68,6 +68,7 @@ nav: | |||
- modules/pulsar.md | |||
- modules/redis.md | |||
- modules/redpanda.md | |||
- modules/dockerregistry.md |
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.
This entry will be probably located at L63 https://github.com/testcontainers/testcontainers-go/pull/1165/files#diff-98d0f806abc9af24e6a7c545d3d77e8f9ad57643e27211d7a7b896113e420ed2R63
@@ -138,6 +138,12 @@ updates: | |||
interval: monthly | |||
open-pull-requests-limit: 3 | |||
rebase-strategy: disabled | |||
- package-ecosystem: gomod |
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.
This entry will be probably located at L93: https://github.com/testcontainers/testcontainers-go/pull/1165/files#diff-dd4fbda47e51f1e35defb9275a9cd9c212ecde0b870cba89ddaaae65c5f3cd28R93
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*DockerRegistryContainer, error) { | ||
req := testcontainers.ContainerRequest{ | ||
Image: "registry:2", | ||
ExposedPorts: []string{"5000:5000/tcp"}, |
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 think we do not want to always force a fixed port for the container:
ExposedPorts: []string{"5000:5000/tcp"}, | |
ExposedPorts: []string{"5000/tcp"}, |
|
||
} | ||
|
||
// WithData customizer that will retrieve a data directory and mount it inside the registry container |
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.
Do we need a Docker mount for it? I wonder if copying the files/dir into the container, using the req.Files
attribute would be something to consider.
@eddumelendez is there a preference when creating modules: using mounts or just copying files before the container start? 🤔
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.
The preference is to copy files.
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.
@davidesalerno then I'd advocate for converting all the Mounts into Files 🙏
// WithImage customizer that will override the registry image used | ||
func WithImage(image string) testcontainers.CustomizeRequestOption { | ||
return func(req *testcontainers.GenericContainerRequest) { | ||
req.Image = image | ||
} | ||
} |
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.
The core library already exposes a testcontainers.WithImage
option, which can be used in the modules.
// WithImage customizer that will override the registry image used | |
func WithImage(image string) testcontainers.CustomizeRequestOption { | |
return func(req *testcontainers.GenericContainerRequest) { | |
req.Image = image | |
} | |
} |
func TestDockerRegistryWithCustomImage(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
container, err := RunContainer(ctx, WithImage("docker.io/registry:latest")) |
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.
container, err := RunContainer(ctx, WithImage("docker.io/registry:latest")) | |
container, err := RunContainer(ctx, testcontainers.WithImage("docker.io/registry:latest")) |
_, cancel := context.WithCancel(context.Background()) | ||
t.Cleanup(cancel) | ||
} | ||
func getRegistryPortAndAddress(t *testing.T, err error, container *DockerRegistryContainer, ctx context.Context) (nat.Port, string) { |
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 create a method at the registry container level, so that any user would be able to get both. Please take a look at how mysql or postgres modules expose the ConnectionString
ctx := context.Background() | ||
wd, err := os.Getwd() | ||
assert.NoError(t, err) | ||
container, err := RunContainer(ctx, WithAuthentication(wd+"/../../testdata/auth"), WithData(wd+"/../../testdata/data"), WithImage("docker.io/registry:latest")) |
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 copy/duplicate the resources that exist in the core library to the module, to avoid relative paths and decouple the module from the upstream core library just a little bit more.
We could decide later if we want to test that feature in the core or in the module.
@@ -0,0 +1,11 @@ | |||
//go:build tools |
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.
Please take a look at #1303, which removed the dependency with gotestsum at the package dependency level: it's now a responsibility of our CI to install it, simplifying our dependency tree.
Therefore, this file should be removed
@@ -0,0 +1,56 @@ | |||
name: DockerRegistry module pipeline |
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.
Please take a look at #1414: this module file has been removed in favour of an array of modules in the ci.yml
workflow.
|
||
} | ||
|
||
// WithData customizer that will retrieve a data directory and mount it inside the registry container |
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.
@davidesalerno then I'd advocate for converting all the Mounts into Files 🙏
@davidesalerno we have sent #2341 creating a module for the docker registry. It supersedes this one, so I marked it to close this one. I'd thank you a lot if you could take a look to that PR and come with your feedback, so it should cover your use case 🙏 Cheers! |
What does this PR do?
This PR is adding the new Docker Registry module. This module is wrapping the registry image and it will be useful for those who needs to interact with a container registry to check if images are pushed or not after a build (i.e. local integration test of projects like kaniko or buildah).