/** * Whether to tail child container logs. * * @return this instance, for chaining */ public SELF withTailChildContainers(boolean tailChildContainers) { this.tailChildContainers = tailChildContainers; return self(); }
/** * Use a local Docker Compose binary instead of a container. * * @return this instance, for chaining */ public SELF withLocalCompose(boolean localCompose) { this.localCompose = localCompose; return self(); }
/** * Whether to pull images first. * * @return this instance, for chaining */ public SELF withPull(boolean pull) { this.pull = pull; return self(); }
public SELF withEnv(Map<String, String> env) { env.forEach(this.env::put); return self(); }
public SELF withScaledService(String serviceBaseName, int numInstances) { scalingPreferences.put(serviceBaseName, numInstances); return self(); }
public SELF withEnv(String key, String value) { env.put(key, value); return self(); }
/** * Attach an output consumer at container startup, enabling stdout and stderr to be followed, waited on, etc. * <p> * More than one consumer may be registered. * * @param serviceName the name of the service as set in the docker-compose.yml file * @param consumer consumer that output frames should be sent to * @return this instance, for chaining */ public SELF withLogConsumer(String serviceName, Consumer<OutputFrame> consumer) { String serviceInstanceName = getServiceInstanceName(serviceName); final List<Consumer<OutputFrame>> consumers = this.logConsumers.getOrDefault(serviceInstanceName, new ArrayList<>()); consumers.add(consumer); this.logConsumers.putIfAbsent(serviceInstanceName, consumers); return self(); }
/** Specify the {@link WaitStrategy} to use to determine if the container is ready. * * @see org.testcontainers.containers.wait.strategy.Wait#defaultWaitStrategy() * @param serviceName the name of the service to wait for * @param waitStrategy the WaitStrategy to use * @return this */ public SELF waitingFor(String serviceName, @NonNull WaitStrategy waitStrategy) { String serviceInstanceName = getServiceInstanceName(serviceName); addWaitStrategy(serviceInstanceName, waitStrategy); return self(); }
public SELF withExposedService(String serviceName, int servicePort, @NonNull WaitStrategy waitStrategy) { String serviceInstanceName = getServiceInstanceName(serviceName); /* * For every service/port pair that needs to be exposed, we register a target on an 'ambassador container'. * * The ambassador container's role is to link (within the Docker network) to one of the * compose services, and proxy TCP network I/O out to a port that the ambassador container * exposes. * * This avoids the need for the docker compose file to explicitly expose ports on all the * services. * * {@link GenericContainer} should ensure that the ambassador container is on the same network * as the rest of the compose environment. */ // Ambassador container will be started together after docker compose has started int ambassadorPort = nextAmbassadorPort.getAndIncrement(); ambassadorPortMappings.computeIfAbsent(serviceInstanceName, __ -> new ConcurrentHashMap<>()).put(servicePort, ambassadorPort); ambassadorContainer.withTarget(ambassadorPort, serviceInstanceName, servicePort); ambassadorContainer.addLink(new FutureContainer(this.project + "_" + serviceInstanceName), serviceInstanceName); addWaitStrategy(serviceInstanceName, waitStrategy); return self(); }
/** * Whether to pull images first. * * @return this instance, for chaining */ public SELF withPull(boolean pull) { this.pull = pull; return self(); }
/** * Whether to tail child container logs. * * @return this instance, for chaining */ public SELF withTailChildContainers(boolean tailChildContainers) { this.tailChildContainers = tailChildContainers; return self(); }
/** * Use a local Docker Compose binary instead of a container. * * @return this instance, for chaining */ public SELF withLocalCompose(boolean localCompose) { this.localCompose = localCompose; return self(); }
/** * Attach an output consumer at container startup, enabling stdout and stderr to be followed, waited on, etc. * <p> * More than one consumer may be registered. * * @param serviceName the name of the service as set in the docker-compose.yml file * @param consumer consumer that output frames should be sent to * @return this instance, for chaining */ public SELF withLogConsumer(String serviceName, Consumer<OutputFrame> consumer) { String serviceInstanceName = getServiceInstanceName(serviceName); final List<Consumer<OutputFrame>> consumers = this.logConsumers.getOrDefault(serviceInstanceName, new ArrayList<>()); consumers.add(consumer); this.logConsumers.putIfAbsent(serviceInstanceName, consumers); return self(); }