17
17
#
18
18
19
19
set -o errexit # abort on nonzero exit status
20
- set -o nounset # abort on unbound variable
21
20
set -o pipefail # don't hide errors within pipes
22
21
23
22
nginx_server_proto=" http"
@@ -41,28 +40,71 @@ e() {
41
40
>&2 echo " $1 "
42
41
}
43
42
44
-
45
- if [ $# -eq 0 ]; then
43
+ usage () { e " Usage: $0 [--latest-njs <default:false>] [--unprivileged <default:false>] [--type <default:oss|plus>" 1>&2 ; exit 1; }
44
+
45
+ for arg in " $@ " ; do
46
+ shift
47
+ case " $arg " in
48
+ ' --help' ) set -- " $@ " ' -h' ;;
49
+ ' --latest-njs' ) set -- " $@ " ' -j' ;;
50
+ ' --unprivileged' ) set -- " $@ " ' -u' ;;
51
+ ' --type' ) set -- " $@ " ' -t' ;;
52
+ * ) set -- " $@ " " $arg " ;;
53
+ esac
54
+ done
55
+
56
+ while getopts " hjut:" arg; do
57
+ case " ${arg} " in
58
+ j)
59
+ njs_latest=" 1"
60
+ ;;
61
+ u)
62
+ unprivileged=" 1"
63
+ ;;
64
+ t)
65
+ nginx_type=" ${OPTARG} "
66
+ ;;
67
+ * )
68
+ usage
69
+ ;;
70
+ esac
71
+ done
72
+ shift $(( OPTIND- 1 ))
73
+
74
+ startup_message=" "
75
+
76
+ if [ -z " ${nginx_type} " ]; then
46
77
nginx_type=" oss"
47
- njs_latest=0
48
- p " No argument specified - defaulting to NGINX OSS. Valid arguments: oss, plus, latest-njs-oss, latest-njs-plus"
78
+ startup_message=" Starting NGINX ${nginx_type} (default)"
79
+ elif ! { [ ${nginx_type} == " oss" ] || [ ${nginx_type} == " plus" ]; }; then
80
+ e " Invalid NGINX type: ${nginx_type} - must be either 'oss' or 'plus'"
81
+ usage
49
82
else
50
- if [[ " ${1} " == * plus ]]; then
51
- nginx_type=" plus"
52
- p " Testing with NGINX Plus"
53
- else
54
- nginx_type=" oss"
55
- p " Testing with NGINX OSS"
56
- fi
83
+ startup_message=" Starting NGINX ${nginx_type} "
84
+ fi
57
85
58
- if [[ " ${1} " == latest-njs-* ]]; then
59
- p " Testing with latest development version of NJS"
60
- njs_latest=1
61
- else
62
- njs_latest=0
63
- fi
86
+ if [ -z " ${njs_latest} " ]; then
87
+ njs_latest=" 0"
88
+ startup_message=" ${startup_message} with the release NJS module (default)"
89
+ elif [ ${njs_latest} -eq 1 ]; then
90
+ startup_message=" ${startup_message} with the latest NJS module"
91
+ else
92
+ startup_message=" ${startup_message} with the release NJS module"
64
93
fi
65
94
95
+ if [ -z " ${unprivileged} " ]; then
96
+ unprivileged=" 0"
97
+ startup_message=" ${startup_message} in privileged mode (default)"
98
+ elif [ ${unprivileged} -eq 1 ]; then
99
+ startup_message=" ${startup_message} in unprivileged mode"
100
+ else
101
+ startup_message=" ${startup_message} in privileged mode"
102
+ fi
103
+
104
+ e " ${startup_message} "
105
+
106
+ set -o nounset # abort on unbound variable
107
+
66
108
docker_cmd=" $( command -v docker) "
67
109
if ! [ -x " ${docker_cmd} " ]; then
68
110
e " required dependency not found: docker not found in the path or not executable"
@@ -102,7 +144,14 @@ if [ "${nginx_type}" = "plus" ]; then
102
144
fi
103
145
104
146
compose () {
105
- " ${docker_compose_cmd} " -f " ${test_compose_config} " -p " ${test_compose_project} " " $@ "
147
+ # Hint to docker-compose the internal port to map for the container
148
+ if [ ${unprivileged} -eq 1 ]; then
149
+ export NGINX_INTERNAL_PORT=8080
150
+ else
151
+ export NGINX_INTERNAL_PORT=80
152
+ fi
153
+
154
+ " ${docker_compose_cmd} " -f " ${test_compose_config} " -p " ${test_compose_project} " " $@ "
106
155
}
107
156
108
157
integration_test () {
@@ -208,6 +257,12 @@ if [ ${njs_latest} -eq 1 ]; then
208
257
--tag nginx-s3-gateway --tag nginx-s3-gateway:latest-njs-${nginx_type} .
209
258
fi
210
259
260
+ if [ ${unprivileged} -eq 1 ]; then
261
+ p " Layering in unprivileged build"
262
+ docker build -f Dockerfile.unprivileged \
263
+ --tag nginx-s3-gateway --tag nginx-s3-gateway:unprivileged-${nginx_type} .
264
+ fi
265
+
211
266
# ## UNIT TESTS
212
267
213
268
p " Running unit tests in Docker image"
0 commit comments