@@ -56,12 +56,14 @@ Environment variables:
5656 to be set before the 'build' action
5757 PHP_VERSION default value: 'default', ie. the stock php version from the Ubuntu version in use. Other possible values: 5.6, 7.0 .. 7.4, 8.0 .. 8.4
5858 UBUNTU_VERSION default value: jammy. Other possible values: xenial, bionic, focal, noble
59- default value: 8080. Set to 'no' not to publish the container's proxy http port to the host
60- can also be set before the 'runtests' and 'runcoverage' actions:
59+ to be set before the 'start' action
60+ HOST_HTTPPORT default value: 80. Set to 'no' not to publish the container's http port to the host
61+ HOST_HTTPSPORT default value: 443. Set to 'no' not to publish the container's https port to the host
62+ HOST_PROXYPORT default value: 8080. Set to 'no' not to publish the container's proxy http port to the host
63+ to be set before the 'runtests' and 'runcoverage' actions:
6164 HTTPSVERIFYHOST 0, 1 or 2. Default and recommended: 0
6265 HTTPSIGNOREPEER 0 or 1. Default and recommended: 1
6366 SSLVERSION 0 (auto), 2 (SSLv2) to 7 (tls 1.3). Default: 0
64- can be used only for 'runtests' and 'runcoverage' actions:
6567 DEBUG
6668"
6769}
@@ -77,76 +79,91 @@ wait_for_bootstrap() {
7779 sleep 1
7880 I=$(( I+ 1 ))
7981 done
80- if [ $I -eq 60 ]; then
82+ if [ $I -gt 60 ]; then
83+ echo ' '
8184 echo " ERROR: Container did not finish bootstrapping within 60 seconds..." >&2
8285 return 1
8386 fi
8487 return 0
8588}
8689
8790build () {
88- stop
89- docker build --build-arg PHP_VERSION --build-arg UBUNTU_VERSION -t " ${IMAGE_NAME} " .
90- if docker inspect " ${CONTAINER_NAME} " > /dev/null 2> /dev/null; then
91- docker rm " ${CONTAINER_NAME} "
92- fi
93- PORTMAPPING=' '
94- # @todo improve error message and abort in case any port is not an integer or negative
95- if [ " $HOST_HTTPPORT " != no ] && [ " $HOST_HTTPPORT " != ' ' ]; then
96- PORTMAPPING=" -p $(( HOST_HTTPPORT- 0 )) :80 "
97- fi
98- if [ " $HOST_HTTPSPORT " != no ] && [ " $HOST_HTTPSPORT " != ' ' ]; then
99- PORTMAPPING=" ${PORTMAPPING} -p $(( HOST_HTTPSPORT)) :443 "
100- fi
101- if [ " $HOST_PROXYPORT " != no ] && [ " $HOST_PROXYPORT " != ' ' ]; then
102- PORTMAPPING=" -p $(( HOST_PROXYPORT- 0 )) :8080 "
103- fi
104- if docker run -d \
105- $PORTMAPPING \
106- --name " ${CONTAINER_NAME} " \
107- --env " CONTAINER_USER_UID=$( id -u) " --env " CONTAINER_USER_GID=$( id -g) " \
108- --env " TESTS_ROOT_DIR=${CONTAINER_WORKSPACE_DIR} " \
109- --env HTTPSERVER=localhost \
110- --env HTTPURI=/tests/index.php? demo=server/server.php \
111- --env HTTPSSERVER=localhost \
112- --env HTTPSURI=/tests/index.php? demo=server/server.php \
113- --env PROXYSERVER=localhost:8080 \
114- --env " HTTPSVERIFYHOST=${HTTPSVERIFYHOST} " \
115- --env " HTTPSIGNOREPEER=${HTTPSIGNOREPEER} " \
116- --env " SSLVERSION=${SSLVERSION} " \
117- --env DEBUG=" ${DEBUG} " \
118- -v " ${ROOT_DIR} " :" ${CONTAINER_WORKSPACE_DIR} " \
119- " ${IMAGE_NAME} " ; then
120- wait_for_bootstrap
91+ if docker build --build-arg PHP_VERSION --build-arg UBUNTU_VERSION -t " ${IMAGE_NAME} " . ; then
92+ if [ " $1 " = ' -r' ]; then
93+ # stop and remove existing containers built from a previous version of this image
94+ if docker inspect " ${CONTAINER_NAME} " > /dev/null 2> /dev/null; then
95+ stop
96+ docker rm " ${CONTAINER_NAME} "
97+ fi
98+ fi
12199 fi
122100}
123101
124102start () {
125- if docker inspect " ${CONTAINER_NAME} " > /dev/null 2> /dev/null; then
126- docker start " ${CONTAINER_NAME} "
127- if [ $? -eq 0 ]; then
128- wait_for_bootstrap
129- fi
103+ if [ " $( docker inspect --format ' {{.State.Status}}' ${CONTAINER_NAME} 2> /dev/null) " = running ]; then
104+ # @todo we should check that the env vars have not changed, and give a warning if so
105+ echo " ${CONTAINER_NAME} already started..."
130106 else
131- build
107+ if docker inspect " ${CONTAINER_NAME} " > /dev/null 2> /dev/null; then
108+ echo " starting existing container ${CONTAINER_NAME} ..."
109+ # @todo we should check that the env vars have not changed, and give a warning if so. Doable using `inspect`...
110+ if docker start " ${CONTAINER_NAME} " ; then
111+ wait_for_bootstrap
112+ fi
113+ else
114+ build
115+
116+ PORTMAPPING=' '
117+ # @todo improve error message and abort in case any port is not an integer or negative
118+ if [ " $HOST_HTTPPORT " != no ] && [ " $HOST_HTTPPORT " != ' ' ]; then
119+ PORTMAPPING=" -p $(( HOST_HTTPPORT- 0 )) :80 "
120+ fi
121+ if [ " $HOST_HTTPSPORT " != no ] && [ " $HOST_HTTPSPORT " != ' ' ]; then
122+ PORTMAPPING=" ${PORTMAPPING} -p $(( HOST_HTTPSPORT)) :443 "
123+ fi
124+ if [ " $HOST_PROXYPORT " != no ] && [ " $HOST_PROXYPORT " != ' ' ]; then
125+ PORTMAPPING=" -p $(( HOST_PROXYPORT- 0 )) :8080 "
126+ fi
127+ if docker run -d \
128+ $PORTMAPPING \
129+ --name " ${CONTAINER_NAME} " \
130+ --env " CONTAINER_USER_UID=$( id -u) " --env " CONTAINER_USER_GID=$( id -g) " \
131+ --env " TESTS_ROOT_DIR=${CONTAINER_WORKSPACE_DIR} " \
132+ --env HTTPSERVER=localhost \
133+ --env HTTPURI=/tests/index.php? demo=server/server.php \
134+ --env HTTPSSERVER=localhost \
135+ --env HTTPSURI=/tests/index.php? demo=server/server.php \
136+ --env PROXYSERVER=localhost:8080 \
137+ -v " ${ROOT_DIR} " :" ${CONTAINER_WORKSPACE_DIR} " \
138+ " ${IMAGE_NAME} " ; then
139+ wait_for_bootstrap
140+ fi
141+ fi
132142 fi
133143}
134144
135145stop () {
136- if docker inspect " ${CONTAINER_NAME} " > /dev/null 2> /dev/null; then
137- docker stop " ${CONTAINER_NAME} "
146+ if [ " $( docker inspect --format ' {{.State.Status}}' ${CONTAINER_NAME} 2> /dev/null) " = exited ]; then
147+ echo " ${CONTAINER_NAME} already stopped"
148+ else
149+ if docker inspect " ${CONTAINER_NAME} " > /dev/null 2> /dev/null; then
150+ echo " stopping ${CONTAINER_NAME} ..."
151+ docker stop " ${CONTAINER_NAME} "
152+ fi
138153 fi
139154}
140155
141156case " ${ACTION} " in
142157
143158 build)
144- build
145- stop
159+ build -r
146160 ;;
147161
148162 cleanup)
149- docker rm " ${CONTAINER_NAME} "
163+ if docker inspect " ${CONTAINER_NAME} " > /dev/null 2> /dev/null; then
164+ docker stop " ${CONTAINER_NAME} "
165+ docker rm " ${CONTAINER_NAME} "
166+ fi
150167 docker rmi " ${IMAGE_NAME} "
151168 ;;
152169
@@ -164,13 +181,13 @@ case "${ACTION}" in
164181 shift
165182 test -t 1 && USE_TTY=" -t"
166183 docker exec -i $USE_TTY \
167- --env " HTTPSVERIFYHOST=${HTTPSVERIFYHOST} " \
168- --env " HTTPSIGNOREPEER=${HTTPSIGNOREPEER} " \
169- --env " SSLVERSION=${SSLVERSION} " \
170- --env DEBUG=" ${DEBUG} " \
171- " ${CONTAINER_NAME} " su " ${CONTAINER_USER} " -c ' "$0" "$@"' -- " $@ "
172- # q: which one is better? test with a command with spaces in options values, and with a composite command such as cd here && do that
173- # "${CONTAINER_NAME}" sudo -iu "${CONTAINER_USER}" -- "$@"
184+ --env " HTTPSVERIFYHOST=${HTTPSVERIFYHOST} " \
185+ --env " HTTPSIGNOREPEER=${HTTPSIGNOREPEER} " \
186+ --env " SSLVERSION=${SSLVERSION} " \
187+ --env DEBUG=" ${DEBUG} " \
188+ " ${CONTAINER_NAME} " su " ${CONTAINER_USER} " -c ' "$0" "$@"' -- " $@ "
189+ # @todo which one is better? test with a command with spaces in options values, and with a composite command such as cd here && do that
190+ # "${CONTAINER_NAME}" sudo -iu "${CONTAINER_USER}" -- "$@"
174191 ;;
175192
176193 restart)
@@ -181,6 +198,7 @@ case "${ACTION}" in
181198 runcoverage)
182199 test -t 1 && USE_TTY=" -t"
183200 # @todo clean up /tmp/phpxmlrpc and .phpunit.result.cache
201+ # @todo run composer install if it was not yet run or we are asked to
184202 if [ ! -d build ]; then mkdir build; fi
185203 docker exec -t " ${CONTAINER_NAME} " " ${CONTAINER_WORKSPACE_DIR} /tests/ci/setup/setup_code_coverage.sh" enable
186204 docker exec -i $USE_TTY \
@@ -194,6 +212,8 @@ case "${ACTION}" in
194212
195213 runtests)
196214 test -t 1 && USE_TTY=" -t"
215+ # @todo clean up /tmp/phpxmlrpc and .phpunit.result.cache
216+ # @todo run composer install if it was not yet run or we are asked to
197217 docker exec -i $USE_TTY \
198218 --env " HTTPSVERIFYHOST=${HTTPSVERIFYHOST} " \
199219 --env " HTTPSIGNOREPEER=${HTTPSIGNOREPEER} " \
@@ -212,10 +232,6 @@ case "${ACTION}" in
212232 start
213233 ;;
214234
215- # status)
216- # :
217- # ;;
218-
219235 stop)
220236 stop
221237 ;;
0 commit comments