From 1c31946352c3f2f7afb938f2cfb0eb4b240cd800 Mon Sep 17 00:00:00 2001 From: Marcus Brandenburger Date: Fri, 30 Aug 2024 13:36:55 +0200 Subject: [PATCH] Fix IRB container package - implement docker API changes Signed-off-by: Marcus Brandenburger --- samples/demos/Makefile | 2 +- samples/demos/irb/Makefile | 4 ++-- samples/demos/irb/pkg/container/container.go | 16 +++++++--------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/samples/demos/Makefile b/samples/demos/Makefile index d78fe63ec..a1c7704b9 100644 --- a/samples/demos/Makefile +++ b/samples/demos/Makefile @@ -8,6 +8,6 @@ include $(TOP)/build.mk DEMOS = irb -build clean: +build test clean: $(foreach DIR, $(DEMOS), $(MAKE) -C $(DIR) $@ || exit;) diff --git a/samples/demos/irb/Makefile b/samples/demos/irb/Makefile index f734a0497..761f7c8b9 100644 --- a/samples/demos/irb/Makefile +++ b/samples/demos/irb/Makefile @@ -7,7 +7,7 @@ include $(TOP)/build.mk COMPONENTS = protos chaincode experimenter -all: pull-images ercc build test +all: ercc build test pull-images: $(DOCKER) pull redis:latest @@ -23,7 +23,7 @@ ercc: build: ercc $(foreach DIR, $(COMPONENTS), $(MAKE) -C $(DIR) $@ || exit;) -test: +test: pull-images $(GO) test -v ./... run: diff --git a/samples/demos/irb/pkg/container/container.go b/samples/demos/irb/pkg/container/container.go index 87119bf34..d7d09060e 100644 --- a/samples/demos/irb/pkg/container/container.go +++ b/samples/demos/irb/pkg/container/container.go @@ -11,7 +11,6 @@ import ( "context" "fmt" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" "github.com/docker/go-connections/nat" @@ -40,12 +39,10 @@ func (c *Container) Start() error { Image: c.Image, Cmd: c.CMD, Env: c.Env, - }, - &container.HostConfig{ - PortBindings: nat.PortMap{ - nat.Port(fmt.Sprintf("%s/tcp", c.HostPort)): []nat.PortBinding{{HostIP: c.HostIP, HostPort: c.HostPort}}, + ExposedPorts: nat.PortSet{ + nat.Port(c.HostPort + "/tcp"): struct{}{}, }, - }, nil, nil, c.Name) + }, nil, nil, nil, c.Name) if err != nil { return err } @@ -54,12 +51,12 @@ func (c *Container) Start() error { return err } - if err := cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil { + if err := cli.ContainerStart(ctx, resp.ID, container.StartOptions{}); err != nil { return err } go func() { - reader, err := cli.ContainerLogs(context.Background(), resp.ID, types.ContainerLogsOptions{ + reader, err := cli.ContainerLogs(context.Background(), resp.ID, container.LogsOptions{ ShowStdout: true, ShowStderr: true, Follow: true, @@ -93,11 +90,12 @@ func (c *Container) Stop() error { return err } + // default timeout is 10s if err := cli.ContainerStop(ctx, c.containerID, container.StopOptions{}); err != nil { return err } - if err := cli.ContainerRemove(ctx, c.containerID, types.ContainerRemoveOptions{}); err != nil { + if err := cli.ContainerRemove(ctx, c.containerID, container.RemoveOptions{}); err != nil { return err }