-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
NginxContainer.java
67 lines (53 loc) · 1.95 KB
/
NginxContainer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package org.testcontainers.containers;
import org.jetbrains.annotations.NotNull;
import org.testcontainers.containers.traits.LinkableContainer;
import org.testcontainers.utility.DockerImageName;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Set;
/**
* @author richardnorth
*/
public class NginxContainer<SELF extends NginxContainer<SELF>>
extends GenericContainer<SELF>
implements LinkableContainer {
private static final int NGINX_DEFAULT_PORT = 80;
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("nginx");
private static final String DEFAULT_TAG = "1.9.4";
/**
* @deprecated use {@link NginxContainer(DockerImageName)} instead
*/
@Deprecated
public NginxContainer() {
this(DEFAULT_IMAGE_NAME.withTag(DEFAULT_TAG));
}
public NginxContainer(String dockerImageName) {
this(DockerImageName.parse(dockerImageName));
}
public NginxContainer(final DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
addExposedPort(NGINX_DEFAULT_PORT);
setCommand("nginx", "-g", "daemon off;");
}
/**
* @return the ports on which to check if the container is ready
* @deprecated use {@link #getLivenessCheckPortNumbers()} instead
*/
@NotNull
@Override
@Deprecated
protected Set<Integer> getLivenessCheckPorts() {
return super.getLivenessCheckPorts();
}
public URL getBaseUrl(String scheme, int port) throws MalformedURLException {
return new URL(scheme + "://" + getHost() + ":" + getMappedPort(port));
}
public void setCustomContent(String htmlContentPath) {
addFileSystemBind(htmlContentPath, "/usr/share/nginx/html", BindMode.READ_ONLY);
}
public SELF withCustomContent(String htmlContentPath) {
this.setCustomContent(htmlContentPath);
return self();
}
}