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

PHP / Psalm installed in docker container #176

Open
shaneparsons opened this issue Jun 21, 2022 · 5 comments
Open

PHP / Psalm installed in docker container #176

shaneparsons opened this issue Jun 21, 2022 · 5 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@shaneparsons
Copy link

I have php / psalm running in a docker container... I've tried various different config options trying to get this plugin to find psalm in that container, but there doesn't seem to be any support for such a workflow... Any ideas / tips? Anybody else have success with something similar?

@orklah
Copy link

orklah commented Jun 21, 2022

It shouldn't be an issue, if you run composer to install psalm, you should be able to use it as usual through vendor/bin/psalm

EDIT: sorry, didn't look at the repo name, I thought you were talking about Psalm itself. nevermind!

@weirdan
Copy link
Member

weirdan commented Jun 21, 2022

Psalm (including the language server) does work in container, however there's currently no support for mapping the paths between host machine and the container. There's a PR in the Psalm repo to address this: vimeo/psalm#8026

@tm1000
Copy link
Collaborator

tm1000 commented Jul 25, 2022

My team uses docker all day long. We actually execute and run psalm outside of the docker instance (so we use our local php binaries). This works well in our case and has been that way for the last 2 years we've been using psalm. We have about 4-5 developers working this way and don't experience issues.

The way the plugin itself works is through STDIO pipes but you can also configure it to connect through TCP however it binds to localhost and is assigned a random port. In TCP Mode vscode starts a language server and then tells Psalm to start with the --tcp option which tells Psalm to connect to said ip and port. If you setup docker correctly you could route the connection outward (so vscode starts the process then you tell psalm to connect to said process with the --tcp option). You'd also need to declare extra_hosts

EG:

    extra_hosts:
        - 'host.docker.internal:host-gateway'

With this set inside the docker container itself I am able to ping the host.

root@e50b0fd4c96e:/usr/local/app# ping host.docker.internal
PING host.docker.internal (172.17.0.1) 56(84) bytes of data.
64 bytes from host.docker.internal (172.17.0.1): icmp_seq=1 ttl=64 time=1.48 ms
64 bytes from host.docker.internal (172.17.0.1): icmp_seq=2 ttl=64 time=0.060 ms
64 bytes from host.docker.internal (172.17.0.1): icmp_seq=3 ttl=64 time=0.099 ms
64 bytes from host.docker.internal (172.17.0.1): icmp_seq=4 ttl=64 time=0.067 ms

This is how we get xdebug breaks to work.

Let me know if this is something you'd like as looking at the code it doesn't seem hard to achieve. We'd basically expose the ability to define the port and ip for both the server and the client ahead of time. In the ip for the client you'd set it to host.docker.internal which would turn into --tcp=host.docker.internal:<someport>

@tm1000 tm1000 self-assigned this Jul 25, 2022
@tm1000 tm1000 added enhancement New feature or request good first issue Good for newcomers labels Jul 25, 2022
@shaneparsons
Copy link
Author

Hey @tm1000, sorry for the delay. That sounds great though! similar to what https://github.com/plotbox-io/psalm-docker-vscode is doing actually.

In working to get the other plugin working in vscode I actually ran into some issues with the container not being able to see the outside, even though I was able to ping it just fine. I think it had to do with the port being randomized, so the ability to set the port would be great. You can actually read a lot about my setup / experience in this issue, if interested.

Currently my workflow is that I moved one of the smaller projects I work on locally, so that php exists on the system and I can use this plugin as is. But there are other bigger / older projects with different php versions that I can't easily do this with, so being able to use the containerized php would be awesome.

@weirdan
Copy link
Member

weirdan commented Apr 19, 2024

however there's currently no support for mapping the paths between host machine and the container.

There is now: vimeo/psalm#10033
This extension needs to allow specifying --map-folder flag for this to work in vscode though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants