Skip to content

Commit 2934feb

Browse files
committed
Merge branch 'main' into fix/multiplexed_exec_output
* main: bug:Fix AMQPS url (testcontainers#2462) chore: more compose updates in comments chore: use "docker compose" (v2) instead of "docker-compose" (v1) (testcontainers#2464) chore(deps): bump github/codeql-action from 2.22.12 to 3.24.9 (testcontainers#2459)
2 parents 29d3fa8 + 2d89e90 commit 2934feb

File tree

10 files changed

+105
-28
lines changed

10 files changed

+105
-28
lines changed

.github/workflows/codeql.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353

5454
# Initializes the CodeQL tools for scanning.
5555
- name: Initialize CodeQL
56-
uses: github/codeql-action/init@e5f05b81d5b6ff8cfa111c80c22c5fd02a384118 # v3.23.0
56+
uses: github/codeql-action/init@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9
5757
with:
5858
languages: ${{ matrix.language }}
5959
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -67,7 +67,7 @@ jobs:
6767
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
6868
# If this step fails, then you should remove it and run the build manually (see below)
6969
- name: Autobuild
70-
uses: github/codeql-action/autobuild@e5f05b81d5b6ff8cfa111c80c22c5fd02a384118 # v3.23.0
70+
uses: github/codeql-action/autobuild@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9
7171

7272
# ℹ️ Command-line programs to run using the OS shell.
7373
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -80,6 +80,6 @@ jobs:
8080
# ./location_of_script_within_repo/buildscript.sh
8181

8282
- name: Perform CodeQL Analysis
83-
uses: github/codeql-action/analyze@e5f05b81d5b6ff8cfa111c80c22c5fd02a384118 # v3.23.0
83+
uses: github/codeql-action/analyze@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9
8484
with:
8585
category: "/language:${{matrix.language}}"

.github/workflows/scorecards.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ jobs:
5151

5252
# required for Code scanning alerts
5353
- name: "Upload SARIF results to code scanning"
54-
uses: github/codeql-action/upload-sarif@1500a131381b66de0c52ac28abb13cd79f4b7ecc # v2.22.12
54+
uses: github/codeql-action/upload-sarif@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9
5555
with:
5656
sarif_file: results.sarif

docker_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,7 @@ func TestContainerWithNoUserID(t *testing.T) {
18541854
}
18551855

18561856
func TestGetGatewayIP(t *testing.T) {
1857-
// When using docker-compose with DinD mode, and using host port or http wait strategy
1857+
// When using docker compose with DinD mode, and using host port or http wait strategy
18581858
// It's need to invoke GetGatewayIP for get the host
18591859
provider, err := providerType.GetProvider(WithLogger(TestLogger(t)))
18601860
if err != nil {

docs/features/docker_compose.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This is intended to be useful on projects where Docker Compose is already used
77
in dev or other environments to define services that an application may be
88
dependent upon.
99

10-
## Using `docker-compose` directly
10+
## Using `docker compose` directly
1111

1212
!!!warning
1313
The minimal version of Go required to use this module is **1.21**.
@@ -16,9 +16,9 @@ dependent upon.
1616
go get github.com/testcontainers/testcontainers-go/modules/compose
1717
```
1818

19-
Because `docker-compose` v2 is implemented in Go it's possible for _Testcontainers for Go_ to
19+
Because `compose` v2 is implemented in Go it's possible for _Testcontainers for Go_ to
2020
use [`github.com/docker/compose`](https://github.com/docker/compose) directly and skip any process execution/_docker-compose-in-a-container_ scenario.
21-
The `ComposeStack` API exposes this variant of using `docker-compose` in an easy way.
21+
The `ComposeStack` API exposes this variant of using `docker compose` in an easy way.
2222

2323
### Basic examples
2424

@@ -88,14 +88,14 @@ func TestSomethingElse(t *testing.T) {
8888

8989
To interact with service containers after a stack was started it is possible to get an `*tc.DockerContainer` instance via the `ServiceContainer(...)` function.
9090
The function takes a **service name** (and a `context.Context`) and returns either a `*tc.DockerContainer` or an `error`.
91-
This is different to the previous `LocalDockerCompose` API where service containers were accessed via their **container name** e.g. `mysql_1` or `mysql-1` (depending on the version of `docker-compose`).
91+
This is different to the previous `LocalDockerCompose` API where service containers were accessed via their **container name** e.g. `mysql_1` or `mysql-1` (depending on the version of `docker compose`).
9292

9393
Furthermore, there's the convenience function `Serices()` to get a list of all services **defined** by the current project.
9494
Note that not all of them need necessarily be correctly started as the information is based on the given compose files.
9595

9696
### Wait strategies
9797

98-
Just like with regular test containers you can also apply wait strategies to `docker-compose` services.
98+
Just like with regular test containers you can also apply wait strategies to `docker compose` services.
9999
The `ComposeStack.WaitForService(...)` function allows you to apply a wait strategy to **a service by name**.
100100
All wait strategies are executed in parallel to both improve startup performance by not blocking too long and to fail
101101
early if something's wrong.
@@ -139,7 +139,7 @@ func TestSomethingWithWaiting(t *testing.T) {
139139

140140
### Compose environment
141141

142-
`docker-compose` supports expansion based on environment variables.
142+
`docker compose` supports expansion based on environment variables.
143143
The `ComposeStack` supports this as well in two different variants:
144144

145145
- `ComposeStack.WithEnv(m map[string]string) ComposeStack` to parameterize stacks from your test code
@@ -150,14 +150,14 @@ The `ComposeStack` supports this as well in two different variants:
150150
Also have a look at [ComposeStack](https://pkg.go.dev/github.com/testcontainers/testcontainers-go#ComposeStack) docs for
151151
further information.
152152

153-
## Usage of `docker-compose` binary
153+
## Usage of the `docker compose` binary
154154

155-
_Node:_ this API is deprecated and superseded by `ComposeStack` which takes advantage of `docker-compose` v2 being
155+
_Node:_ this API is deprecated and superseded by `ComposeStack` which takes advantage of `compose` v2 being
156156
implemented in Go as well by directly using the upstream project.
157157

158158
You can override Testcontainers' default behaviour and make it use a
159-
docker-compose binary installed on the local machine. This will generally yield
160-
an experience that is closer to running docker-compose locally, with the caveat
159+
docker compose binary installed on the local machine. This will generally yield
160+
an experience that is closer to running docker compose locally, with the caveat
161161
that Docker Compose needs to be present on dev and CI machines.
162162

163163
### Examples

modules/compose/compose.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,12 @@ func NewLocalDockerCompose(filePaths []string, identifier string, opts ...LocalD
155155
opts[idx].ApplyToLocalCompose(dc.LocalDockerComposeOptions)
156156
}
157157

158-
dc.Executable = "docker-compose"
158+
dc.Executable = "docker"
159159
if runtime.GOOS == "windows" {
160-
dc.Executable = "docker-compose.exe"
160+
dc.Executable = "docker.exe"
161161
}
162162

163+
dc.composeSubcommand = "compose"
163164
dc.ComposeFilePaths = filePaths
164165

165166
dc.absComposeFilePaths = make([]string, len(filePaths))

modules/compose/compose_api.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (f stackDownOptionFunc) applyToStackDown(do *api.DownOptions) {
3434
f(do)
3535
}
3636

37-
// RunServices is comparable to 'docker-compose run' as it only creates a subset of containers
37+
// RunServices is comparable to 'docker compose run' as it only creates a subset of containers
3838
// instead of all services defined by the project
3939
func RunServices(serviceNames ...string) StackUpOption {
4040
return stackUpOptionFunc(func(o *stackUpOptions) {
@@ -231,7 +231,6 @@ func (d *dockerCompose) Up(ctx context.Context, opts ...StackUpOption) error {
231231
Wait: upOptions.Wait,
232232
},
233233
})
234-
235234
if err != nil {
236235
return err
237236
}

modules/compose/compose_local.go

+27-7
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ func (c composeVersion2) Format(parts ...string) string {
4141
return strings.Join(parts, "-")
4242
}
4343

44+
// Deprecated: use ComposeStack instead
4445
// LocalDockerCompose represents a Docker Compose execution using local binary
45-
// docker-compose or docker-compose.exe, depending on the underlying platform
46+
// docker compose or docker.exe compose, depending on the underlying platform
4647
type LocalDockerCompose struct {
4748
ComposeVersion
4849
*LocalDockerComposeOptions
4950
Executable string
51+
composeSubcommand string
5052
ComposeFilePaths []string
5153
absComposeFilePaths []string
5254
Identifier string
@@ -58,17 +60,20 @@ type LocalDockerCompose struct {
5860
}
5961

6062
type (
63+
// Deprecated: it will be removed in the next major release
6164
// LocalDockerComposeOptions defines options applicable to LocalDockerCompose
6265
LocalDockerComposeOptions struct {
6366
Logger testcontainers.Logging
6467
}
6568

69+
// Deprecated: it will be removed in the next major release
6670
// LocalDockerComposeOption defines a common interface to modify LocalDockerComposeOptions
6771
// These options can be passed to NewLocalDockerCompose in a variadic way to customize the returned LocalDockerCompose instance
6872
LocalDockerComposeOption interface {
6973
ApplyToLocalCompose(opts *LocalDockerComposeOptions)
7074
}
7175

76+
// Deprecated: it will be removed in the next major release
7277
// LocalDockerComposeOptionsFunc is a shorthand to implement the LocalDockerComposeOption interface
7378
LocalDockerComposeOptionsFunc func(opts *LocalDockerComposeOptions)
7479
)
@@ -86,6 +91,7 @@ func WithLogger(logger testcontainers.Logging) ComposeLoggerOption {
8691
}
8792
}
8893

94+
// Deprecated: it will be removed in the next major release
8995
func (o ComposeLoggerOption) ApplyToLocalCompose(opts *LocalDockerComposeOptions) {
9096
opts.Logger = o.logger
9197
}
@@ -94,15 +100,18 @@ func (o ComposeLoggerOption) applyToComposeStack(opts *composeStackOptions) {
94100
opts.Logger = o.logger
95101
}
96102

103+
// Deprecated: it will be removed in the next major release
97104
func (f LocalDockerComposeOptionsFunc) ApplyToLocalCompose(opts *LocalDockerComposeOptions) {
98105
f(opts)
99106
}
100107

101-
// Down executes docker-compose down
108+
// Deprecated: it will be removed in the next major release
109+
// Down executes docker compose down
102110
func (dc *LocalDockerCompose) Down() ExecError {
103111
return executeCompose(dc, []string{"down", "--remove-orphans", "--volumes"})
104112
}
105113

114+
// Deprecated: it will be removed in the next major release
106115
func (dc *LocalDockerCompose) getDockerComposeEnvironment() map[string]string {
107116
environment := map[string]string{}
108117

@@ -117,10 +126,12 @@ func (dc *LocalDockerCompose) getDockerComposeEnvironment() map[string]string {
117126
return environment
118127
}
119128

129+
// Deprecated: it will be removed in the next major release
120130
func (dc *LocalDockerCompose) containerNameFromServiceName(service, separator string) string {
121131
return dc.Identifier + separator + service
122132
}
123133

134+
// Deprecated: it will be removed in the next major release
124135
func (dc *LocalDockerCompose) applyStrategyToRunningContainer() error {
125136
cli, err := testcontainers.NewDockerClientWithOpts(context.Background())
126137
if err != nil {
@@ -163,36 +174,41 @@ func (dc *LocalDockerCompose) applyStrategyToRunningContainer() error {
163174

164175
err = strategy.WaitUntilReady(context.Background(), dockercontainer)
165176
if err != nil {
166-
return fmt.Errorf("Unable to apply wait strategy %v to service %s due to %w", strategy, k.service, err)
177+
return fmt.Errorf("unable to apply wait strategy %v to service %s due to %w", strategy, k.service, err)
167178
}
168179
}
169180
return nil
170181
}
171182

183+
// Deprecated: it will be removed in the next major release
172184
// Invoke invokes the docker compose
173185
func (dc *LocalDockerCompose) Invoke() ExecError {
174186
return executeCompose(dc, dc.Cmd)
175187
}
176188

189+
// Deprecated: it will be removed in the next major release
177190
// WaitForService sets the strategy for the service that is to be waited on
178191
func (dc *LocalDockerCompose) WaitForService(service string, strategy wait.Strategy) DockerCompose {
179192
dc.waitStrategySupplied = true
180193
dc.WaitStrategyMap[waitService{service: service}] = strategy
181194
return dc
182195
}
183196

197+
// Deprecated: it will be removed in the next major release
184198
// WithCommand assigns the command
185199
func (dc *LocalDockerCompose) WithCommand(cmd []string) DockerCompose {
186200
dc.Cmd = cmd
187201
return dc
188202
}
189203

204+
// Deprecated: it will be removed in the next major release
190205
// WithEnv assigns the environment
191206
func (dc *LocalDockerCompose) WithEnv(env map[string]string) DockerCompose {
192207
dc.Env = env
193208
return dc
194209
}
195210

211+
// Deprecated: it will be removed in the next major release
196212
// WithExposedService sets the strategy for the service that is to be waited on. If multiple strategies
197213
// are given for a single service running on different ports, both strategies will be applied on the same container
198214
func (dc *LocalDockerCompose) WithExposedService(service string, port int, strategy wait.Strategy) DockerCompose {
@@ -201,7 +217,8 @@ func (dc *LocalDockerCompose) WithExposedService(service string, port int, strat
201217
return dc
202218
}
203219

204-
// determineVersion checks which version of docker-compose is installed
220+
// Deprecated: it will be removed in the next major release
221+
// determineVersion checks which version of docker compose is installed
205222
// depending on the version services names are composed in a different way
206223
func (dc *LocalDockerCompose) determineVersion() error {
207224
execErr := executeCompose(dc, []string{"version", "--short"})
@@ -232,6 +249,7 @@ func (dc *LocalDockerCompose) determineVersion() error {
232249
return nil
233250
}
234251

252+
// Deprecated: it will be removed in the next major release
235253
// validate checks if the files to be run in the compose are valid YAML files, setting up
236254
// references to all services in them
237255
func (dc *LocalDockerCompose) validate() error {
@@ -336,11 +354,12 @@ func execute(
336354
}
337355
}
338356

357+
// Deprecated: it will be removed in the next major release
339358
func executeCompose(dc *LocalDockerCompose, args []string) ExecError {
340359
if which(dc.Executable) != nil {
341360
return ExecError{
342361
Command: []string{dc.Executable},
343-
Error: fmt.Errorf("Local Docker Compose not found. Is %s on the PATH?", dc.Executable),
362+
Error: fmt.Errorf("Local Docker not found. Is %s on the PATH?", dc.Executable),
344363
}
345364
}
346365

@@ -349,7 +368,8 @@ func executeCompose(dc *LocalDockerCompose, args []string) ExecError {
349368
environment[k] = v
350369
}
351370

352-
var cmds []string
371+
// initialise the command with the compose subcommand
372+
cmds := []string{dc.composeSubcommand}
353373
pwd := "."
354374
if len(dc.absComposeFilePaths) > 0 {
355375
pwd, _ = filepath.Split(dc.absComposeFilePaths[0])
@@ -367,7 +387,7 @@ func executeCompose(dc *LocalDockerCompose, args []string) ExecError {
367387
if err != nil {
368388
args := strings.Join(dc.Cmd, " ")
369389
return ExecError{
370-
Command: []string{dc.Executable},
390+
Command: []string{dc.Executable, args},
371391
Error: fmt.Errorf("Local Docker compose exited abnormally whilst running %s: [%v]. %s", dc.Executable, args, err.Error()),
372392
}
373393
}

modules/compose/compose_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func ExampleNewLocalDockerCompose() {
3333

3434
func ExampleLocalDockerCompose() {
3535
_ = LocalDockerCompose{
36-
Executable: "docker-compose",
36+
Executable: "docker compose",
3737
ComposeFilePaths: []string{
3838
"/path/to/docker-compose.yml",
3939
"/path/to/docker-compose-1.yml",

modules/rabbitmq/rabbitmq.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (c *RabbitMQContainer) AmqpURL(ctx context.Context) (string, error) {
4848

4949
// AmqpURL returns the URL for AMQPS clients.
5050
func (c *RabbitMQContainer) AmqpsURL(ctx context.Context) (string, error) {
51-
endpoint, err := c.PortEndpoint(ctx, nat.Port(DefaultAMQPPort), "")
51+
endpoint, err := c.PortEndpoint(ctx, nat.Port(DefaultAMQPSPort), "")
5252
if err != nil {
5353
return "", err
5454
}

0 commit comments

Comments
 (0)