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

Add xdebug make command. #378

Merged
merged 3 commits into from
Jun 26, 2024
Merged

Add xdebug make command. #378

merged 3 commits into from
Jun 26, 2024

Conversation

alxp
Copy link
Contributor

@alxp alxp commented Feb 26, 2024

What does this pull request do?

Adds a 'make xdebug' command which installs xdebug temporarily (until make down; make up is run again) and places a minimal working xdebug.ini file in the php82 config filder.

How should this be teste>??

  1. Set up a 'local development environment to listen for xdebug connections on the default port for XDebug 3.x. Instructions for Visual Studio: Code are here: https://marketplace.visualstudio.com/items?itemName=xdebug.php-debug#:~:text=VS%20Code%20Configuration,by%20default%209003)%20for%20Xdebug.
  2. Run 'make xdebug'.
  3. Set a breakpoint in your IDE somewhere where you know the code will run, e.g., in index.php.
  4. Tell your IDE to start debugging
  5. Refresh a page on your ISLE-DC site.
    The breakpoint should stop code execution and you should be able to do all the usual things.

When you're done, run 'make down' and then ''make up'. XDebug should no longer be installed.

@alxp alxp marked this pull request as draft March 1, 2024 13:09
@alxp
Copy link
Contributor Author

alxp commented Mar 1, 2024

Converting this to draft because it has the gateway timeout problem that the code environment has.

Need to stuff in settings like this:

NGINX_CLIENT_BODY_TIMEOUT=3600s
NGINX_FASTCGI_CONNECT_TIMEOUT=3600s
NGINX_FASTCGI_READ_TIMEOUT=36000s
NGINX_FASTCGI_SEND_TIMEOUT=3600s
NGINX_KEEPALIVE_TIMEOUT=3600s
NGINX_LINGERING_TIMEOUT=3600s
NGINX_PROXY_CONNECT_TIMEOUT=3600s
NGINX_PROXY_READ_TIMEOUT=3600s
NGINX_PROXY_SEND_TIMEOUT=3600s
NGINX_SEND_TIMEOUT=3600s
PHP_DEFAULT_SOCKET_TIMEOUT=3600s
PHP_MAX_EXECUTION_TIME=3600s
PHP_POST_MAX_SIZE=1280M
PHP_PROCESS_CONTROL_TIMEOUT=3600s
PHP_REQUEST_TERMINATE_TIMEOUT=3600s
PHP_UPLOAD_MAX_FILESIZE=1280M

so want to figure out a way to do that just when the user runs make starter_ddev

@noahwsmith
Copy link
Contributor

@alxp
Copy link
Contributor Author

alxp commented Mar 1, 2024

It looks like I can also put them in https://github.com/Islandora-Devops/isle-dc/blob/development/build/docker-compose/docker-compose.drupal.yml

But I think we should maybe make these only get set to such big values if the user runs 'make starter_dev' as opposed to 'make starter'.

Will tinker more when I have some free time.

@alxp alxp marked this pull request as ready for review March 4, 2024 23:49
@alxp
Copy link
Contributor Author

alxp commented Mar 4, 2024

@seth-shaw-asu This is ready to test.

On a clean ISLE-DC,

$ cp sample-dev.env
$ make starter_dev
$ cp scripts/extra/launch.json .vscode
$ make xdebug

Then set a breakpoint in e.g. codebase/web/index.php, start debugging (F5 in VSCode) and laod any page.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@Natkeeran
Copy link
Contributor

@alxp

Testing this PR.

The php extension is installed. The config file gets installed properly. Able to launch the debug server/service via the launch.json. It says "Listening to Xdebug on port 0.0.0.0:9003 ...". I have the chrome plugin to set the xdebug cookie. However, the breakpoint does not get hit in the vs code.

Nothing in the xdebug log.

@rosiel
Copy link
Contributor

rosiel commented Mar 28, 2024

It works great on my mac. I used Intellij IDEA and threw a breakpoint in index.php and on "listening" mode it immediately caught the incoming xdebug connection. I didn't have to click the old "Start Debugger" bookmarklet. Neato!

rosiel
rosiel previously approved these changes Mar 28, 2024
@rosiel rosiel dismissed their stale review March 28, 2024 17:52

