-
-
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
Changes from all commits
7025005
3811c5b
83aa322
f66f0b9
8e54e79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: DockerRegistry module pipeline | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
on: | ||
push: | ||
paths-ignore: | ||
- 'mkdocs.yml' | ||
- 'docs/**' | ||
- 'README.md' | ||
pull_request: | ||
paths-ignore: | ||
- 'mkdocs.yml' | ||
- 'docs/**' | ||
- 'README.md' | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test-dockerregistry: | ||
strategy: | ||
matrix: | ||
go-version: [1.19.x, 1.x] | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
id: go | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v3 | ||
|
||
- name: modVerify | ||
working-directory: ./modules/dockerregistry | ||
run: go mod verify | ||
|
||
- name: modTidy | ||
working-directory: ./modules/dockerregistry | ||
run: make tools-tidy | ||
|
||
- name: gotestsum | ||
working-directory: ./modules/dockerregistry | ||
run: make test-unit | ||
|
||
- name: Run checker | ||
run: | | ||
./scripts/check_environment.sh | ||
|
||
- name: Test Summary | ||
uses: test-summary/action@4ee9ece4bca777a38f05c8fc578ac2007fe266f7 | ||
with: | ||
paths: "**/TEST-dockerregistry*.xml" | ||
if: always() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# DockerRegistry | ||
|
||
Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
||
## Introduction | ||
|
||
The Testcontainers module for Docker Registry. | ||
|
||
## Adding this module to your project dependencies | ||
|
||
Please run the following command to add the Docker Registry module to your Go dependencies: | ||
|
||
``` | ||
go get github.com/testcontainers/testcontainers-go/modules/dockerregistry | ||
``` | ||
|
||
## Usage example | ||
|
||
<!--codeinclude--> | ||
[Creating a Docker Registry container](../../modules/dockerregistry/dockerregistry.go) | ||
<!--/codeinclude--> | ||
|
||
<!--codeinclude--> | ||
[Test for a Docker Registry container](../../modules/dockerregistry/dockerregistry_test.go) | ||
<!--/codeinclude--> | ||
|
||
## Module reference | ||
|
||
The Docker Registry module exposes one entrypoint function to create the Docker Registry container, and this function receives two parameters: | ||
|
||
```golang | ||
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*DockerRegistryContainer, error) | ||
``` | ||
|
||
- `context.Context`, the Go context. | ||
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options. | ||
|
||
### Container Options | ||
|
||
When starting the Docker Registry container, you can pass options in a variadic way to configure it. | ||
|
||
#### Image | ||
|
||
If you need to set a different Docker Registry image, you can use `testcontainers.WithImage` with a valid Docker image | ||
for DockerRegistry. E.g. `testcontainers.WithImage("docker.io/registry:latest")`. | ||
|
||
#### Wait Strategies | ||
|
||
If you need to set a different wait strategy for Docker Registry, you can use `testcontainers.WithWaitStrategy` with a valid wait strategy | ||
for DockerRegistry. | ||
|
||
!!!info | ||
The default deadline for the wait strategy is 60 seconds. | ||
|
||
At the same time, it's possible to set a wait strategy and a custom deadline with `testcontainers.WithWaitStrategyAndDeadline`. | ||
|
||
#### Docker type modifiers | ||
|
||
If you need an advanced configuration for Docker Registry, you can leverage the following Docker type modifiers: | ||
|
||
- `testcontainers.WithConfigModifier` | ||
- `testcontainers.WithHostConfigModifier` | ||
- `testcontainers.WithEndpointSettingsModifier` | ||
|
||
Please read the [Create containers: Advanced Settings](../features/creating_container.md#advanced-settings) documentation for more information. | ||
|
||
### Container Methods | ||
|
||
The Docker Registry container exposes the following methods: |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 |
||
- modules/vault.md | ||
- Examples: | ||
- examples/index.md | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include ../../commons-test.mk | ||
|
||
.PHONY: test | ||
test: | ||
$(MAKE) test-dockerregistry |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,96 @@ | ||||||||||||||
package dockerregistry | ||||||||||||||
|
||||||||||||||
import ( | ||||||||||||||
"context" | ||||||||||||||
|
||||||||||||||
"github.com/testcontainers/testcontainers-go" | ||||||||||||||
"github.com/testcontainers/testcontainers-go/wait" | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
// DockerRegistryContainer represents the DockerRegistry container type used in the module | ||||||||||||||
type DockerRegistryContainer struct { | ||||||||||||||
testcontainers.Container | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// RunContainer creates an instance of the DockerRegistry container type | ||||||||||||||
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 commentThe 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:
Suggested change
|
||||||||||||||
WaitingFor: wait.ForExposedPort(), | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
genericContainerReq := testcontainers.GenericContainerRequest{ | ||||||||||||||
ContainerRequest: req, | ||||||||||||||
Started: true, | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
for _, opt := range opts { | ||||||||||||||
opt.Customize(&genericContainerReq) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
container, err := testcontainers.GenericContainer(ctx, genericContainerReq) | ||||||||||||||
if err != nil { | ||||||||||||||
return nil, err | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
return &DockerRegistryContainer{Container: container}, nil | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// WithAuthentication customizer that will retrieve a htpasswd file into the htpasswd directory given in input | ||||||||||||||
func WithAuthentication(htpasswdPath string) testcontainers.CustomizeRequestOption { | ||||||||||||||
return func(req *testcontainers.GenericContainerRequest) { | ||||||||||||||
if req.Env == nil { | ||||||||||||||
req.Env = make(map[string]string) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
req.Env["REGISTRY_AUTH"] = "htpasswd" | ||||||||||||||
req.Env["REGISTRY_AUTH_HTPASSWD_REALM"] = "Registry" | ||||||||||||||
req.Env["REGISTRY_AUTH_HTPASSWD_PATH"] = "/auth/htpasswd" | ||||||||||||||
|
||||||||||||||
if req.Mounts == nil { | ||||||||||||||
req.Mounts = testcontainers.ContainerMounts{} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
htpasswdMount := testcontainers.ContainerMount{ | ||||||||||||||
Source: testcontainers.GenericBindMountSource{ | ||||||||||||||
HostPath: htpasswdPath, | ||||||||||||||
}, | ||||||||||||||
Target: "/auth", | ||||||||||||||
} | ||||||||||||||
req.Mounts = append(req.Mounts, htpasswdMount) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// 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 commentThe 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 @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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. @davidesalerno then I'd advocate for converting all the Mounts into Files 🙏 |
||||||||||||||
func WithData(dataDir string) testcontainers.CustomizeRequestOption { | ||||||||||||||
return func(req *testcontainers.GenericContainerRequest) { | ||||||||||||||
if req.Env == nil { | ||||||||||||||
req.Env = make(map[string]string) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
req.Env["REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY"] = "/data" | ||||||||||||||
|
||||||||||||||
if req.Mounts == nil { | ||||||||||||||
req.Mounts = testcontainers.ContainerMounts{} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
dataMount := testcontainers.ContainerMount{ | ||||||||||||||
Source: testcontainers.GenericBindMountSource{ | ||||||||||||||
HostPath: dataDir, | ||||||||||||||
}, | ||||||||||||||
Target: "/data", | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
req.Mounts = append(req.Mounts, dataMount) | ||||||||||||||
|
||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// WithImage customizer that will override the registry image used | ||||||||||||||
func WithImage(image string) testcontainers.CustomizeRequestOption { | ||||||||||||||
return func(req *testcontainers.GenericContainerRequest) { | ||||||||||||||
req.Image = image | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
Comment on lines
+91
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The core library already exposes a
Suggested change
|
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