org.testcontainers.containers.SelinuxContext Java Examples
The following examples show how to use
org.testcontainers.containers.SelinuxContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CopyFileToContainerTest.java From testcontainers-java with MIT License | 6 votes |
@Test public void shouldUseCopyOnlyWithReadOnlyClasspathResources() { String resource = "/test_copy_to_container.txt"; GenericContainer<?> container = new GenericContainer<>() .withClasspathResourceMapping(resource, "/readOnly", BindMode.READ_ONLY) .withClasspathResourceMapping(resource, "/readOnlyNoSelinux", BindMode.READ_ONLY) .withClasspathResourceMapping(resource, "/readOnlyShared", BindMode.READ_ONLY, SelinuxContext.SHARED) .withClasspathResourceMapping(resource, "/readWrite", BindMode.READ_WRITE); Map<MountableFile, String> copyMap = container.getCopyToFileContainerPathMap(); assertTrue("uses copy for read-only", copyMap.containsValue("/readOnly")); assertTrue("uses copy for read-only and no Selinux", copyMap.containsValue("/readOnlyNoSelinux")); assertFalse("uses mount for read-only with Selinux", copyMap.containsValue("/readOnlyShared")); assertFalse("uses mount for read-write", copyMap.containsValue("/readWrite")); }
Example #2
Source File: EtcdContainer.java From jetcd with Apache License 2.0 | 4 votes |
public EtcdContainer(Network network, LifecycleListener listener, boolean ssl, String clusterName, String endpoint, List<String> endpoints, String image, List<String> additionalArgs) { this.endpoint = endpoint; this.ssl = ssl; this.listener = listener; this.dataDirectory = createDataDirectory(endpoint); this.container = new FixedHostPortGenericContainer<>(image); this.container.withExposedPorts(ETCD_PEER_PORT); this.container.withFixedExposedPort(getAvailablePort(), ETCD_CLIENT_PORT); this.container.withNetwork(network); this.container.withNetworkAliases(endpoint); this.container.waitingFor(Wait.forLogMessage(".*ready to serve client requests.*", 1)); this.container.withLogConsumer(new Slf4jLogConsumer(LOGGER).withPrefix(endpoint)); this.container.addFileSystemBind(dataDirectory.toString(), ETCD_DATA_DIR, BindMode.READ_WRITE, SelinuxContext.SHARED); List<String> cmd = new ArrayList<>(); cmd.add("etcd"); cmd.add("--name"); cmd.add(endpoint); cmd.add("--advertise-client-urls"); cmd.add((ssl ? "https" : "http") + "://0.0.0.0:" + ETCD_CLIENT_PORT); cmd.add("--listen-client-urls"); cmd.add((ssl ? "https" : "http") + "://0.0.0.0:" + ETCD_CLIENT_PORT); cmd.add("--data-dir"); cmd.add(ETCD_DATA_DIR); if (ssl) { this.container.withClasspathResourceMapping( "ssl/cert/" + endpoint + ".pem", "/etc/ssl/etcd/server.pem", BindMode.READ_ONLY, SelinuxContext.SHARED); this.container.withClasspathResourceMapping( "ssl/cert/" + endpoint + "-key.pem", "/etc/ssl/etcd/server-key.pem", BindMode.READ_ONLY, SelinuxContext.SHARED); cmd.add("--cert-file"); cmd.add("/etc/ssl/etcd/server.pem"); cmd.add("--key-file"); cmd.add("/etc/ssl/etcd/server-key.pem"); } if (endpoints.size() > 1) { cmd.add("--initial-advertise-peer-urls"); cmd.add("http://" + endpoint + ":" + ETCD_PEER_PORT); cmd.add("--listen-peer-urls"); cmd.add("http://0.0.0.0:" + ETCD_PEER_PORT); cmd.add("--initial-cluster-token"); cmd.add(clusterName); cmd.add("--initial-cluster"); cmd.add(endpoints.stream().map(e -> e + "=http://" + e + ":" + ETCD_PEER_PORT).collect(Collectors.joining(","))); cmd.add("--initial-cluster-state"); cmd.add("new"); } cmd.addAll(additionalArgs); if (!cmd.isEmpty()) { this.container.withCommand(cmd.toArray(new String[0])); } }
Example #3
Source File: EtcdContainer.java From etcd4j with Apache License 2.0 | 4 votes |
public EtcdContainer(Network network, LifecycleListener listener, boolean ssl, String clusterName, String endpoint, List<String> endpoints) { this.endpoint = endpoint; this.ssl = ssl; this.listener = listener; final String name = endpoint; final List<String> command = new ArrayList<>(); this.container = new FixedHostPortGenericContainer<>(ETCD_DOCKER_IMAGE_NAME); this.container.withExposedPorts(ETCD_CLIENT_PORT, ETCD_PEER_PORT); this.container.withNetwork(network); this.container.withNetworkAliases(name); this.container.waitingFor(waitStrategy()); this.container.withLogConsumer(logConsumer()); command.add("--name"); command.add(name); command.add("--advertise-client-urls"); command.add((ssl ? "https" : "http") + "://0.0.0.0:" + ETCD_CLIENT_PORT); command.add("--listen-client-urls"); command.add((ssl ? "https" : "http") + "://0.0.0.0:" + ETCD_CLIENT_PORT); if (ssl) { this.container.withClasspathResourceMapping( "ssl/cert/" + name + ".pem", "/etc/ssl/etcd/server.pem", BindMode.READ_ONLY, SelinuxContext.SHARED); this.container.withClasspathResourceMapping( "ssl/cert/" + name + "-key.pem", "/etc/ssl/etcd/server-key.pem", BindMode.READ_ONLY, SelinuxContext.SHARED); command.add("--cert-file"); command.add("/etc/ssl/etcd/server.pem"); command.add("--key-file"); command.add("/etc/ssl/etcd/server-key.pem"); } if (endpoints.size() > 1) { command.add("--initial-advertise-peer-urls"); command.add("http://" + name + ":" + ETCD_PEER_PORT); command.add("--listen-peer-urls"); command.add("http://0.0.0.0:" + ETCD_PEER_PORT); command.add("--initial-cluster-token"); command.add(clusterName); command.add("--initial-cluster"); command.add(endpoints.stream().map(e -> e + "=" + "http://" + e + ":" + ETCD_PEER_PORT).collect(Collectors.joining(","))); command.add("--initial-cluster-state"); command.add("new"); } if (!command.isEmpty()) { this.container.withCommand(command.toArray(new String[command.size()])); } }