-
Notifications
You must be signed in to change notification settings - Fork 97
/
jvm-dns-ttl-policy.sh
executable file
·79 lines (65 loc) · 2.31 KB
/
jvm-dns-ttl-policy.sh
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
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh
if [ -z "${1}" ]; then
echo "Usage: ${0} <image> --enable-security-manager"
exit 1
fi
target_image="${1}"
dockerfile="
FROM ${target_image}
WORKDIR /var/tmp
RUN printf ' \\
public class DNSTTLPolicy { \\
public static void main(String args[]) { \\
System.out.printf(\"Implementation DNS TTL for JVM in Docker image based on '${target_image}' is %%d seconds\\\\n\", sun.net.InetAddressCachePolicy.get()); \\
} \\
}' >DNSTTLPolicy.java
RUN javac DNSTTLPolicy.java -XDignore.symbol.file
CMD java DNSTTLPolicy
ENTRYPOINT java DNSTTLPolicy
"
dockerfile_security_manager="
FROM ${target_image}
WORKDIR /var/tmp
RUN printf ' \\
public class DNSTTLPolicy { \\
public static void main(String args[]) { \\
System.out.printf(\"Implementation DNS TTL for JVM in Docker image based on '${target_image}' (with security manager enabled) is %%d seconds\\\\n\", sun.net.InetAddressCachePolicy.get()); \\
} \\
}' >DNSTTLPolicy.java
RUN printf ' \\
grant { \\
permission java.security.AllPermission; \\
};' >all-permissions.policy
RUN javac DNSTTLPolicy.java -XDignore.symbol.file
CMD java -Djava.security.manager -Djava.security.policy==all-permissions.policy DNSTTLPolicy
ENTRYPOINT java -Djava.security.manager -Djava.security.policy==all-permissions.policy DNSTTLPolicy
"
target_dockerfile="${dockerfile}"
if [ -n "${2}" ] && [ "${2}" == "--enable-security-manager" ]; then
target_dockerfile="${dockerfile_security_manager}"
fi
tag_name="jvm-dns-ttl-policy"
output_file="$(mktemp)"
function cleanup() {
rm "${output_file}"
docker rmi "${tag_name}" >/dev/null
}
trap "cleanup; exit" SIGHUP SIGINT SIGTERM
echo "Building Docker image based on ${target_image} ..." >&2
docker build -t "${tag_name}" - <<<"${target_dockerfile}" &>"${output_file}"
if [ "$?" -ne 0 ]; then
>&2 echo "Error building test image:"
cat "${output_file}"
cleanup
exit 1
fi
echo "Testing DNS TTL ..." >&2
docker run --rm "${tag_name}" &>"${output_file}"
if [ "$?" -ne 0 ]; then
>&2 echo "Error running test image:"
cat "${output_file}"
cleanup
exit 1
fi
cat "${output_file}"
cleanup