Skip to content

Commit

Permalink
Merge branch 'main' into fix/issue-2755-idea
Browse files Browse the repository at this point in the history
  • Loading branch information
abhipranay authored Oct 23, 2024
2 parents 02d57ba + 7ca3d8e commit 3d5d881
Show file tree
Hide file tree
Showing 73 changed files with 155 additions and 153 deletions.
14 changes: 7 additions & 7 deletions container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func Test_BuildImageWithContexts(t *testing.T) {
}{
{
Name: "Dockerfile",
Contents: `FROM docker.io/alpine
Contents: `FROM alpine
CMD ["echo", "this is from the archive"]`,
},
}
Expand Down Expand Up @@ -216,7 +216,7 @@ func Test_BuildImageWithContexts(t *testing.T) {
},
{
Name: "Dockerfile",
Contents: `FROM docker.io/alpine
Contents: `FROM alpine
WORKDIR /app
COPY . .
CMD ["sh", "./say_hi.sh"]`,
Expand Down Expand Up @@ -365,7 +365,7 @@ func Test_GetLogsFromFailedContainer(t *testing.T) {
ctx := context.Background()
// directDockerHubReference {
req := testcontainers.ContainerRequest{
Image: "docker.io/alpine",
Image: "alpine",
Cmd: []string{"echo", "-n", "I was not expecting this"},
WaitingFor: wait.ForLog("I was expecting this").WithStartupTimeout(5 * time.Second),
}
Expand All @@ -392,11 +392,11 @@ func Test_GetLogsFromFailedContainer(t *testing.T) {
type dockerImageSubstitutor struct{}

func (s dockerImageSubstitutor) Description() string {
return "DockerImageSubstitutor (prepends docker.io)"
return "DockerImageSubstitutor (prepends registry.hub.docker.com)"
}

func (s dockerImageSubstitutor) Substitute(image string) (string, error) {
return "docker.io/" + image, nil
return "registry.hub.docker.com/library/" + image, nil
}

// }
Expand Down Expand Up @@ -455,7 +455,7 @@ func TestImageSubstitutors(t *testing.T) {
name: "Prepend namespace",
image: "alpine",
substitutors: []testcontainers.ImageSubstitutor{dockerImageSubstitutor{}},
expectedImage: "docker.io/alpine",
expectedImage: "registry.hub.docker.com/library/alpine",
},
{
name: "Substitution with error",
Expand Down Expand Up @@ -554,5 +554,5 @@ func ExampleGenericContainer_withSubstitutors() {

fmt.Println(dockerContainer.Image)

// Output: docker.io/alpine:latest
// Output: registry.hub.docker.com/library/alpine:latest
}
12 changes: 7 additions & 5 deletions docker_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/testcontainers/testcontainers-go/wait"
)

const testBashImage string = "bash:5.2.26"

func TestCopyFileToContainer(t *testing.T) {
ctx, cnl := context.WithTimeout(context.Background(), 30*time.Second)
defer cnl()
Expand All @@ -30,7 +32,7 @@ func TestCopyFileToContainer(t *testing.T) {

ctr, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "docker.io/bash",
Image: testBashImage,
Files: []testcontainers.ContainerFile{
{
Reader: r,
Expand Down Expand Up @@ -66,7 +68,7 @@ func TestCopyFileToRunningContainer(t *testing.T) {

ctr, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "docker.io/bash:5.2.26",
Image: testBashImage,
Files: []testcontainers.ContainerFile{
{
HostFilePath: waitForPath,
Expand Down Expand Up @@ -104,7 +106,7 @@ func TestCopyDirectoryToContainer(t *testing.T) {

ctr, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "docker.io/bash",
Image: testBashImage,
Files: []testcontainers.ContainerFile{
{
HostFilePath: dataDirectory,
Expand Down Expand Up @@ -141,7 +143,7 @@ func TestCopyDirectoryToRunningContainerAsFile(t *testing.T) {

ctr, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "docker.io/bash",
Image: testBashImage,
Files: []testcontainers.ContainerFile{
{
HostFilePath: waitForPath,
Expand Down Expand Up @@ -183,7 +185,7 @@ func TestCopyDirectoryToRunningContainerAsDir(t *testing.T) {

ctr, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "docker.io/bash",
Image: testBashImage,
Files: []testcontainers.ContainerFile{
{
HostFilePath: waitForPath,
Expand Down
42 changes: 21 additions & 21 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import (
)

const (
mysqlImage = "docker.io/mysql:8.0.36"
nginxDelayedImage = "docker.io/menedev/delayed-nginx:1.15.2"
nginxImage = "docker.io/nginx"
nginxAlpineImage = "docker.io/nginx:alpine"
mysqlImage = "mysql:8.0.36"
nginxDelayedImage = "menedev/delayed-nginx:1.15.2"
nginxImage = "nginx"
nginxAlpineImage = "nginx:alpine"
nginxDefaultPort = "80/tcp"
nginxHighPort = "8080/tcp"
daemonMaxVersion = "1.41"
Expand Down Expand Up @@ -804,8 +804,8 @@ func Test_BuildContainerFromDockerfileWithBuildLog(t *testing.T) {

temp := strings.Split(string(out), "\n")

if !regexp.MustCompile(`^Step\s*1/\d+\s*:\s*FROM docker.io/alpine$`).MatchString(temp[0]) {
t.Errorf("Expected stdout first line to be %s. Got '%s'.", "Step 1/* : FROM docker.io/alpine", temp[0])
if !regexp.MustCompile(`^Step\s*1/\d+\s*:\s*FROM alpine$`).MatchString(temp[0]) {
t.Errorf("Expected stdout first line to be %s. Got '%s'.", "Step 1/* : FROM alpine", temp[0])
}
}

Expand Down Expand Up @@ -878,7 +878,7 @@ func TestCMD(t *testing.T) {
ctx := context.Background()

req := ContainerRequest{
Image: "docker.io/alpine",
Image: "alpine",
WaitingFor: wait.ForAll(
wait.ForLog("command override!"),
),
Expand All @@ -904,7 +904,7 @@ func TestEntrypoint(t *testing.T) {
ctx := context.Background()

req := ContainerRequest{
Image: "docker.io/alpine",
Image: "alpine",
WaitingFor: wait.ForAll(
wait.ForLog("entrypoint override!"),
),
Expand All @@ -930,7 +930,7 @@ func TestWorkingDir(t *testing.T) {
ctx := context.Background()

req := ContainerRequest{
Image: "docker.io/alpine",
Image: "alpine",
WaitingFor: wait.ForAll(
wait.ForLog("/var/tmp/test"),
),
Expand All @@ -950,7 +950,7 @@ func TestWorkingDir(t *testing.T) {
func ExampleDockerProvider_CreateContainer() {
ctx := context.Background()
req := ContainerRequest{
Image: "docker.io/nginx:alpine",
Image: "nginx:alpine",
ExposedPorts: []string{"80/tcp"},
WaitingFor: wait.ForHTTP("/").WithStartupTimeout(10 * time.Second),
}
Expand Down Expand Up @@ -983,7 +983,7 @@ func ExampleDockerProvider_CreateContainer() {
func ExampleContainer_Host() {
ctx := context.Background()
req := ContainerRequest{
Image: "docker.io/nginx:alpine",
Image: "nginx:alpine",
ExposedPorts: []string{"80/tcp"},
WaitingFor: wait.ForHTTP("/").WithStartupTimeout(10 * time.Second),
}
Expand Down Expand Up @@ -1025,7 +1025,7 @@ func ExampleContainer_Host() {
func ExampleContainer_Start() {
ctx := context.Background()
req := ContainerRequest{
Image: "docker.io/nginx:alpine",
Image: "nginx:alpine",
ExposedPorts: []string{"80/tcp"},
WaitingFor: wait.ForHTTP("/").WithStartupTimeout(10 * time.Second),
}
Expand Down Expand Up @@ -1062,7 +1062,7 @@ func ExampleContainer_Start() {
func ExampleContainer_Stop() {
ctx := context.Background()
req := ContainerRequest{
Image: "docker.io/nginx:alpine",
Image: "nginx:alpine",
ExposedPorts: []string{"80/tcp"},
WaitingFor: wait.ForHTTP("/").WithStartupTimeout(10 * time.Second),
}
Expand Down Expand Up @@ -1096,7 +1096,7 @@ func ExampleContainer_Stop() {
func ExampleContainer_MappedPort() {
ctx := context.Background()
req := ContainerRequest{
Image: "docker.io/nginx:alpine",
Image: "nginx:alpine",
ExposedPorts: []string{"80/tcp"},
WaitingFor: wait.ForHTTP("/").WithStartupTimeout(10 * time.Second),
}
Expand Down Expand Up @@ -1147,7 +1147,7 @@ func TestContainerCreationWithVolumeAndFileWritingToIt(t *testing.T) {
bashC, err := GenericContainer(ctx, GenericContainerRequest{
ProviderType: providerType,
ContainerRequest: ContainerRequest{
Image: "docker.io/bash",
Image: "bash:5.2.26",
Files: []ContainerFile{
{
HostFilePath: absPath,
Expand All @@ -1167,7 +1167,7 @@ func TestContainerCreationWithVolumeAndFileWritingToIt(t *testing.T) {
func TestContainerWithTmpFs(t *testing.T) {
ctx := context.Background()
req := ContainerRequest{
Image: "docker.io/busybox",
Image: "busybox",
Cmd: []string{"sleep", "10"},
Tmpfs: map[string]string{"/testtmpfs": "rw"},
}
Expand Down Expand Up @@ -1242,7 +1242,7 @@ func TestContainerNonExistentImage(t *testing.T) {
c, err := GenericContainer(ctx, GenericContainerRequest{
ProviderType: providerType,
ContainerRequest: ContainerRequest{
Image: "docker.io/postgres:12",
Image: "postgres:12",
WaitingFor: wait.ForLog("log"),
},
Started: true,
Expand All @@ -1266,7 +1266,7 @@ func TestContainerCustomPlatformImage(t *testing.T) {
c, err := GenericContainer(ctx, GenericContainerRequest{
ProviderType: providerType,
ContainerRequest: ContainerRequest{
Image: "docker.io/redis:latest",
Image: "redis:latest",
ImagePlatform: nonExistentPlatform,
},
Started: false,
Expand All @@ -1282,7 +1282,7 @@ func TestContainerCustomPlatformImage(t *testing.T) {
c, err := GenericContainer(ctx, GenericContainerRequest{
ProviderType: providerType,
ContainerRequest: ContainerRequest{
Image: "docker.io/mysql:8.0.36",
Image: "mysql:8.0.36",
ImagePlatform: "linux/amd64",
},
Started: false,
Expand Down Expand Up @@ -1817,7 +1817,7 @@ func TestContainerRunningCheckingStatusCode(t *testing.T) {
func TestContainerWithUserID(t *testing.T) {
ctx := context.Background()
req := ContainerRequest{
Image: "docker.io/alpine:latest",
Image: "alpine:latest",
User: "60125",
Cmd: []string{"sh", "-c", "id -u"},
WaitingFor: wait.ForExit(),
Expand Down Expand Up @@ -1846,7 +1846,7 @@ func TestContainerWithUserID(t *testing.T) {
func TestContainerWithNoUserID(t *testing.T) {
ctx := context.Background()
req := ContainerRequest{
Image: "docker.io/alpine:latest",
Image: "alpine:latest",
Cmd: []string{"sh", "-c", "id -u"},
WaitingFor: wait.ForExit(),
}
Expand Down
4 changes: 2 additions & 2 deletions docs/features/image_name_substitution.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ _Testcontainers for Go_ will automatically apply the prefix to every image that
_Testcontainers for Go_ will not apply the prefix to:

* non-Hub image names (e.g. where another registry is set)
* Docker Hub image names where the hub registry is explicitly part of the name (i.e. anything with a `docker.io` or `registry.hub.docker.com` host part)
* Docker Hub image names where the hub registry is explicitly part of the name (i.e. anything with a `registry.hub.docker.com` host part)

## Developing a custom function for transforming image names on the fly

Expand All @@ -68,7 +68,7 @@ You can implement a custom image name substitutor by:
* implementing the `ImageNameSubstitutor` interface, exposed by the `testcontainers` package.
* configuring _Testcontainers for Go_ to use your custom implementation, defined at the `ContainerRequest` level.

The following is an example image substitutor implementation prepending the `docker.io/` prefix, used in the tests:
The following is an example image substitutor implementation prepending the `registry.hub.docker.com/library/` prefix, used in the tests:

<!--codeinclude-->
[Image Substitutor Interface](../../options.go) inside_block:imageSubstitutor
Expand Down
2 changes: 1 addition & 1 deletion docs/features/wait/exit.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The exit wait strategy will check that the container is not in the running state

```golang
req := ContainerRequest{
Image: "docker.io/alpine:latest",
Image: "alpine:latest",
WaitingFor: wait.ForExit(),
}
```
2 changes: 1 addition & 1 deletion docs/features/wait/health.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The health wait strategy will check that the container is in the healthy state a

```golang
req := ContainerRequest{
Image: "docker.io/alpine:latest",
Image: "alpine:latest",
WaitingFor: wait.ForHealthCheck(),
}
```
8 changes: 4 additions & 4 deletions docs/features/wait/host_port.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Variations on the HostPort wait strategy are supported, including:

```golang
req := ContainerRequest{
Image: "docker.io/nginx:alpine",
Image: "nginx:alpine",
ExposedPorts: []string{"80/tcp"},
WaitingFor: wait.ForListeningPort("80/tcp"),
}
Expand All @@ -26,7 +26,7 @@ The wait strategy will use the lowest exposed port from the container configurat

```golang
req := ContainerRequest{
Image: "docker.io/nginx:alpine",
Image: "nginx:alpine",
WaitingFor: wait.ForExposedPort(),
}
```
Expand All @@ -35,7 +35,7 @@ Said that, it could be the case that the container request included ports to be

```golang
req := ContainerRequest{
Image: "docker.io/nginx:alpine",
Image: "nginx:alpine",
ExposedPorts: []string{"80/tcp", "9080/tcp"},
WaitingFor: wait.ForExposedPort(),
}
Expand All @@ -55,7 +55,7 @@ In this case, the `wait.ForExposedPort.SkipInternalCheck` can be used to skip th

```golang
req := ContainerRequest{
Image: "docker.io/nginx:alpine",
Image: "nginx:alpine",
ExposedPorts: []string{"80/tcp", "9080/tcp"},
WaitingFor: wait.ForExposedPort().SkipInternalCheck(),
}
Expand Down
4 changes: 2 additions & 2 deletions docs/features/wait/log.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The Log wait strategy will check if a string occurs in the container logs for a

```golang
req := ContainerRequest{
Image: "docker.io/mysql:8.0.36",
Image: "mysql:8.0.36",
ExposedPorts: []string{"3306/tcp", "33060/tcp"},
Env: map[string]string{
"MYSQL_ROOT_PASSWORD": "password",
Expand All @@ -24,7 +24,7 @@ Using a regular expression:

```golang
req := ContainerRequest{
Image: "docker.io/mysql:8.0.36",
Image: "mysql:8.0.36",
ExposedPorts: []string{"3306/tcp", "33060/tcp"},
Env: map[string]string{
"MYSQL_ROOT_PASSWORD": "password",
Expand Down
2 changes: 1 addition & 1 deletion docs/features/wait/multi.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Available Options:

```golang
req := ContainerRequest{
Image: "docker.io/mysql:8.0.36",
Image: "mysql:8.0.36",
ExposedPorts: []string{"3306/tcp", "33060/tcp"},
Env: map[string]string{
"MYSQL_ROOT_PASSWORD": "password",
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/artemis.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ When starting the Artemis container, you can pass options in a variadic way to c
#### Image

If you need to set a different Artemis Docker image, you can set a valid Docker image as the second argument in the `Run` function.
E.g. `Run(context.Background(), "docker.io/apache/activemq-artemis:2.30.0")`.
E.g. `Run(context.Background(), "apache/activemq-artemis:2.30.0")`.

{% include "../features/common_functional_options.md" %}

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/consul.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ When starting the Consul container, you can pass options in a variadic way to co
#### Image

If you need to set a different Consul Docker image, you can set a valid Docker image as the second argument in the `Run` function.
E.g. `Run(context.Background(), "docker.io/hashicorp/consul:1.15")`.
E.g. `Run(context.Background(), "hashicorp/consul:1.15")`.

{% include "../features/common_functional_options.md" %}

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/couchbase.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ When starting the Couchbase container, you can pass options in a variadic way to
#### Image

If you need to set a different Couchbase Docker image, you can set a valid Docker image as the second argument in the `Run` function.
E.g. `Run(context.Background(), "docker.io/couchbase:6.5.1")`.
E.g. `Run(context.Background(), "couchbase:6.5.1")`.

You can find the Docker images that are currently tested in this module, for the Enterprise and Community editions, in the following list:

Expand Down
Loading

0 comments on commit 3d5d881

Please sign in to comment.