@@ -29,6 +29,8 @@ function shouldPassEnvVarToDocker () {
2929}
3030
3131function buildDockerEnvVarsCommandLinePart () {
32+ # $1 should be the name of the environment variable to hold the result
33+ # local -n makes `result' reference to the variable named by $1
3234 local -n result=$1
3335 result=()
3436 # Iterate over environment variables
@@ -79,6 +81,8 @@ function onScriptExit () {
7981}
8082
8183function main () {
84+ local dockerToRunImageName=${1:? }
85+
8286 if [ -z " ${ELASTIC_APM_PHP_TESTS_MATRIX_ROW} " ] ; then
8387 echo " ELASTIC_APM_PHP_TESTS_MATRIX_ROW environment variable should be set before calling ${BASH_SOURCE[0]} "
8488 exit 1
@@ -96,12 +100,24 @@ function main () {
96100
97101 repoRootDir=" $( realpath " ${thisScriptDir} /.." ) "
98102
99- buildDockerEnvVarsCommandLinePart dockerRunCmdVariablePart
103+ buildDockerEnvVarsCommandLinePart dockerRunCmdLineArgs
104+
105+ # Let the tests know that are being run inside a container
106+ dockerRunCmdLineArgs=(" ${dockerRunCmdLineArgs[@]} " -e " ELASTIC_APM_PHP_TESTS_IS_IN_CONTAINER=true" )
107+
108+ # ELASTIC_APM_PHP_TESTS_THIS_CONTAINER_IMAGE_NAME is used by tests to find container ID
109+ dockerRunCmdLineArgs=(" ${dockerRunCmdLineArgs[@]} " -e " ELASTIC_APM_PHP_TESTS_THIS_CONTAINER_IMAGE_NAME=${dockerToRunImageName} " )
110+
100111 if [ " ${shouldStartExternalServices} " == " true" ] ; then
101- dockerRunCmdVariablePart =(" ${dockerRunCmdVariablePart [@]} " " --network=elastic-apm-php-external-services-for-component-tests-net" )
112+ dockerRunCmdLineArgs =(" ${dockerRunCmdLineArgs [@]} " " --network=elastic-apm-php-external-services-for-component-tests-net" )
102113 fi
103- # shellcheck disable=SC2154 # dockerRunCmdVariablePart is assigned by buildDockerEnvVarsCommandLinePart
104- docker run --rm -v " ${repoRootDir} :/app" -w /app " ${dockerRunCmdVariablePart[@]} " " $@ "
114+
115+ dockerRunCmdLineArgs=(" ${dockerRunCmdLineArgs[@]} " -v /var/run/docker.sock:/var/run/docker.sock)
116+ dockerRunCmdLineArgs=(" ${dockerRunCmdLineArgs[@]} " -v " ${repoRootDir} :/app" )
117+ dockerRunCmdLineArgs=(" ${dockerRunCmdLineArgs[@]} " -w /app)
118+
119+ # shellcheck disable=SC2154 # dockerRunCmdLineArgs is assigned by buildDockerEnvVarsCommandLinePart
120+ docker run --rm -w /app " ${dockerRunCmdLineArgs[@]} " " $@ "
105121}
106122
107123main " $@ "
0 commit comments