Skip to content

Commit

Permalink
Add default labels when Ryuk is disabled (testcontainers#1339)
Browse files Browse the repository at this point in the history
* Add org.testcontainers label

For consistency with the other Testcontainers lang implementations,
label `org.testcontainers=true` should be added.

* Add default labels when ryuk is disabled

* Remove default labels from reaper as they would be added later

* Fix test

* Fix lint

* Do not use map reference

* Update internal/testcontainersdocker/labels.go

Co-authored-by: Manuel de la Peña <mdelapenya@gmail.com>

* Update docker.go

Co-authored-by: Manuel de la Peña <mdelapenya@gmail.com>

---------

Co-authored-by: Manuel de la Peña <mdelapenya@gmail.com>
  • Loading branch information
eddumelendez and mdelapenya committed Aug 9, 2023
1 parent c82a1c5 commit b908ddc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
4 changes: 4 additions & 0 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,10 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque
}
}

for k, v := range testcontainersdocker.DefaultLabels() {
req.Labels[k] = v
}

dockerInput := &container.Config{
Entrypoint: req.Entrypoint,
Image: tag,
Expand Down
10 changes: 10 additions & 0 deletions internal/testcontainersdocker/labels.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package testcontainersdocker

import "github.com/testcontainers/testcontainers-go/internal"

const (
LabelBase = "org.testcontainers"
LabelLang = LabelBase + ".lang"
LabelReaper = LabelBase + ".reaper"
LabelSessionID = LabelBase + ".sessionId"
LabelVersion = LabelBase + ".version"
)

func DefaultLabels() map[string]string {
return map[string]string{
LabelBase: "true",
LabelLang: "go",
LabelVersion: internal.Version,
}
}
3 changes: 0 additions & 3 deletions reaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/docker/docker/api/types/container"
"github.com/docker/go-connections/nat"
"github.com/testcontainers/testcontainers-go/internal"
"github.com/testcontainers/testcontainers-go/internal/testcontainersdocker"
"github.com/testcontainers/testcontainers-go/wait"
)
Expand Down Expand Up @@ -198,8 +197,6 @@ func (r *Reaper) Labels() map[string]string {
return map[string]string{
TestcontainerLabel: "true",
TestcontainerLabelSessionID: r.SessionID,
testcontainersdocker.LabelLang: "go",
testcontainersdocker.LabelVersion: internal.Version,
testcontainersdocker.LabelSessionID: r.SessionID,
}
}
Expand Down
9 changes: 3 additions & 6 deletions reaper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/docker/docker/api/types/network"
"github.com/docker/go-connections/nat"
"github.com/stretchr/testify/assert"
"github.com/testcontainers/testcontainers-go/internal"
"github.com/testcontainers/testcontainers-go/internal/config"
"github.com/testcontainers/testcontainers-go/internal/testcontainersdocker"
"github.com/testcontainers/testcontainers-go/wait"
Expand Down Expand Up @@ -55,11 +54,9 @@ func createContainerRequest(customize func(ContainerRequest) ContainerRequest) C
ReaperImage: "reaperImage",
ExposedPorts: []string{"8080/tcp"},
Labels: map[string]string{
TestcontainerLabel: "true",
TestcontainerLabelIsReaper: "true",
testcontainersdocker.LabelReaper: "true",
testcontainersdocker.LabelLang: "go",
testcontainersdocker.LabelVersion: internal.Version,
TestcontainerLabel: "true",
TestcontainerLabelIsReaper: "true",
testcontainersdocker.LabelReaper: "true",
},
Mounts: Mounts(BindMount(testcontainersdocker.ExtractDockerSocket(context.Background()), "/var/run/docker.sock")),
WaitingFor: wait.ForListeningPort(nat.Port("8080/tcp")),
Expand Down

0 comments on commit b908ddc

Please sign in to comment.