github.com/weaviate/weaviate@v1.24.6/test/docker/minio.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package docker
    13  
    14  import (
    15  	"context"
    16  	"fmt"
    17  	"time"
    18  
    19  	"github.com/docker/go-connections/nat"
    20  	"github.com/testcontainers/testcontainers-go"
    21  	"github.com/testcontainers/testcontainers-go/wait"
    22  )
    23  
    24  const MinIO = "test-minio"
    25  
    26  func startMinIO(ctx context.Context, networkName string) (*DockerContainer, error) {
    27  	port := nat.Port("9000/tcp")
    28  	container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
    29  		ContainerRequest: testcontainers.ContainerRequest{
    30  			Image:        "minio/minio",
    31  			ExposedPorts: []string{"9000/tcp"},
    32  			Name:         MinIO,
    33  			Hostname:     MinIO,
    34  			AutoRemove:   true,
    35  			Networks:     []string{networkName},
    36  			NetworkAliases: map[string][]string{
    37  				networkName: {MinIO},
    38  			},
    39  			Env: map[string]string{
    40  				"MINIO_ROOT_USER":     "aws_access_key",
    41  				"MINIO_ROOT_PASSWORD": "aws_secret_key",
    42  			},
    43  			Cmd: []string{"server", "/data"},
    44  			WaitingFor: wait.ForAll(
    45  				wait.ForListeningPort(port),
    46  				wait.ForHTTP("/minio/health/ready").WithPort(port),
    47  			).WithDeadline(60 * time.Second),
    48  		},
    49  		Started: true,
    50  		Reuse:   true,
    51  	})
    52  	if err != nil {
    53  		return nil, err
    54  	}
    55  	uri, err := container.PortEndpoint(ctx, port, "")
    56  	if err != nil {
    57  		return nil, err
    58  	}
    59  	envSettings := make(map[string]string)
    60  	envSettings["BACKUP_S3_ENDPOINT"] = fmt.Sprintf("%s:%s", MinIO, port.Port())
    61  	envSettings["BACKUP_S3_USE_SSL"] = "false"
    62  	envSettings["AWS_ACCESS_KEY_ID"] = "aws_access_key"
    63  	envSettings["AWS_SECRET_KEY"] = "aws_secret_key"
    64  	endpoints := make(map[EndpointName]endpoint)
    65  	endpoints[HTTP] = endpoint{port, uri}
    66  	return &DockerContainer{MinIO, endpoints, container, envSettings}, nil
    67  }