I am running functional tests as CI in my GitHub runner.
To properly execute my tests, I am building a docker image and running it (a slightly modified mysql container). Because I am building the container from a Dockerfile (not only pulling it from a registry), I dont use GitHub service
or container
capabilities (https://docs.github.com/en/actions/use-cases-and-examples/using-containerized-services/about-service-containers).
Instead I have some steps dedicated in my GH workflow to build the container and run it like this
- name: build docker container
run: |
cd tests/functional/olbp/mocked_data/
docker build --no-cache -f my_service.Dockerfile -t my_service_test:latest .
- name: run container
run: docker run --name my_service -d -p 127.0.0.1:3306:3306 my_service_test --sql_mode="NO_ENGINE_SUBSTITUTION"
- name: wait for MySQL to start
run: |
until mysqladmin ping -h 127.0.0.1 --silent; do
echo 'Waiting for MySQL to start...'
sleep 1
done
Finally I am calling my functional tests (pytest) with python
- name: run the functional tests
run: python -m pytest tests/functional -vv -s --log-cli-level=DEBUG
This is working fine, my tests can obvisouly interract with the mysql container.
However I am struggling to interract with Docker in this context. I would like to generate a mysqldump part of my tests. So I wrote this inside my tests:
dck_exc_output = subprocess.run(
[
"docker",
"exec",
"my_service",
"mysqldump",
"--skip-triggers",
"--skip-extended-insert",
"--compact",
"--no-create-info",
"-uroot",
"-psupersecret",
"my_db",
"my_table",
">",
live_data_dump,
],
capture_output=True,
shell=True,
)
logging.debug(dck_exc_output)
It is working fine when being executed from my computer but whenever I try to get this executed inside the GH Runner (this docker command or even a simple docker version). I end up on this output:
DEBUG root:my_test.py:246 CompletedProcess(args=['docker', 'version'], returncode=0, stdout=b'', stderr=b'nUsage: docker [OPTIONS] COMMANDnnA self-sufficient runtime for containersnnCommon Commands:n run Create and run a new container from an imagen exec Execute a command in a running containern ps List containersn build Build an image from a Dockerfilen pull Download an image from a registryn push Upload an image to a registryn images List imagesn login Log in to a registryn logout Log out from a registryn search Search Docker Hub for imagesn version Show the Docker version informationn info Display system-wide informationnnManagement Commands:n builder Manage buildsn buildx* Docker Buildxn compose* Docker Composen container Manage containersn context Manage contextsn image Manage imagesn manifest Manage Docker image manifests and manifest listsn network Manage networksn plugin Manage pluginsn system Manage Dockern trust Manage trust on Docker imagesn volume Manage volumesnnSwarm Commands:n swarm Manage SwarmnnCommands:n attach Attach local standard input, output, and error streams to a running containern commit Create a new image from a container's changesn cp Copy files/folders between a container and the local filesystemn create Create a new containern diff Inspect changes to files or directories on a container's filesystemn events Get real time events from the servern export Export a container's filesystem as a tar archiven history Show the history of an imagen import Import the contents from a tarball to create a filesystem imagen inspect Return low-level information on Docker objectsn kill Kill one or more running containersn load Load an image from a tar archive or STDINn logs Fetch the logs of a containern pause Pause all processes within one or more containersn port List port mappings or a specific mapping for the containern rename Rename a containern restart Restart one or more containersn rm Remove one or more containersn rmi Remove one or more imagesn save Save one or more images to a tar archive (streamed to STDOUT by default)n start Start one or more stopped containersn stats Display a live stream of container(s) resource usage statisticsn stop Stop one or more running containersn tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGEn top Display the running processes of a containern unpause Unpause all processes within one or more containersn update Update configuration of one or more containersn wait Block until one or more containers stop, then print their exit codesnnGlobal Options:n --config string Location of client config files (defaultn "/home/runner/.docker")n -c, --context string Name of the context to use to connect to then daemon (overrides DOCKER_HOST env var andn default context set with "docker context use")n -D, --debug Enable debug moden -H, --host list Daemon socket to connect ton -l, --log-level string Set the logging level ("debug", "info",n "warn", "error", "fatal") (default "info")n --tls Use TLS; implied by --tlsverifyn --tlscacert string Trust certs signed only by this CA (defaultn "/home/runner/.docker/ca.pem")n --tlscert string Path to TLS certificate file (defaultn "/home/runner/.docker/cert.pem")n --tlskey string Path to TLS key file (defaultn "/home/runner/.docker/key.pem")n --tlsverify Use TLS and verify the remoten -v, --version Print version information and quitnnRun 'docker COMMAND --help' for more information on a command.nnFor more help on how to use Docker, head to https://docs.docker.com/go/guides/n')
I already confirmed that I have same user, same permission and same env variable between the subprocess and the GH runner commands.
I cannot understand why I am receiving this output. The docker executable seems to be found (because I am receiving the helppage as if I was executing a wrong command) but it will not execute as it is doing when I run the test locally.
1