Home > database >  Configuring Minio Testcontainers with different default port
Configuring Minio Testcontainers with different default port

Time:01-10

Quick summary: How can I change the default port of the minio client running in my test container?

I want to use minio as a testcontainer in my application which already working when I start it locally. here is the codesnippet I use to run the testcontainer:


public class MinioContainer extends GenericContainer<MinioContainer> {

    private static final int DEFAULT_PORT = 9000;
    private static final String DEFAULT_IMAGE = "/minio/minio";
    private static final String DEFAULT_TAG = "latest";

    private static final String MINIO_ACCESS_KEY = "MINIO_ACCESS_KEY";
    private static final String MINIO_SECRET_KEY = "MINIO_SECRET_KEY";

    private static final String DEFAULT_STORAGE_DIRECTORY = "/data";
    private static final String HEALTH_ENDPOINT = "/minio/health/ready";

    public MinioContainer() {

        this(DEFAULT_IMAGE   ":"   DEFAULT_TAG);
    }

    public MinioContainer(String image) {

        super(image == null ? DEFAULT_IMAGE   ":"   DEFAULT_TAG : image);
        Network network = Network.newNetwork();
        withNetwork(network);
        withNetworkAliases("minio-"   Base58.randomString(6));
        addExposedPort(DEFAULT_PORT);
        withEnv(MINIO_ACCESS_KEY, "access_key");
        withEnv(MINIO_SECRET_KEY, "secret_key");
        withCommand("server", DEFAULT_STORAGE_DIRECTORY);
        setWaitStrategy(new HttpWaitStrategy()
                .forPort(DEFAULT_PORT)
                .forPath(HEALTH_ENDPOINT)
                .withStartupTimeout(Duration.ofMinutes(1)));
    }

    public String getHostAddress() {

        return getHost()   ":"   getMappedPort(DEFAULT_PORT);
    }
}

As soon as I deploy this on our cluster, where also an minio container is running at port 9000, it shows this error message in the console:

io.minio.errors.ErrorResponseException: The Access Key Id you provided does not exist in our records.
    at some.package.MinioTest.setup(MinioTest.java:58)

In my test i am running a SpringBootTest using this container and injecting my minio client. I also configured a test application yaml so I can run my test with an active test profile. The error happens on following code snippet:

private final String BUCKET = "bucket";
....

@BeforeEach
void setup() {
    boolean bucketExists = minioClient.bucketExists(BucketExistsArgs.builder().bucket(BUCKET).build());
...
}

Is there a way to change the DEFAULT_PORT on my MinioContainer so it is not the same port as the minio container already running on my cluster? I am not able to get my tests running on our pipeline because of this issue, which is only happening on our cluster.

As soon as I change the DEFAULT_PORT to something different than 9000 on my MinioContainer, the Container stops working because it is not able to find the HEALTH_ENDPOINT and therefor the whole container just stops working.

I hope I explained my problem clear enough. If not please tell me so I can try to explain it clearer. I am already completely frustrated with this issue.

BR Null

CodePudding user response:

I found the solution for my problem. Minio supports the following command:

"server /data --address :9100"

Now I was able to generate my testcontainer now like this:


 public static GenericContainer<?> minioContainer = new GenericContainer<>(MINIO_IMAGE)
            .withCommand("server /data --address :9100")
            .withExposedPorts(9100);

Now the MinioContainer in my Test runs with Port 9100.

Hopefully I was able to help someone else with this issue.

  • Related