Found some problems.

@rosiel
Copy link
Contributor

rosiel commented Mar 28, 2024

The Xdebug part worked. But after running make down and make up, I get only Gateway Timeouts when trying to access the site.

That said, i didn't follow the steps outlined in @alxp's comment above, and just ran make xdebug on this branch.

@DonRichards
Copy link
Member

DonRichards commented Apr 10, 2024

@alxp To get it to work on my Ubuntu machine I had to make a couple of small modifications. This could be nothing and could be nothing but here's what I changed

  1. Switched the docker-compose to docker compose.
  2. Removed the trailing space char on the line -docker compose exec -T drupal with-contenv bash -lc "chown root:root /etc/php82/conf.d/xdebug.ini"
  3. Add a sleep delay after the drupal restart (this actually did cause me an issue).

Without the delay I get this error message

s6-envdir: fatal: unable to envdir /run/s6/container_environment: No such file or directory
make: *** [Makefile:671: xdebug] Error 111

And if you want it to come up with the make help command just add the description under the .PHONY. Here is what my code looks like with these changes.

.PHONY: xdebug
## Turn on xdebug.
xdebug:
	sleep 6
	docker compose exec -T drupal with-contenv bash -lc "apk add php82-pecl-xdebug"
	docker cp scripts/extra/xdebug.ini $$(docker compose ps -q drupal):/etc/php82/conf.d/xdebug.ini
	-docker compose exec -T drupal with-contenv bash -lc "chown root:root /etc/php82/conf.d/xdebug.ini"
	docker compose restart drupal
	sleep 6
	docker compose exec -T drupal with-contenv bash -lc "php -i | grep xdebug"

I'm not sure how else to test this. I don't personally use xdebug.

@alxp
Copy link
Contributor Author

alxp commented May 7, 2024

I googled a bit and learned that you can make 'host.docker.internal' work on Linux hosts by adding the following to the container definition in docker-compose:

``yaml
extra_hosts:

  • "host.docker.internal:host-gateway"

Source:  https://stackoverflow.com/questions/31324981/how-to-access-host-port-from-docker-container/61424570#61424570

I notice the tests seem to be failing and it looks like teh default NGinx gateway timeout when not in debug mode is too short.

<img width="1512" alt="image" src="https://github.com/Islandora-Devops/isle-dc/assets/82412/bb0f9c05-67d4-4271-a68e-49ed4857d736">


The part that's failing is when it tries to do a site config export in the Web UI, and the timeout happens before teh export can finish.

I'll come back to this, but in the mean time @DonRichards  you might have more luck running this on a Linux host.

Remember to follow the instructions in the README and copy scripts/extra/launch.json to your .vscode directory and launch VS code from the project root (not codebase).

@alxp
Copy link
Contributor Author

alxp commented Jun 2, 2024

I've re-rolled this with a much simpler approach.

There is now a make command that just sets all Nginx and PHP timeout values in the docker-compose.yml file and restarts docker, so the settings get picked up.

It then downloads and enables XDebug.

I've also added a default launch.json file that has XDebug commands correctly configured.

So to test:

  1. Start up an ISLE-DC site.
  2. Run make xdebug and wait for it to finish.
  3. Set a breakpoint e.g., in codebase/web/index.php
  4. Tell your IDE to listen for XDebug connections
  5. Load a page of your ISLE site.

This is worth trying again @DonRichards @rosiel @Natkeeran however the Linux version may need a tweaked XDebug.ini.

@alxp alxp force-pushed the xdebug branch 2 times, most recently from 23aca9a to ae7b620 Compare June 7, 2024 01:47
@rosiel rosiel requested a review from aOelschlager June 12, 2024 17:52
Copy link
Contributor

@aOelschlager aOelschlager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this on a Linux laptop and it worked for me! I just needed to download the PHP Debug extension in Visual Studio Code. I set a few breakpoints in index.php and ran Listen for Xdebug.

@aOelschlager aOelschlager merged commit 908ca60 into development Jun 26, 2024
1 check passed
@aOelschlager aOelschlager deleted the xdebug branch June 26, 2024 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants