@@ -20,27 +20,29 @@ HOST_HTTPPORT="${HOST_HTTPPORT:-80}"
2020HOST_HTTPSPORT=" ${HOST_HTTPSPORT:- 443} "
2121HOST_PROXYPORT=" ${HOST_PROXYPORT:- 8080} "
2222
23+ CONTAINER_INSTALL_ON_START=" ${CONTAINER_INSTALL_ON_START:- true} "
2324CONTAINER_NAME_PREFIX=" ${CONTAINER_NAME_PREFIX:- phpxmlrpc} "
2425CONTAINER_IMAGE_PREFIX=" ${CONTAINER_IMAGE_PREFIX:- phpxmlrpc_} "
2526CONTAINER_USER=docker
2627CONTAINER_WORKSPACE_DIR=" /home/${CONTAINER_USER} /workspace"
2728
28- ROOT_DIR=" $( dirname -- " $( dirname -- " $( dirname -- " $( readlink -f " $0 " ) " ) " ) " ) "
2929IMAGE_NAME=" ${CONTAINER_NAME_PREFIX} :${UBUNTU_VERSION} -${PHP_VERSION} "
3030CONTAINER_NAME=" ${CONTAINER_IMAGE_PREFIX}${UBUNTU_VERSION} _${PHP_VERSION} "
3131
32+ ROOT_DIR=" $( dirname -- " $( dirname -- " $( dirname -- " $( readlink -f " $0 " ) " ) " ) " ) "
33+
3234cd " $( dirname -- " $( readlink -f " $0 " ) " ) "
3335
3436help () {
3537 printf " Usage: vm.sh [OPTIONS] ACTION [OPTARGS]
3638
37- Manages the Test Environment Docker Container
39+ Manages the Test Environment ( Docker Container)
3840
3941Commands:
4042 build build or rebuild the container image with the test env
4143 cleanup remove the container and its image
42- enter start a shell session in the container
43- exec [\$ command] runs a single command in the container
44+ enter start a shell session in the running container
45+ exec [\$ command] run a single command in the running container
4446 inspect
4547 logs
4648 port
@@ -58,14 +60,15 @@ Options:
5860 -h print help
5961
6062Environment variables:
61- to be set before the 'build' action
63+ used by the 'build' action
6264 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
6365 UBUNTU_VERSION default value: jammy. Other possible values: xenial, bionic, focal, noble
64- to be set before the 'start' action
66+ used by the 'start' action
6567 HOST_HTTPPORT default value: 80. Set to 'no' not to publish the container's http port to the host
6668 HOST_HTTPSPORT default value: 443. Set to 'no' not to publish the container's https port to the host
6769 HOST_PROXYPORT default value: 8080. Set to 'no' not to publish the container's proxy http port to the host
68- to be set before the 'runtests' and 'runcoverage' actions:
70+ CONTAINER_INSTALL_ON_START default value: true. Change to avoid having Composer be run at the start of the Container
71+ used by the 'runtests' and 'runcoverage' actions:
6972 HTTPSVERIFYHOST 0, 1 or 2. Default and recommended: 0
7073 HTTPSIGNOREPEER 0 or 1. Default and recommended: 1
7174 SSLVERSION 0 (auto), 2 (SSLv2) to 7 (tls 1.3). Default: 0
@@ -97,21 +100,21 @@ build() {
97100 if [ " $1 " = ' -r' ]; then
98101 # stop and remove existing containers built from a previous version of this image
99102 if docker inspect " ${CONTAINER_NAME} " > /dev/null 2> /dev/null; then
100- stop
103+ stop -q
101104 docker rm " ${CONTAINER_NAME} "
102105 fi
103106 fi
104107 fi
105108}
106109
107110start () {
108- if [ " $( docker inspect --format ' {{.State.Status}}' ${CONTAINER_NAME} 2> /dev/null) " = running ]; then
109- # @todo we should check that the env vars have not changed, and give a warning if so
111+ if [ " $( docker inspect --format ' {{.State.Status}}' " ${CONTAINER_NAME} " 2> /dev/null) " = running ]; then
112+ # @todo we should check that the env vars have not changed, and give a warning if so. Doable using `docker container cp`...
110113 echo " ${CONTAINER_NAME} already started..."
111114 else
112115 if docker inspect " ${CONTAINER_NAME} " > /dev/null 2> /dev/null; then
113116 echo " starting existing container ${CONTAINER_NAME} ..."
114- # @todo we should check that the env vars have not changed, and give a warning if so. Doable using `inspect`...
117+ # @todo we should check that the env vars have not changed, and give a warning if so. Doable using `docker container inspect`...
115118 if docker start " ${CONTAINER_NAME} " ; then
116119 wait_for_bootstrap
117120 fi
@@ -129,11 +132,13 @@ start() {
129132 if [ " $HOST_PROXYPORT " != no ] && [ " $HOST_PROXYPORT " != ' ' ]; then
130133 PORTMAPPING=" -p $(( HOST_PROXYPORT- 0 )) :8080 "
131134 fi
135+ # @todo map the composer cache dir to a host folder, to speed up reinstalls
132136 if docker run -d \
133137 $PORTMAPPING \
134138 --name " ${CONTAINER_NAME} " \
135139 --env " CONTAINER_USER_UID=$( id -u) " --env " CONTAINER_USER_GID=$( id -g) " \
136140 --env " TESTS_ROOT_DIR=${CONTAINER_WORKSPACE_DIR} " \
141+ --env " INSTALL_ON_START=${CONTAINER_INSTALL_ON_START} " \
137142 --env HTTPSERVER=localhost \
138143 --env HTTPURI=/tests/index.php? demo=server/server.php \
139144 --env HTTPSSERVER=localhost \
@@ -148,11 +153,15 @@ start() {
148153}
149154
150155stop () {
151- if [ " $( docker inspect --format ' {{.State.Status}}' ${CONTAINER_NAME} 2> /dev/null) " = exited ]; then
152- echo " ${CONTAINER_NAME} already stopped"
156+ if [ " $( docker inspect --format ' {{.State.Status}}' " ${CONTAINER_NAME} " 2> /dev/null) " = exited ]; then
157+ if [ " $1 " != -q ]; then
158+ echo " ${CONTAINER_NAME} already stopped"
159+ fi
153160 else
154161 if docker inspect " ${CONTAINER_NAME} " > /dev/null 2> /dev/null; then
155- echo " stopping ${CONTAINER_NAME} ..."
162+ if [ " $1 " != -q ]; then
163+ echo " stopping ${CONTAINER_NAME} ..."
164+ fi
156165 docker stop " ${CONTAINER_NAME} "
157166 fi
158167 fi
@@ -166,7 +175,7 @@ case "${ACTION}" in
166175
167176 cleanup)
168177 if docker inspect " ${CONTAINER_NAME} " > /dev/null 2> /dev/null; then
169- docker stop " ${CONTAINER_NAME} "
178+ stop -q
170179 docker rm " ${CONTAINER_NAME} "
171180 fi
172181 docker rmi " ${IMAGE_NAME} "
@@ -201,30 +210,38 @@ case "${ACTION}" in
201210 ;;
202211
203212 runcoverage)
204- if [ " $( docker inspect --format ' {{.State.Status}}' ${CONTAINER_NAME} 2> /dev/null) " != running ]; then
213+ if [ " $( docker inspect --format ' {{.State.Status}}' " ${CONTAINER_NAME} " 2> /dev/null) " != running ]; then
205214 start
206215 fi
207216 test -t 1 && USE_TTY=" -t"
208- # @todo clean up /tmp/phpxmlrpc and .phpunit.result.cache
209- # @todo run composer install if it was not yet run or we are asked to
210- if [ ! -d build ]; then mkdir build; fi
211- docker exec -t " ${CONTAINER_NAME} " " ${CONTAINER_WORKSPACE_DIR} /tests/ci/setup/setup_code_coverage.sh" enable
217+ # @todo clean up /tmp/phpxmlrpc (in setup_code_coverage.sh?) and possibly .phpunit.result.cache
218+ # run composer install if it was not yet run
219+ if [ ! -f ../../composer.lock ] || [ ! -d ../../vendor ]; then
220+ # @todo do not swallow _all_ composer errors - just stuff such as an abandoned package
221+ docker exec $USE_TTY " ${CONTAINER_NAME} " /root/setup/setup_app.sh " ${CONTAINER_WORKSPACE_DIR} " || true
222+ fi
223+ if [ ! -d ./var/coverage ]; then mkdir -p ./var/coverage; fi
224+ docker exec -t " ${CONTAINER_NAME} " " /root/setup/setup_code_coverage.sh" enable
212225 docker exec -i $USE_TTY \
213226 --env " HTTPSVERIFYHOST=${HTTPSVERIFYHOST} " \
214227 --env " HTTPSIGNOREPEER=${HTTPSIGNOREPEER} " \
215228 --env " SSLVERSION=${SSLVERSION} " \
216229 --env DEBUG=" ${DEBUG} " \
217- " ${CONTAINER_NAME} " su " ${CONTAINER_USER} " -c " ./vendor/bin/phpunit --coverage-html build /coverage -v tests"
218- docker exec -t " ${CONTAINER_NAME} " " ${CONTAINER_WORKSPACE_DIR} /tests/ci /setup/setup_code_coverage.sh" disable
230+ " ${CONTAINER_NAME} " su " ${CONTAINER_USER} " -c " ./vendor/bin/phpunit --coverage-html tests/ci/var /coverage -v tests"
231+ docker exec -t " ${CONTAINER_NAME} " " /root /setup/setup_code_coverage.sh" disable
219232 ;;
220233
221234 runtests)
222- if [ " $( docker inspect --format ' {{.State.Status}}' ${CONTAINER_NAME} 2> /dev/null) " != running ]; then
235+ if [ " $( docker inspect --format ' {{.State.Status}}' " ${CONTAINER_NAME} " 2> /dev/null) " != running ]; then
223236 start
224237 fi
225238 test -t 1 && USE_TTY=" -t"
226- # @todo clean up /tmp/phpxmlrpc and .phpunit.result.cache
227- # @todo run composer install if it was not yet run or we are asked to
239+ # @todo clean up .phpunit.result.cache?
240+ # run composer install if it was not yet run
241+ if [ ! -f ../../composer.lock ] || [ ! -d ../../vendor ] ; then
242+ # @todo do not swallow _all_ composer errors - just stuff such as an abandoned package
243+ docker exec $USE_TTY " ${CONTAINER_NAME} " /root/setup/setup_app.sh " ${CONTAINER_WORKSPACE_DIR} " || true
244+ fi
228245 docker exec -i $USE_TTY \
229246 --env " HTTPSVERIFYHOST=${HTTPSVERIFYHOST} " \
230247 --env " HTTPSIGNOREPEER=${HTTPSIGNOREPEER} " \
0 commit comments