Skip to content

Commit d2e04c9

Browse files
Don't PublishAllPorts AND specify the same IP bindings, else we get "address already in use" reliably on docker v28 (#776)
* Update docker client v26.1.5 -> v28.1.1 * Set a deterministic network interface name, and ensure we're the default gateway These options were introduced in v28. They are ignored by older Docker client versions. * Update go from `1.22` -> `1.23` This was required as of moby v28: moby/moby#49541 * Update types to new names/locations for docker v28 * Downgrade docker to work with more installations: * Reapply v28.0.4 since we need priority? * Remove needless config; this will break homerunner * Include alias again for fed tests --------- Co-authored-by: Kegan Dougal <[email protected]>
1 parent 55095cf commit d2e04c9

File tree

5 files changed

+27
-32
lines changed

5 files changed

+27
-32
lines changed

cmd/perftest/snapshot.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"encoding/json"
66
"time"
77

8-
"github.com/docker/docker/api/types"
8+
"github.com/docker/docker/api/types/container"
99
"github.com/matrix-org/complement/internal/docker"
1010
)
1111

@@ -30,7 +30,7 @@ func snapshotStats(spanName, desc string, deployment *docker.Deployment, absDura
3030
if err != nil {
3131
return nil
3232
}
33-
var sj types.StatsJSON
33+
var sj container.StatsResponse
3434
err = json.NewDecoder(stats.Body).Decode(&sj)
3535
stats.Body.Close()
3636
if err != nil {

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module github.com/matrix-org/complement
22

3-
go 1.22
3+
go 1.23
44

5-
toolchain go1.22.1
5+
toolchain go1.23.9
66

77
require (
8-
github.com/docker/docker v26.1.5+incompatible
8+
github.com/docker/docker v28.0.4+incompatible
99
github.com/docker/go-connections v0.4.0
1010
github.com/gorilla/mux v1.8.0
1111
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
@@ -36,6 +36,7 @@ require (
3636
github.com/gogo/protobuf v1.3.2 // indirect
3737
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
3838
github.com/moby/docker-image-spec v1.3.1 // indirect
39+
github.com/moby/sys/atomicwriter v0.1.0 // indirect
3940
github.com/moby/term v0.0.0-20210610120745-9d4ed1856297 // indirect
4041
github.com/morikuni/aec v1.0.0 // indirect
4142
github.com/opencontainers/go-digest v1.0.0 // indirect

go.sum

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
2222
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2323
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
2424
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
25-
github.com/docker/docker v26.1.5+incompatible h1:NEAxTwEjxV6VbBMBoGG3zPqbiJosIApZjxlbrG9q3/g=
26-
github.com/docker/docker v26.1.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
25+
github.com/docker/docker v27.5.1+incompatible h1:4PYU5dnBYqRQi0294d1FBECqT9ECWeQAIfE8q4YnPY8=
26+
github.com/docker/docker v27.5.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
27+
github.com/docker/docker v28.0.4+incompatible h1:JNNkBctYKurkw6FrHfKqY0nKIDf5nrbxjVBtS+cdcok=
28+
github.com/docker/docker v28.0.4+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
29+
github.com/docker/docker v28.1.1+incompatible h1:49M11BFLsVO1gxY9UX9p/zwkE/rswggs8AdFmXQw51I=
30+
github.com/docker/docker v28.1.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
2731
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
2832
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
2933
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
@@ -77,6 +81,10 @@ github.com/miekg/dns v1.1.50 h1:DQUfb9uc6smULcREF09Uc+/Gd46YWqJd5DbpPE9xkcA=
7781
github.com/miekg/dns v1.1.50/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME=
7882
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
7983
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
84+
github.com/moby/sys/atomicwriter v0.1.0 h1:kw5D/EqkBwsBFi0ss9v1VG3wIkVhzGvLklJ+w3A14Sw=
85+
github.com/moby/sys/atomicwriter v0.1.0/go.mod h1:Ul8oqv2ZMNHOceF643P6FKPXeCmYtlQMvpizfsSoaWs=
86+
github.com/moby/sys/sequential v0.6.0 h1:qrx7XFUd/5DxtqcoH1h438hF5TmOvzC/lspjy7zgvCU=
87+
github.com/moby/sys/sequential v0.6.0/go.mod h1:uyv8EUTrca5PnDsdMGXhZe6CCe8U/UiTWd+lL+7b/Ko=
8088
github.com/moby/term v0.0.0-20210610120745-9d4ed1856297 h1:yH0SvLzcbZxcJXho2yh7CqdENGMQe73Cw3woZBpPli0=
8189
github.com/moby/term v0.0.0-20210610120745-9d4ed1856297/go.mod h1:vgPCkQMyxTZ7IDy8SXRufE172gr8+K/JE/7hHFxHW3A=
8290
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=

internal/docker/builder.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import (
2020
"strings"
2121
"time"
2222

23-
"github.com/docker/docker/api/types"
2423
"github.com/docker/docker/api/types/container"
2524
"github.com/docker/docker/api/types/image"
25+
"github.com/docker/docker/api/types/network"
2626
"github.com/docker/docker/client"
2727
"github.com/docker/docker/pkg/stdcopy"
2828
"github.com/docker/go-connections/nat"
@@ -81,7 +81,7 @@ func (d *Builder) Cleanup() {
8181

8282
// removeImages removes all images with `complementLabel`.
8383
func (d *Builder) removeNetworks() error {
84-
networks, err := d.Docker.NetworkList(context.Background(), types.NetworkListOptions{
84+
networks, err := d.Docker.NetworkList(context.Background(), network.ListOptions{
8585
Filters: label(
8686
complementLabel,
8787
"complement_pkg="+d.Config.PackageNamespace,
@@ -438,7 +438,7 @@ func generateASRegistrationYaml(as b.ApplicationService) string {
438438
// Name is guaranteed not to be empty when err == nil
439439
func createNetworkIfNotExists(docker *client.Client, pkgNamespace, blueprintName string) (networkName string, err error) {
440440
// check if a network already exists for this blueprint
441-
nws, err := docker.NetworkList(context.Background(), types.NetworkListOptions{
441+
nws, err := docker.NetworkList(context.Background(), network.ListOptions{
442442
Filters: label(
443443
"complement_pkg="+pkgNamespace,
444444
"complement_blueprint="+blueprintName,
@@ -456,7 +456,7 @@ func createNetworkIfNotExists(docker *client.Client, pkgNamespace, blueprintName
456456
}
457457
networkName = "complement_" + pkgNamespace + "_" + blueprintName
458458
// make a user-defined network so we get DNS based on the container name
459-
nw, err := docker.NetworkCreate(context.Background(), networkName, types.NetworkCreate{
459+
nw, err := docker.NetworkCreate(context.Background(), networkName, network.CreateOptions{
460460
Labels: map[string]string{
461461
complementLabel: blueprintName,
462462
"complement_blueprint": blueprintName,

internal/docker/deployer.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ import (
3131
"time"
3232

3333
"github.com/docker/docker/client"
34-
"github.com/docker/go-connections/nat"
3534
complementRuntime "github.com/matrix-org/complement/runtime"
3635

37-
"github.com/docker/docker/api/types"
3836
"github.com/docker/docker/api/types/container"
3937
"github.com/docker/docker/api/types/image"
4038
"github.com/docker/docker/api/types/mount"
@@ -382,20 +380,8 @@ func deployImage(
382380
}, &container.HostConfig{
383381
CapAdd: []string{"NET_ADMIN"}, // TODO : this should be some sort of option
384382
PublishAllPorts: true,
385-
PortBindings: nat.PortMap{
386-
nat.Port("8008/tcp"): []nat.PortBinding{
387-
{
388-
HostIP: cfg.HSPortBindingIP,
389-
},
390-
},
391-
nat.Port("8448/tcp"): []nat.PortBinding{
392-
{
393-
HostIP: cfg.HSPortBindingIP,
394-
},
395-
},
396-
},
397-
ExtraHosts: extraHosts,
398-
Mounts: mounts,
383+
ExtraHosts: extraHosts,
384+
Mounts: mounts,
399385
}, &network.NetworkingConfig{
400386
EndpointsConfig: map[string]*network.EndpointSettings{
401387
networkName: {
@@ -404,7 +390,7 @@ func deployImage(
404390
},
405391
}, nil, containerName)
406392
if err != nil {
407-
return nil, err
393+
return nil, fmt.Errorf("ContainerCreate: %s", err)
408394
}
409395
for _, w := range body.Warnings {
410396
log.Printf("WARN: ContainerCreate: %s", w)
@@ -446,7 +432,7 @@ func deployImage(
446432

447433
err = docker.ContainerStart(ctx, containerID, container.StartOptions{})
448434
if err != nil {
449-
return stubDeployment, err
435+
return stubDeployment, fmt.Errorf("ContainerStart: %s", err)
450436
}
451437
if cfg.DebugLoggingEnabled {
452438
log.Printf("%s: Started container %s", contextStr, containerID)
@@ -458,7 +444,7 @@ func deployImage(
458444
}
459445
inspect, err := docker.ContainerInspect(ctx, containerID)
460446
if err != nil {
461-
return stubDeployment, err
447+
return stubDeployment, fmt.Errorf("ContainerInspect: %s", err)
462448
}
463449
for vol := range inspect.Config.Volumes {
464450
log.Printf(
@@ -506,7 +492,7 @@ func copyToContainer(docker *client.Client, containerID, path string, data []byt
506492
tw.Close()
507493

508494
// Put our new fake file in the container volume
509-
err = docker.CopyToContainer(context.Background(), containerID, "/", &buf, types.CopyToContainerOptions{
495+
err = docker.CopyToContainer(context.Background(), containerID, "/", &buf, container.CopyToContainerOptions{
510496
AllowOverwriteDirWithFile: false,
511497
})
512498
if err != nil {
@@ -518,7 +504,7 @@ func copyToContainer(docker *client.Client, containerID, path string, data []byt
518504
// Waits until a homeserver container has NAT ports assigned and returns its clientside API URL and federation API URL.
519505
func waitForPorts(ctx context.Context, docker *client.Client, containerID string) (baseURL string, fedBaseURL string, err error) {
520506
// We need to hammer the inspect endpoint until the ports show up, they don't appear immediately.
521-
var inspect types.ContainerJSON
507+
var inspect container.InspectResponse
522508
inspectStartTime := time.Now()
523509
for time.Since(inspectStartTime) < time.Second {
524510
inspect, err = docker.ContainerInspect(ctx, containerID)

0 commit comments

Comments
 (0)