From 8f4b456e0e6b544efc0995b28457d9b830915ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Thu, 22 Aug 2024 18:26:24 +0200 Subject: [PATCH] break: use a docker image type for modules --- image.go | 15 +++++++++++++++ modules/artemis/artemis.go | 4 ++-- modules/azurite/azurite.go | 4 ++-- modules/cassandra/cassandra.go | 4 ++-- modules/chroma/chroma.go | 4 ++-- modules/clickhouse/clickhouse.go | 4 ++-- modules/cockroachdb/cockroachdb.go | 4 ++-- modules/consul/consul.go | 4 ++-- modules/couchbase/couchbase.go | 4 ++-- modules/couchbase/options.go | 4 ++-- modules/dolt/dolt.go | 4 ++-- modules/elasticsearch/elasticsearch.go | 8 ++++---- modules/elasticsearch/elasticsearch_test.go | 2 +- modules/elasticsearch/version.go | 2 +- modules/gcloud/bigquery.go | 4 ++-- modules/gcloud/bigtable.go | 4 ++-- modules/gcloud/datastore.go | 4 ++-- modules/gcloud/firestore.go | 4 ++-- modules/gcloud/pubsub.go | 4 ++-- modules/gcloud/spanner.go | 4 ++-- modules/grafana-lgtm/grafana.go | 4 ++-- modules/inbucket/inbucket.go | 4 ++-- modules/influxdb/influxdb.go | 4 ++-- modules/influxdb/influxdb_test.go | 2 +- modules/k3s/k3s.go | 4 ++-- modules/k6/k6.go | 4 ++-- modules/kafka/kafka.go | 4 ++-- modules/localstack/localstack.go | 4 ++-- modules/localstack/localstack_test.go | 2 +- modules/mariadb/mariadb.go | 4 ++-- modules/milvus/milvus.go | 4 ++-- modules/minio/minio.go | 4 ++-- modules/mockserver/mockserver.go | 4 ++-- modules/mongodb/mongodb.go | 4 ++-- modules/mongodb/mongodb_test.go | 2 +- modules/mssql/mssql.go | 4 ++-- modules/mysql/mysql.go | 4 ++-- modules/nats/nats.go | 4 ++-- modules/neo4j/neo4j.go | 4 ++-- modules/neo4j/neo4j_test.go | 3 ++- modules/ollama/ollama.go | 12 +++++++----- modules/ollama/ollama_test.go | 3 ++- modules/openfga/openfga.go | 4 ++-- modules/openldap/openldap.go | 4 ++-- modules/opensearch/opensearch.go | 4 ++-- modules/postgres/postgres.go | 4 ++-- modules/postgres/postgres_test.go | 2 +- modules/pulsar/pulsar.go | 4 ++-- modules/qdrant/qdrant.go | 4 ++-- modules/rabbitmq/rabbitmq.go | 4 ++-- modules/redis/redis.go | 4 ++-- modules/redis/redis_test.go | 3 ++- modules/redpanda/redpanda.go | 4 ++-- modules/registry/registry.go | 4 ++-- modules/surrealdb/surrealdb.go | 4 ++-- modules/valkey/valkey.go | 4 ++-- modules/valkey/valkey_test.go | 3 ++- modules/vault/vault.go | 4 ++-- modules/vearch/vearch.go | 4 ++-- modules/weaviate/weaviate.go | 4 ++-- 60 files changed, 134 insertions(+), 113 deletions(-) diff --git a/image.go b/image.go index f7f2bf0260..15b260f3be 100644 --- a/image.go +++ b/image.go @@ -4,6 +4,21 @@ import ( "context" ) +// DockerImage represents a Docker image as a string. +// Valid examples: +// - "alpine:3.12" +// - "docker.io/nginx:latest" +// - "my-registry.local:5000/my-image:my-tag" +type DockerImage string + +func NewDockerImage(image string) DockerImage { + return DockerImage(image) +} + +func (d DockerImage) String() string { + return string(d) +} + // ImageInfo represents a summary information of an image type ImageInfo struct { ID string diff --git a/modules/artemis/artemis.go b/modules/artemis/artemis.go index 9edfcaa527..78ee42dbe4 100644 --- a/modules/artemis/artemis.go +++ b/modules/artemis/artemis.go @@ -85,10 +85,10 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Artemis container type with a given image -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*Container, error) { req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), Env: map[string]string{ "ARTEMIS_USER": "artemis", "ARTEMIS_PASSWORD": "artemis", diff --git a/modules/azurite/azurite.go b/modules/azurite/azurite.go index 1dcdae4709..a64bccb195 100644 --- a/modules/azurite/azurite.go +++ b/modules/azurite/azurite.go @@ -75,9 +75,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Azurite container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*AzuriteContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*AzuriteContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{BlobPort, QueuePort, TablePort}, Env: map[string]string{}, Entrypoint: []string{"azurite"}, diff --git a/modules/cassandra/cassandra.go b/modules/cassandra/cassandra.go index c5dbfc61d6..de66d0274a 100644 --- a/modules/cassandra/cassandra.go +++ b/modules/cassandra/cassandra.go @@ -81,9 +81,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Cassandra container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*CassandraContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*CassandraContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{string(port)}, Env: map[string]string{ "CASSANDRA_SNITCH": "GossipingPropertyFileSnitch", diff --git a/modules/chroma/chroma.go b/modules/chroma/chroma.go index d0d633f390..5d93854020 100644 --- a/modules/chroma/chroma.go +++ b/modules/chroma/chroma.go @@ -20,9 +20,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Chroma container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*ChromaContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*ChromaContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"8000/tcp"}, WaitingFor: wait.ForAll( wait.ForListeningPort("8000/tcp"), diff --git a/modules/clickhouse/clickhouse.go b/modules/clickhouse/clickhouse.go index 88b8b82d4b..80f7aa4673 100644 --- a/modules/clickhouse/clickhouse.go +++ b/modules/clickhouse/clickhouse.go @@ -221,9 +221,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the ClickHouse container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*ClickHouseContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*ClickHouseContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), Env: map[string]string{ "CLICKHOUSE_USER": defaultUser, "CLICKHOUSE_PASSWORD": defaultUser, diff --git a/modules/cockroachdb/cockroachdb.go b/modules/cockroachdb/cockroachdb.go index e53ef08c6a..861405491a 100644 --- a/modules/cockroachdb/cockroachdb.go +++ b/modules/cockroachdb/cockroachdb.go @@ -74,11 +74,11 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the CockroachDB container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*CockroachDBContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*CockroachDBContainer, error) { o := defaultOptions() req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{ defaultSQLPort, defaultAdminPort, diff --git a/modules/consul/consul.go b/modules/consul/consul.go index fab3c5b29d..ea2597252c 100644 --- a/modules/consul/consul.go +++ b/modules/consul/consul.go @@ -69,10 +69,10 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Consul container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*ConsulContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*ConsulContainer, error) { containerReq := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{ defaultHttpApiPort + "/tcp", defaultBrokerPort + "/tcp", diff --git a/modules/couchbase/couchbase.go b/modules/couchbase/couchbase.go index 5bd73a4eab..e3b8133ca8 100644 --- a/modules/couchbase/couchbase.go +++ b/modules/couchbase/couchbase.go @@ -63,7 +63,7 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Couchbase container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*CouchbaseContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*CouchbaseContainer, error) { config := &Config{ enabledServices: make([]Service, 0), username: "Administrator", @@ -72,7 +72,7 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom } req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{MGMT_PORT + "/tcp", MGMT_SSL_PORT + "/tcp"}, } diff --git a/modules/couchbase/options.go b/modules/couchbase/options.go index 64acf24292..2b823216d9 100644 --- a/modules/couchbase/options.go +++ b/modules/couchbase/options.go @@ -13,7 +13,7 @@ type Config struct { password string isEnterprise bool buckets []bucket - imageName string + imageName testcontainers.DockerImage indexStorageMode indexStorageMode } @@ -90,7 +90,7 @@ func WithBuckets(bucket ...bucket) bucketCustomizer { // Deprecated: Use testcontainers.WithImage instead. func WithImageName(imageName string) Option { return func(c *Config) { - c.imageName = imageName + c.imageName = testcontainers.NewDockerImage(imageName) } } diff --git a/modules/dolt/dolt.go b/modules/dolt/dolt.go index d819e18f5c..d997a2d0c6 100644 --- a/modules/dolt/dolt.go +++ b/modules/dolt/dolt.go @@ -45,9 +45,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Dolt container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*DoltContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*DoltContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"3306/tcp", "33060/tcp"}, Env: map[string]string{ "DOLT_USER": defaultUser, diff --git a/modules/elasticsearch/elasticsearch.go b/modules/elasticsearch/elasticsearch.go index 10a863c589..349c5edca2 100644 --- a/modules/elasticsearch/elasticsearch.go +++ b/modules/elasticsearch/elasticsearch.go @@ -20,9 +20,9 @@ const ( const ( // Deprecated: it will be removed in the next major version - DefaultBaseImage = "docker.elastic.co/elasticsearch/elasticsearch" + DefaultBaseImage testcontainers.DockerImage = "docker.elastic.co/elasticsearch/elasticsearch" // Deprecated: it will be removed in the next major version - DefaultBaseImageOSS = "docker.elastic.co/elasticsearch/elasticsearch-oss" + DefaultBaseImageOSS testcontainers.DockerImage = "docker.elastic.co/elasticsearch/elasticsearch-oss" ) // ElasticsearchContainer represents the Elasticsearch container type used in the module @@ -38,10 +38,10 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Elasticsearch container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*ElasticsearchContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*ElasticsearchContainer, error) { req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), Env: map[string]string{ "discovery.type": "single-node", "cluster.routing.allocation.disk.threshold_enabled": "false", diff --git a/modules/elasticsearch/elasticsearch_test.go b/modules/elasticsearch/elasticsearch_test.go index 1bc7d79456..e8cb126b1c 100644 --- a/modules/elasticsearch/elasticsearch_test.go +++ b/modules/elasticsearch/elasticsearch_test.go @@ -34,7 +34,7 @@ func TestElasticsearch(t *testing.T) { tests := []struct { name string - image string + image testcontainers.DockerImage passwordCustomiser testcontainers.ContainerCustomizer }{ { diff --git a/modules/elasticsearch/version.go b/modules/elasticsearch/version.go index 9ddc2836ad..e12899b079 100644 --- a/modules/elasticsearch/version.go +++ b/modules/elasticsearch/version.go @@ -9,7 +9,7 @@ import ( // isOSS returns true if the base image (without tag) is an OSS image func isOSS(image string) bool { - return strings.HasPrefix(image, DefaultBaseImageOSS) + return strings.HasPrefix(image, DefaultBaseImageOSS.String()) } // isAtLeastVersion returns true if the base image (without tag) is in a version or above diff --git a/modules/gcloud/bigquery.go b/modules/gcloud/bigquery.go index 54363dc2f2..9d79049fb6 100644 --- a/modules/gcloud/bigquery.go +++ b/modules/gcloud/bigquery.go @@ -16,10 +16,10 @@ func RunBigQueryContainer(ctx context.Context, opts ...testcontainers.ContainerC // RunBigQuery creates an instance of the GCloud container type for BigQuery. // The URI will always use http:// as the protocol. -func RunBigQuery(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { +func RunBigQuery(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"9050/tcp", "9060/tcp"}, WaitingFor: wait.ForHTTP("/discovery/v1/apis/bigquery/v2/rest").WithPort("9050/tcp").WithStartupTimeout(time.Second * 5), }, diff --git a/modules/gcloud/bigtable.go b/modules/gcloud/bigtable.go index 4bea521ff1..725acbdd49 100644 --- a/modules/gcloud/bigtable.go +++ b/modules/gcloud/bigtable.go @@ -15,10 +15,10 @@ func RunBigTableContainer(ctx context.Context, opts ...testcontainers.ContainerC } // RunBigTable creates an instance of the GCloud container type for BigTable. -func RunBigTable(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { +func RunBigTable(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"9000/tcp"}, WaitingFor: wait.ForLog("running"), }, diff --git a/modules/gcloud/datastore.go b/modules/gcloud/datastore.go index 92ab671842..35feb463a4 100644 --- a/modules/gcloud/datastore.go +++ b/modules/gcloud/datastore.go @@ -15,10 +15,10 @@ func RunDatastoreContainer(ctx context.Context, opts ...testcontainers.Container } // RunDatastore creates an instance of the GCloud container type for Datastore. -func RunDatastore(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { +func RunDatastore(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"8081/tcp"}, WaitingFor: wait.ForHTTP("/").WithPort("8081/tcp"), }, diff --git a/modules/gcloud/firestore.go b/modules/gcloud/firestore.go index 7f9ced72f7..3ba8f744c7 100644 --- a/modules/gcloud/firestore.go +++ b/modules/gcloud/firestore.go @@ -15,10 +15,10 @@ func RunFirestoreContainer(ctx context.Context, opts ...testcontainers.Container } // RunFirestore creates an instance of the GCloud container type for Firestore. -func RunFirestore(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { +func RunFirestore(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"8080/tcp"}, WaitingFor: wait.ForLog("running"), }, diff --git a/modules/gcloud/pubsub.go b/modules/gcloud/pubsub.go index a2a4e74a1c..2913000652 100644 --- a/modules/gcloud/pubsub.go +++ b/modules/gcloud/pubsub.go @@ -15,10 +15,10 @@ func RunPubsubContainer(ctx context.Context, opts ...testcontainers.ContainerCus } // RunPubsub creates an instance of the GCloud container type for Pubsub. -func RunPubsub(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { +func RunPubsub(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"8085/tcp"}, WaitingFor: wait.ForLog("started"), }, diff --git a/modules/gcloud/spanner.go b/modules/gcloud/spanner.go index d57154ab1d..d2b316011a 100644 --- a/modules/gcloud/spanner.go +++ b/modules/gcloud/spanner.go @@ -14,10 +14,10 @@ func RunSpannerContainer(ctx context.Context, opts ...testcontainers.ContainerCu } // RunSpanner creates an instance of the GCloud container type for Spanner. -func RunSpanner(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { +func RunSpanner(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"9010/tcp"}, WaitingFor: wait.ForLog("Cloud Spanner emulator running"), }, diff --git a/modules/grafana-lgtm/grafana.go b/modules/grafana-lgtm/grafana.go index 1e2f33adba..979097165f 100644 --- a/modules/grafana-lgtm/grafana.go +++ b/modules/grafana-lgtm/grafana.go @@ -25,9 +25,9 @@ type GrafanaLGTMContainer struct { } // Run creates an instance of the Grafana LGTM container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*GrafanaLGTMContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*GrafanaLGTMContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{GrafanaPort, LokiPort, TempoPort, OtlpGrpcPort, OtlpHttpPort, PrometheusPort}, WaitingFor: wait.ForLog(".*The OpenTelemetry collector and the Grafana LGTM stack are up and running.*\\s").AsRegexp().WithOccurrence(1), } diff --git a/modules/inbucket/inbucket.go b/modules/inbucket/inbucket.go index beae784557..2c945b4f7b 100644 --- a/modules/inbucket/inbucket.go +++ b/modules/inbucket/inbucket.go @@ -54,9 +54,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Inbucket container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*InbucketContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*InbucketContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"2500/tcp", "9000/tcp", "1100/tcp"}, WaitingFor: wait.ForAll( wait.ForListeningPort("2500/tcp"), diff --git a/modules/influxdb/influxdb.go b/modules/influxdb/influxdb.go index d359c8cbbc..f544306c9b 100644 --- a/modules/influxdb/influxdb.go +++ b/modules/influxdb/influxdb.go @@ -22,9 +22,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the InfluxDB container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*InfluxDbContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*InfluxDbContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"8086/tcp", "8088/tcp"}, Env: map[string]string{ "INFLUXDB_BIND_ADDRESS": ":8088", diff --git a/modules/influxdb/influxdb_test.go b/modules/influxdb/influxdb_test.go index 6ec5ec7399..881bf883af 100644 --- a/modules/influxdb/influxdb_test.go +++ b/modules/influxdb/influxdb_test.go @@ -96,7 +96,7 @@ func TestWithConfigFile(t *testing.T) { influxVersion := "1.8.10" influxDbContainer, err := influxdb.Run(context.Background(), - "influxdb:"+influxVersion, + testcontainers.NewDockerImage("influxdb:"+influxVersion), influxdb.WithConfigFile(filepath.Join("testdata", "influxdb.conf")), ) require.NoError(t, err) diff --git a/modules/k3s/k3s.go b/modules/k3s/k3s.go index f6cfb055c4..474a67f715 100644 --- a/modules/k3s/k3s.go +++ b/modules/k3s/k3s.go @@ -54,14 +54,14 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the K3s container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*K3sContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*K3sContainer, error) { host, err := getContainerHost(ctx, opts...) if err != nil { return nil, err } req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{ defaultKubeSecurePort, defaultRancherWebhookPort, diff --git a/modules/k6/k6.go b/modules/k6/k6.go index 591cd48f0c..b22d400673 100644 --- a/modules/k6/k6.go +++ b/modules/k6/k6.go @@ -167,9 +167,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the K6 container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*K6Container, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*K6Container, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), Cmd: []string{"run"}, WaitingFor: wait.ForExit(), } diff --git a/modules/kafka/kafka.go b/modules/kafka/kafka.go index c0c02890d4..0d6d58ae37 100644 --- a/modules/kafka/kafka.go +++ b/modules/kafka/kafka.go @@ -43,9 +43,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Kafka container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*KafkaContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*KafkaContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{string(publicPort)}, Env: map[string]string{ // envVars { diff --git a/modules/localstack/localstack.go b/modules/localstack/localstack.go index f06054e83b..c6b66cb550 100644 --- a/modules/localstack/localstack.go +++ b/modules/localstack/localstack.go @@ -73,11 +73,11 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize // Run creates an instance of the LocalStack container type // - overrideReq: a function that can be used to override the default container request, usually used to set the image version, environment variables for localstack, etc. -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*LocalStackContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*LocalStackContainer, error) { dockerHost := testcontainers.ExtractDockerSocket() req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), WaitingFor: wait.ForHTTP("/_localstack/health").WithPort("4566/tcp").WithStartupTimeout(120 * time.Second), ExposedPorts: []string{fmt.Sprintf("%d/tcp", defaultPort)}, Env: map[string]string{}, diff --git a/modules/localstack/localstack_test.go b/modules/localstack/localstack_test.go index 70797fe3cd..24a62e2a0a 100644 --- a/modules/localstack/localstack_test.go +++ b/modules/localstack/localstack_test.go @@ -120,7 +120,7 @@ func TestRunContainer(t *testing.T) { container, err := Run( ctx, - fmt.Sprintf("localstack/localstack:%s", tt.version), + testcontainers.NewDockerImage(fmt.Sprintf("localstack/localstack:%s", tt.version)), ) t.Run("Localstack:"+tt.version+" - multiple services exposed on same port", func(t *testing.T) { diff --git a/modules/mariadb/mariadb.go b/modules/mariadb/mariadb.go index fae71c7871..8f009abaa8 100644 --- a/modules/mariadb/mariadb.go +++ b/modules/mariadb/mariadb.go @@ -126,9 +126,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the MariaDB container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MariaDBContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*MariaDBContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"3306/tcp", "33060/tcp"}, Env: map[string]string{ "MARIADB_USER": defaultUser, diff --git a/modules/milvus/milvus.go b/modules/milvus/milvus.go index 9b944f6160..46de2f05a1 100644 --- a/modules/milvus/milvus.go +++ b/modules/milvus/milvus.go @@ -48,14 +48,14 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Milvus container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MilvusContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*MilvusContainer, error) { config, err := renderEmbedEtcdConfig(defaultClientPort) if err != nil { return nil, fmt.Errorf("render config: %w", err) } req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"19530/tcp", "9091/tcp", "2379/tcp"}, Env: map[string]string{ "ETCD_USE_EMBED": "true", diff --git a/modules/minio/minio.go b/modules/minio/minio.go index c7e2898d9f..c0fe82ff3b 100644 --- a/modules/minio/minio.go +++ b/modules/minio/minio.go @@ -63,9 +63,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Minio container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MinioContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*MinioContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"9000/tcp"}, WaitingFor: wait.ForHTTP("/minio/health/live").WithPort("9000"), Env: map[string]string{ diff --git a/modules/mockserver/mockserver.go b/modules/mockserver/mockserver.go index b53f164e86..9f35fdde35 100644 --- a/modules/mockserver/mockserver.go +++ b/modules/mockserver/mockserver.go @@ -20,9 +20,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the MockServer container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MockServerContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*MockServerContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"1080/tcp"}, WaitingFor: wait.ForAll( wait.ForLog("started on port: 1080"), diff --git a/modules/mongodb/mongodb.go b/modules/mongodb/mongodb.go index 188c55e85b..12bbc203d5 100644 --- a/modules/mongodb/mongodb.go +++ b/modules/mongodb/mongodb.go @@ -22,9 +22,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the MongoDB container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MongoDBContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*MongoDBContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"27017/tcp"}, WaitingFor: wait.ForAll( wait.ForLog("Waiting for connections"), diff --git a/modules/mongodb/mongodb_test.go b/modules/mongodb/mongodb_test.go index ead2b1818b..ed8e4fbec0 100644 --- a/modules/mongodb/mongodb_test.go +++ b/modules/mongodb/mongodb_test.go @@ -14,7 +14,7 @@ import ( func TestMongoDB(t *testing.T) { type tests struct { name string - img string + img testcontainers.DockerImage opts []testcontainers.ContainerCustomizer } testCases := []tests{ diff --git a/modules/mssql/mssql.go b/modules/mssql/mssql.go index ca30d02385..f9c38c084f 100644 --- a/modules/mssql/mssql.go +++ b/modules/mssql/mssql.go @@ -48,9 +48,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the MSSQLServer container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MSSQLServerContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*MSSQLServerContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{defaultPort}, Env: map[string]string{ "MSSQL_SA_PASSWORD": defaultPassword, diff --git a/modules/mysql/mysql.go b/modules/mysql/mysql.go index 7bc6bf7e25..fb1a9cab1a 100644 --- a/modules/mysql/mysql.go +++ b/modules/mysql/mysql.go @@ -50,9 +50,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the MySQL container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MySQLContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*MySQLContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"3306/tcp", "33060/tcp"}, Env: map[string]string{ "MYSQL_USER": defaultUser, diff --git a/modules/nats/nats.go b/modules/nats/nats.go index 0ded01dd09..240fe2e706 100644 --- a/modules/nats/nats.go +++ b/modules/nats/nats.go @@ -28,9 +28,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the NATS container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*NATSContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*NATSContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{defaultClientPort, defaultRoutingPort, defaultMonitoringPort}, Cmd: []string{"-DV", "-js"}, WaitingFor: wait.ForLog("Listening for client connections on 0.0.0.0:4222"), diff --git a/modules/neo4j/neo4j.go b/modules/neo4j/neo4j.go index e4f7fc3314..84dbb61e22 100644 --- a/modules/neo4j/neo4j.go +++ b/modules/neo4j/neo4j.go @@ -48,10 +48,10 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Neo4j container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Neo4jContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*Neo4jContainer, error) { httpPort, _ := nat.NewPort("tcp", defaultHttpPort) request := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), Env: map[string]string{ "NEO4J_AUTH": "none", }, diff --git a/modules/neo4j/neo4j_test.go b/modules/neo4j/neo4j_test.go index 20bd17188b..c86bd33ef0 100644 --- a/modules/neo4j/neo4j_test.go +++ b/modules/neo4j/neo4j_test.go @@ -9,6 +9,7 @@ import ( neo "github.com/neo4j/neo4j-go-driver/v5/neo4j" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/neo4j" ) @@ -64,7 +65,7 @@ func TestNeo4jWithEnterpriseLicense(t *testing.T) { ctx := context.Background() - images := map[string]string{ + images := map[string]testcontainers.DockerImage{ "StandardEdition": "docker.io/neo4j:4.4", "EnterpriseEdition": "docker.io/neo4j:4.4-enterprise", } diff --git a/modules/ollama/ollama.go b/modules/ollama/ollama.go index b8a2fc1de6..f45011c683 100644 --- a/modules/ollama/ollama.go +++ b/modules/ollama/ollama.go @@ -42,13 +42,15 @@ func (c *OllamaContainer) ConnectionString(ctx context.Context) (string, error) // The target image name should be unique, as this method will commit the current state // of the container into a new image with the given name, so it doesn't override existing images. // It should be used for creating an image that contains a loaded model. -func (c *OllamaContainer) Commit(ctx context.Context, targetImage string) error { +func (c *OllamaContainer) Commit(ctx context.Context, targetImage testcontainers.DockerImage) error { cli, err := testcontainers.NewDockerClientWithOpts(context.Background()) if err != nil { return err } - list, err := cli.ImageList(ctx, image.ListOptions{Filters: filters.NewArgs(filters.Arg("reference", targetImage))}) + targetImg := targetImage.String() + + list, err := cli.ImageList(ctx, image.ListOptions{Filters: filters.NewArgs(filters.Arg("reference", targetImg))}) if err != nil { return fmt.Errorf("listing images %w", err) } @@ -58,7 +60,7 @@ func (c *OllamaContainer) Commit(ctx context.Context, targetImage string) error } _, err = cli.ContainerCommit(ctx, c.GetContainerID(), container.CommitOptions{ - Reference: targetImage, + Reference: targetImg, Config: &container.Config{ Labels: map[string]string{ core.LabelSessionID: "", @@ -79,9 +81,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Ollama container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*OllamaContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*OllamaContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"11434/tcp"}, WaitingFor: wait.ForListeningPort("11434/tcp").WithStartupTimeout(60 * time.Second), } diff --git a/modules/ollama/ollama_test.go b/modules/ollama/ollama_test.go index b60538835b..04f6523c92 100644 --- a/modules/ollama/ollama_test.go +++ b/modules/ollama/ollama_test.go @@ -11,6 +11,7 @@ import ( "github.com/google/uuid" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/exec" "github.com/testcontainers/testcontainers-go/modules/ollama" ) @@ -71,7 +72,7 @@ func TestOllama(t *testing.T) { // Defining the target image name based on the default image and a random string. // Users can change the way this is generated, but it should be unique. - targetImage := fmt.Sprintf("%s-%s", ollama.DefaultOllamaImage, strings.ToLower(uuid.New().String()[:4])) + targetImage := testcontainers.NewDockerImage(fmt.Sprintf("%s-%s", ollama.DefaultOllamaImage, strings.ToLower(uuid.New().String()[:4]))) err := container.Commit(context.Background(), targetImage) // } diff --git a/modules/openfga/openfga.go b/modules/openfga/openfga.go index ccdaab71cb..2d257e662f 100644 --- a/modules/openfga/openfga.go +++ b/modules/openfga/openfga.go @@ -46,9 +46,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the OpenFGA container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*OpenFGAContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*OpenFGAContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), Cmd: []string{"run"}, ExposedPorts: []string{"3000/tcp", "8080/tcp", "8081/tcp"}, WaitingFor: wait.ForAll( diff --git a/modules/openldap/openldap.go b/modules/openldap/openldap.go index dc215226c1..4445819b17 100644 --- a/modules/openldap/openldap.go +++ b/modules/openldap/openldap.go @@ -129,9 +129,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the OpenLDAP container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*OpenLDAPContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*OpenLDAPContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), Env: map[string]string{ "LDAP_ADMIN_USERNAME": defaultUser, "LDAP_ADMIN_PASSWORD": defaultPassword, diff --git a/modules/opensearch/opensearch.go b/modules/opensearch/opensearch.go index 83177c8471..b28f98e3c8 100644 --- a/modules/opensearch/opensearch.go +++ b/modules/opensearch/opensearch.go @@ -34,9 +34,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the OpenSearch container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*OpenSearchContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*OpenSearchContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{defaultHTTPPort, "9600/tcp"}, Env: map[string]string{ "discovery.type": "single-node", diff --git a/modules/postgres/postgres.go b/modules/postgres/postgres.go index 0ab4d889d1..3e8e195551 100644 --- a/modules/postgres/postgres.go +++ b/modules/postgres/postgres.go @@ -140,9 +140,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Postgres container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*PostgresContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*PostgresContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), Env: map[string]string{ "POSTGRES_USER": defaultUser, "POSTGRES_PASSWORD": defaultPassword, diff --git a/modules/postgres/postgres_test.go b/modules/postgres/postgres_test.go index adef0defe3..f9195245d5 100644 --- a/modules/postgres/postgres_test.go +++ b/modules/postgres/postgres_test.go @@ -32,7 +32,7 @@ func TestPostgres(t *testing.T) { tests := []struct { name string - image string + image testcontainers.DockerImage }{ { name: "Postgres", diff --git a/modules/pulsar/pulsar.go b/modules/pulsar/pulsar.go index c1c5c94517..5b713faf62 100644 --- a/modules/pulsar/pulsar.go +++ b/modules/pulsar/pulsar.go @@ -144,9 +144,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize // - the log message "Successfully updated the policies on namespace public/default" // // - command: "/bin/bash -c /pulsar/bin/apply-config-from-env.py /pulsar/conf/standalone.conf && bin/pulsar standalone --no-functions-worker -nss" -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*Container, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), Env: map[string]string{}, ExposedPorts: []string{defaultPulsarPort, defaultPulsarAdminPort}, WaitingFor: defaultWaitStrategies, diff --git a/modules/qdrant/qdrant.go b/modules/qdrant/qdrant.go index e934403f96..8f895b8533 100644 --- a/modules/qdrant/qdrant.go +++ b/modules/qdrant/qdrant.go @@ -21,9 +21,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Qdrant container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*QdrantContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*QdrantContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"6333/tcp", "6334/tcp"}, WaitingFor: wait.ForAll( wait.ForListeningPort("6333/tcp").WithStartupTimeout(5*time.Second), diff --git a/modules/rabbitmq/rabbitmq.go b/modules/rabbitmq/rabbitmq.go index bcc1a849d7..4584a94563 100644 --- a/modules/rabbitmq/rabbitmq.go +++ b/modules/rabbitmq/rabbitmq.go @@ -73,9 +73,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the RabbitMQ container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*RabbitMQContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*RabbitMQContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), Env: map[string]string{ "RABBITMQ_DEFAULT_USER": defaultUser, "RABBITMQ_DEFAULT_PASS": defaultPassword, diff --git a/modules/redis/redis.go b/modules/redis/redis.go index 33ce823994..8933af8d8e 100644 --- a/modules/redis/redis.go +++ b/modules/redis/redis.go @@ -50,9 +50,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Redis container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*RedisContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*RedisContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"6379/tcp"}, WaitingFor: wait.ForLog("* Ready to accept connections"), } diff --git a/modules/redis/redis_test.go b/modules/redis/redis_test.go index f98079685f..a299cf44df 100644 --- a/modules/redis/redis_test.go +++ b/modules/redis/redis_test.go @@ -11,6 +11,7 @@ import ( "github.com/google/uuid" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" tcredis "github.com/testcontainers/testcontainers-go/modules/redis" ) @@ -47,7 +48,7 @@ func TestRedisWithImage(t *testing.T) { tests := []struct { name string - image string + image testcontainers.DockerImage }{ { name: "Redis6", diff --git a/modules/redpanda/redpanda.go b/modules/redpanda/redpanda.go index 3ed3932066..85342d09bd 100644 --- a/modules/redpanda/redpanda.go +++ b/modules/redpanda/redpanda.go @@ -59,7 +59,7 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Redpanda container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*Container, error) { tmpDir, err := os.MkdirTemp("", "redpanda") if err != nil { return nil, fmt.Errorf("failed to create directory: %w", err) @@ -70,7 +70,7 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom // Some (e.g. Image) may be overridden by providing an option argument to this function. req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), User: "root:root", // Files: Will be added later after we've rendered our YAML templates. ExposedPorts: []string{ diff --git a/modules/registry/registry.go b/modules/registry/registry.go index b554f8dcc7..df9aaab60c 100644 --- a/modules/registry/registry.go +++ b/modules/registry/registry.go @@ -212,9 +212,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Registry container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*RegistryContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*RegistryContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{registryPort}, Env: map[string]string{ // convenient for testing diff --git a/modules/surrealdb/surrealdb.go b/modules/surrealdb/surrealdb.go index 1968ca5d98..29bb4f65ab 100644 --- a/modules/surrealdb/surrealdb.go +++ b/modules/surrealdb/surrealdb.go @@ -86,9 +86,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the SurrealDB container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*SurrealDBContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*SurrealDBContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), Env: map[string]string{ "SURREAL_USER": "root", "SURREAL_PASS": "root", diff --git a/modules/valkey/valkey.go b/modules/valkey/valkey.go index e3b3728ddd..299151ddaa 100644 --- a/modules/valkey/valkey.go +++ b/modules/valkey/valkey.go @@ -52,9 +52,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Valkey container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*ValkeyContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*ValkeyContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"6379/tcp"}, WaitingFor: wait.ForLog("* Ready to accept connections"), } diff --git a/modules/valkey/valkey_test.go b/modules/valkey/valkey_test.go index c440f79179..0d3c348034 100644 --- a/modules/valkey/valkey_test.go +++ b/modules/valkey/valkey_test.go @@ -11,6 +11,7 @@ import ( "github.com/stretchr/testify/require" "github.com/valkey-io/valkey-go" + "github.com/testcontainers/testcontainers-go" tcvalkey "github.com/testcontainers/testcontainers-go/modules/valkey" ) @@ -47,7 +48,7 @@ func TestValkeyWithImage(t *testing.T) { tests := []struct { name string - image string + image testcontainers.DockerImage }{ // There is only one release of Valkey at the time of writing { diff --git a/modules/vault/vault.go b/modules/vault/vault.go index 37237748ed..999291ef52 100644 --- a/modules/vault/vault.go +++ b/modules/vault/vault.go @@ -27,9 +27,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Vault container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*VaultContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*VaultContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{defaultPort + "/tcp"}, HostConfigModifier: func(hc *container.HostConfig) { hc.CapAdd = []string{"IPC_LOCK"} diff --git a/modules/vearch/vearch.go b/modules/vearch/vearch.go index dccedacad1..675d8143cc 100644 --- a/modules/vearch/vearch.go +++ b/modules/vearch/vearch.go @@ -21,9 +21,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Vearch container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*VearchContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*VearchContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), ExposedPorts: []string{"8817/tcp", "9001/tcp"}, Cmd: []string{"-conf=/vearch/config.toml", "all"}, Privileged: true, diff --git a/modules/weaviate/weaviate.go b/modules/weaviate/weaviate.go index 93665efc66..90c3d3f9aa 100644 --- a/modules/weaviate/weaviate.go +++ b/modules/weaviate/weaviate.go @@ -26,9 +26,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } // Run creates an instance of the Weaviate container type -func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*WeaviateContainer, error) { +func Run(ctx context.Context, img testcontainers.DockerImage, opts ...testcontainers.ContainerCustomizer) (*WeaviateContainer, error) { req := testcontainers.ContainerRequest{ - Image: img, + Image: img.String(), Cmd: []string{"--host", "0.0.0.0", "--scheme", "http", "--port", "8080"}, ExposedPorts: []string{httpPort, grpcPort}, Env: map[string]string{