Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Can not import testcontainers-go #629

Closed
kulyklev opened this issue Nov 21, 2022 · 8 comments
Closed

[Bug]: Can not import testcontainers-go #629

kulyklev opened this issue Nov 21, 2022 · 8 comments
Labels
bug An issue with the library

Comments

@kulyklev
Copy link

Testcontainers version

0.16.0

Using the latest Testcontainers version?

Yes

Host OS

Ubuntu 22.04.1 LTS

Host arch

x86

Go version

go1.19.2 linux/amd64

Docker version

Client: Docker Engine - Community
 Version:           20.10.17
 API version:       1.41
 Go version:        go1.17.11
 Git commit:        100c701
 Built:             Mon Jun  6 23:03:23 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.17
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.11
  Git commit:       a89b842
  Built:            Mon Jun  6 23:01:15 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.6
  GitCommit:        10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc:
  Version:          1.1.2
  GitCommit:        v1.1.2-0-ga916309
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Docker info

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.8.2-docker)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Containers: 3
  Running: 1
  Paused: 0
  Stopped: 2
 Images: 29
 Server Version: 20.10.17
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc version: v1.1.2-0-ga916309
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.15.0-53-generic
 Operating System: Ubuntu 22.04.1 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 24
 Total Memory: 62.73GiB
 Name: home-PC
 ID: KJ33:WZJ3:PT2Z:LFJK:ZR7F:KNDU:CKX6:7JKS:SZ4P:7VVA:ZM5Y:7EBE
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Username: speedforce7
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

What happened?

I took some sample code and wanted to import dependencies with go mod tidy to run it, but receive error. I tried to clean modules cache with go clean -modcache, but it didn't help. I still have issues with import.

Sample code:

package docker

import (
	"context"
	"fmt"

	_ "github.com/testcontainers/testcontainers-go"
	_ "github.com/testcontainers/testcontainers-go/wait"
)

func SetupTestDatabase() testcontainers.Container {
	// 1. Create PostgreSQL container request
	containerReq := testcontainers.ContainerRequest{
		Image:        "postgres:latest",
		ExposedPorts: []string{"5432/tcp"},
		WaitingFor:   wait.ForListeningPort("5432/tcp"),
		Env: map[string]string{
			"POSTGRES_DB":       "testdb",
			"POSTGRES_PASSWORD": "postgres",
			"POSTGRES_USER":     "postgres",
		},
	}

	// 2. Start PostgreSQL container
	dbContainer, _ := testcontainers.GenericContainer(
		context.Background(),
		testcontainers.GenericContainerRequest{
			ContainerRequest: containerReq,
			Started:          true,
		})

	// 3.1 Get host and port of PostgreSQL container
	host, _ := dbContainer.Host(context.Background())
	port, _ := dbContainer.MappedPort(context.Background(), "5432")

	// 3.2 Create db connection string and connect
	dbURI := fmt.Sprintf("postgres://postgres:postgres@%v:%v/testdb", host, port.Port())

	return dbContainer
}

Relevant log output

$ go mod tidy
go: finding module for package github.com/testcontainers/testcontainers-go/wait
go: finding module for package github.com/testcontainers/testcontainers-go
go: found github.com/testcontainers/testcontainers-go in github.com/testcontainers/testcontainers-go v0.16.0
go: found github.com/testcontainers/testcontainers-go/wait in github.com/testcontainers/testcontainers-go v0.16.0
go: finding module for package github.com/docker/docker/builder/remotecontext/urlutil
go: finding module for package github.com/tonistiigi/go-rosetta
go: found github.com/tonistiigi/go-rosetta in github.com/tonistiigi/go-rosetta v0.0.0-20220804170347-3f4430f2d346
go: finding module for package github.com/docker/docker/builder/remotecontext/urlutil
fmdi.dev/server/internal/sys/docker imports
        github.com/testcontainers/testcontainers-go imports
        github.com/docker/compose/v2/pkg/compose imports
        github.com/docker/docker/builder/remotecontext/urlutil: module github.com/docker/docker@latest found (v20.10.21+incompatible), but does not contain package github.com/docker/docker/builder/remotecontext/urlutil

Additional information

No response

@kulyklev kulyklev added the bug An issue with the library label Nov 21, 2022
@mdelapenya
Copy link
Collaborator

mdelapenya commented Nov 21, 2022

Hi @kulyklev thanks for reporting this issue. I'm going to do a repro right now and will update it as soon I find anything clear.

@kulyklev
Copy link
Author

Thank you @mdelapenya!
Small update on my issue. I switched to testcontainers to v0.15.0 and now it works

@mdelapenya
Copy link
Collaborator

Thank you @mdelapenya! Small update on my issue. I switched to testcontainers to v0.15.0 and now it works

I think it could be caused by the replace directive that we introduced here: https://github.com/testcontainers/testcontainers-go/pull/476/files#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6R28

@baez90 do you think it could be affecting downstream consumers?

@mdelapenya
Copy link
Collaborator

mdelapenya commented Nov 21, 2022

I was able to reproduce the error, and it seems connected to the dependency with Docker, as I suspected in my previous comment.

I fixed adding this replace instruction to the go.mod:

replace github.com/docker/docker => github.com/docker/docker v20.10.3-0.20221013203545-33ab36d6b304+incompatible // 22.06 branch

which directly comes from testcontainer-go (See here). I'm currently checking out how to mitigate this, if it's possible

@mdelapenya
Copy link
Collaborator

More on this: given the latest version v0.16.0 comes including the Compose dependency, and the Docker folks added a replace directive until the upcoming Docker 22.06 release is out, we were forced to add it too, causing consumer to add the replace directive too.

Please see docker/compose#9946 (comment)

@kiview I'm going to update the release notes, in the breaking changes section to explain how to proceed with consuming the latest version.

@mdelapenya
Copy link
Collaborator

@kulyklev I've updated the release notes: https://github.com/testcontainers/testcontainers-go/releases/tag/v0.16.0

Do you think it's descriptive enough on how to proceed ? I moved the Docker Compose feature from the "Features" section to the "Breaking Changes" one, moving the BC section to the top

@kulyklev
Copy link
Author

Yes, now it's better. Now I can run v0.16.0. Thanks a lot.
But still, you need to think about your documentation. Your project is really cool, but when you can't start it out of the box it's a bad promotion.

@mdelapenya
Copy link
Collaborator

But still, you need to think about your documentation. Your project is really cool, but when you can't start it out of the box it's a bad promotion.

Thanks for this feedback. We are aware of the issue you mention and we are working on fixing it. Since I joined the team as a full-time maintainer past summer, we are working more and more on improving the docs , which is definitively important for us as an OSS project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue with the library
Projects
None yet
Development

No branches or pull requests

2 participants