|
| 1 | +package org.testcontainers.milvus; |
| 2 | + |
| 3 | +import org.testcontainers.containers.GenericContainer; |
| 4 | +import org.testcontainers.containers.wait.strategy.Wait; |
| 5 | +import org.testcontainers.utility.DockerImageName; |
| 6 | +import org.testcontainers.utility.MountableFile; |
| 7 | + |
| 8 | +/** |
| 9 | + * Testcontainers implementation for Milvus. |
| 10 | + * <p> |
| 11 | + * Supported image: {@code milvusdb/milvus} |
| 12 | + * <p> |
| 13 | + * Exposed ports: |
| 14 | + * <ul> |
| 15 | + * <li>Management port: 9091</li> |
| 16 | + * <li>HTTP: 19530</li> |
| 17 | + * </ul> |
| 18 | + */ |
| 19 | +public class MilvusContainer extends GenericContainer<MilvusContainer> { |
| 20 | + |
| 21 | + private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("milvusdb/milvus"); |
| 22 | + |
| 23 | + private String etcdEndpoint; |
| 24 | + |
| 25 | + public MilvusContainer(String image) { |
| 26 | + this(DockerImageName.parse(image)); |
| 27 | + } |
| 28 | + |
| 29 | + public MilvusContainer(DockerImageName dockerImageName) { |
| 30 | + super(dockerImageName); |
| 31 | + dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); |
| 32 | + withExposedPorts(9091, 19530); |
| 33 | + waitingFor(Wait.forHttp("/healthz").forPort(9091)); |
| 34 | + withCommand("milvus", "run", "standalone"); |
| 35 | + withCopyFileToContainer( |
| 36 | + MountableFile.forClasspathResource("testcontainers/embedEtcd.yaml"), |
| 37 | + "/milvus/configs/embedEtcd.yaml" |
| 38 | + ); |
| 39 | + withEnv("COMMON_STORAGETYPE", "local"); |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + protected void configure() { |
| 44 | + if (this.etcdEndpoint == null) { |
| 45 | + withEnv("ETCD_USE_EMBED", "true"); |
| 46 | + withEnv("ETCD_DATA_DIR", "/var/lib/milvus/etcd"); |
| 47 | + withEnv("ETCD_CONFIG_PATH", "/milvus/configs/embedEtcd.yaml"); |
| 48 | + } else { |
| 49 | + withEnv("ETCD_ENDPOINTS", this.etcdEndpoint); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + public MilvusContainer withEtcdEndpoint(String etcdEndpoint) { |
| 54 | + this.etcdEndpoint = etcdEndpoint; |
| 55 | + return this; |
| 56 | + } |
| 57 | + |
| 58 | + public String getEndpoint() { |
| 59 | + return "http://" + getHost() + ":" + getMappedPort(19530); |
| 60 | + } |
| 61 | +} |
0 commit comments