Skip to content

Use host networking to access services on the host or in service containers #29

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

Merged
merged 1 commit into from
May 29, 2021
Merged

Use host networking to access services on the host or in service containers #29

merged 1 commit into from
May 29, 2021

Conversation

osma
Copy link
Contributor

@osma osma commented May 25, 2021

This PR adds a --network host argument to the docker run command that executes PHPUnit within its own container. This way, the container is not bound to the default bridge network (where it is in practice isolated from other containers and the host system in terms of networking) but instead stays on the host network. It can access services running on the host (e.g. a MySQL daemon). If service containers are used, they can also be accessed as long as their ports are exposed to the host machine using a ports declaration.

See #28 for some background.

I've tested this using my own fork osma/phpunit and it works in my case (accessing a Fuseki service on the host machine). If you want to try it out you can use it like this:

    - name: Run PHPUnit tests
      uses: osma/phpunit@v2-network-host

Fixes #28
Fixes #26 (probably)

@g105b
Copy link
Member

g105b commented May 26, 2021

Hi @osma,

This is great, thanks! I can't see any issue with this really in terms of opening up networks to other things, because if it weren't for needing to run a pre-built PHP image, we would be running PHPUnit within the Action Runner itself anyway.

I will test what you've done in https://github.com/php-actions/example-phpunit to make sure existing tests aren't affected for some reason, but on the whole this looks really positive and I'm very thankful for your input.

Greg.

@g105b g105b merged commit 91ff02a into php-actions:master May 29, 2021
@osma
Copy link
Contributor Author

osma commented May 31, 2021

Thanks for merging @g105b ! Any chance of tagging a new release so that this version can be used with the uses keyword from other Actions?

@osma
Copy link
Contributor Author

osma commented Jun 3, 2021

Ah, I realized it's possible to use uses with a specific commit id, so I did this instead:

uses: php-actions/phpunit@91ff02a58932e63741157ea8c04e7e7077233537

Anyway a fresh tagged release (perhaps just moving the v2 tag a little?) would be nice.

@g105b
Copy link
Member

g105b commented Jun 3, 2021

Hi @osma ,

I'm planning on making a new release with your changes - there's another improvement I'd like to finish with the PHP build system and then I'll release a v3 soon.

By the way, you can also do uses: php-actions/phpunit@master or any other branch name.

Cheers,
Greg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Cannot access local network services from the PHPUnit container Error:SQLSTATE[HY000] [2002] No such file or directory
2 participants