Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run arbitrary commands within the container #57

Open
g105b opened this issue Sep 18, 2023 · 5 comments
Open

Run arbitrary commands within the container #57

g105b opened this issue Sep 18, 2023 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@g105b
Copy link
Member

g105b commented Sep 18, 2023

Many CI workflows configure the workspace environment before executing. This Github Action works in a way that completely isolates the test runner from the environment, by running your tests in its own Docker container, sharing only the project source files.

It would be useful to run any arbitrary shell command within the container. This should probably be transferred to other php-actions too.

@antman3351
Copy link

Would it be possible to add a option like "BEFORE_RUN_CMD" and run it before the tests ? ( I was trying to add mysql-client to the container )

I tried to build a dockerfile and put the commands in but failed...

.... 
echo "FROM ${docker_tag}" > Dockerfile

if [ -n "$BEFORE_RUN_CMD" ]
then
  echo "RUN ${BEFORE_RUN_CMD}" >> Dockerfile
fi

echo "CMD ${command_string[@]}" >> Dockerfile

cat Dockerfile.ymal

docker build -t phpunit_container .

docker run --rm \
  --name phpunit \
	--volume "${phar_path}":/usr/local/bin/phpunit \
	--volume "${GITHUB_WORKSPACE}":/app \
	--workdir /app \
	--network host \
	--env-file <( env| cut -f1 -d= ) \
	phpunit_container

@g105b
Copy link
Member Author

g105b commented Sep 21, 2023

That idea is certainly on the right tracks. However I think it would be better to run something like MySQL in its own container so it can be managed in its own step - but then it would require the change here to be able to configure which ports are exposed to the PHPUnit container.

I have a feeling that the BEFORE_RUN_CMD idea might have issues, due to how the Dockerfile is built into a Package and stored on Github's container registry.

I will give it some thought!

@antman3351
Copy link

MySql server is in it's own container and that worked fine I just passed the ${{ job.services.mariadb.ports['3306'] }} to PHP via an environment variable and had no problems connecting from the PHP Unit container.
I need the mysql-client ( not server ) binary to be able to quickly restore the test DB multiple times during some tests without having to do it from PHP. e.g. mysql -h 127.0.0.1 -u root --password=root db_unittest < dump_unittest.sql

I'm clueless to how Github's container registry works, but another idea I pondered was delaying the execution of phpunit to allow commands to be executed before using docker exec -it <container name> sh -c "<command>"

@g105b
Copy link
Member Author

g105b commented Sep 22, 2023

Gotcha. I see the issue you're explaining. I'll look into how MySQL Client can be included in the PHP Alpine container, as it might just make sense to include it by default, seeing how close friends PHP and MySQL are. What do you think to that idea?

@antman3351
Copy link

Sounds good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Development

No branches or pull requests

2 participants