Чтобы правильно выполнить мои тесты, я создаю образ Docker и запускаю его (слегка измененный контейнер MySQL). Поскольку я создаю контейнер из файла Dockerfile (а не только извлекаю его из реестра), я не использую возможности службы GitHub или контейнера (https://docs.github.com/en/actions/ use-cases-and-examples/using-containerized-services/about-service-containers).
Вместо этого в рабочем процессе GH у меня есть несколько шагов, посвященных созданию контейнера и его запуску, как это
Код: Выделить всё
- 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
Код: Выделить всё
- name: run the functional tests
run: python -m pytest tests/functional -vv -s --log-cli-level=DEBUG
Однако я изо всех сил пытаюсь взаимодействовать с Docker в этом контексте. Я хотел бы создать часть моих тестов mysqldump. Итак, я написал это в своих тестах:
Код: Выделить всё
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)
Код: Выделить всё
DEBUG root:my_test.py:246 CompletedProcess(args=['docker', 'version'], returncode=0, stdout=b'', stderr=b'\nUsage: docker [OPTIONS] COMMAND\n\nA self-sufficient runtime for containers\n\nCommon Commands:\n run Create and run a new container from an image\n exec Execute a command in a running container\n ps List containers\n build Build an image from a Dockerfile\n pull Download an image from a registry\n push Upload an image to a registry\n images List images\n login Log in to a registry\n logout Log out from a registry\n search Search Docker Hub for images\n version Show the Docker version information\n info Display system-wide information\n\nManagement Commands:\n builder Manage builds\n buildx* Docker Buildx\n compose* Docker Compose\n container Manage containers\n context Manage contexts\n image Manage images\n manifest Manage Docker image manifests and manifest lists\n network Manage networks\n plugin Manage plugins\n system Manage Docker\n trust Manage trust on Docker images\n volume Manage volumes\n\nSwarm Commands:\n swarm Manage Swarm\n\nCommands:\n attach Attach local standard input, output, and error streams to a running container\n commit Create a new image from a container\'s changes\n cp Copy files/folders between a container and the local filesystem\n create Create a new container\n diff Inspect changes to files or directories on a container\'s filesystem\n events Get real time events from the server\n export Export a container\'s filesystem as a tar archive\n history Show the history of an image\n import Import the contents from a tarball to create a filesystem image\n inspect Return low-level information on Docker objects\n kill Kill one or more running containers\n load Load an image from a tar archive or STDIN\n logs Fetch the logs of a container\n pause Pause all processes within one or more containers\n port List port mappings or a specific mapping for the container\n rename Rename a container\n restart Restart one or more containers\n rm Remove one or more containers\n rmi Remove one or more images\n save Save one or more images to a tar archive (streamed to STDOUT by default)\n start Start one or more stopped containers\n stats Display a live stream of container(s) resource usage statistics\n stop Stop one or more running containers\n tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE\n top Display the running processes of a container\n unpause Unpause all processes within one or more containers\n update Update configuration of one or more containers\n wait Block until one or more containers stop, then print their exit codes\n\nGlobal Options:\n --config string Location of client config files (default\n "/home/runner/.docker")\n -c, --context string Name of the context to use to connect to the\n daemon (overrides DOCKER_HOST env var and\n default context set with "docker context use")\n -D, --debug Enable debug mode\n -H, --host list Daemon socket to connect to\n -l, --log-level string Set the logging level ("debug", "info",\n "warn", "error", "fatal") (default "info")\n --tls Use TLS; implied by --tlsverify\n --tlscacert string Trust certs signed only by this CA (default\n "/home/runner/.docker/ca.pem")\n --tlscert string Path to TLS certificate file (default\n "/home/runner/.docker/cert.pem")\n --tlskey string Path to TLS key file (default\n "/home/runner/.docker/key.pem")\n --tlsverify Use TLS and verify the remote\n -v, --version Print version information and quit\n\nRun \'docker COMMAND --help\' for more information on a command.\n\nFor more help on how to use Docker, head to https://docs.docker.com/go/guides/\n')
Я не могу понять, почему я получаю этот вывод. Кажется, исполняемый файл Docker найден (поскольку я получаю страницу справки, как будто я выполнял неправильную команду), но он не будет выполняться так, как при локальном запуске теста.
Подробнее здесь: https://stackoverflow.com/questions/790 ... hub-runner