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 an option to configure site constants #14371

Merged
merged 6 commits into from
Mar 22, 2019

Conversation

gziolo
Copy link
Member

@gziolo gziolo commented Mar 11, 2019

Description

Replaces #12457 where it was expected to be able to update SCRIPT_DEBUG constant:

When I setup Gutenberg for local development, I'd expect it to load unminified files.

Takes out part of #13452 where it is necessary to be able to set WP_DEBUG constant.

This PR enables an option to make debugging WordPress easier with the existing Docker setup by providing env variables which reflect the same PHP constants used in WordPress:

  • WP_DEBUG
  • SCRIPT_DEBUG

See more at https://codex.wordpress.org/Debugging_in_WordPress.

Testing

To enable all available site constant variables run the following:

SCRIPT_DEBUG=true WP_DEBUG=true ./bin/setup-local-env.sh

To disable all available site constant variables run the following:

SCRIPT_DEBUG=false WP_DEBUG=false ./bin/setup-local-env.sh

@gziolo gziolo added [Status] In Progress Tracking issues with work in progress [Type] Build Tooling Issues or PRs related to build tooling labels Mar 11, 2019
@gziolo gziolo self-assigned this Mar 11, 2019
@gziolo
Copy link
Member Author

gziolo commented Mar 11, 2019

Yay, it works https://travis-ci.com/WordPress/gutenberg/jobs/183804711#L978-L978.

Thanks @aduth and @pento for inspiration how to tackle it :)

I will polish PR real quick and add missing description and docs.

@gziolo gziolo requested review from ellatrix and pento March 11, 2019 14:12
@gziolo gziolo force-pushed the update/docker-install-constants branch from aae4823 to 55bf396 Compare March 11, 2019 14:13
@gziolo gziolo removed the [Status] In Progress Tracking issues with work in progress label Mar 11, 2019
@gziolo gziolo added this to the 5.3 (Gutenberg) milestone Mar 11, 2019
.travis.yml Outdated Show resolved Hide resolved
@@ -90,6 +90,24 @@ if [ "$CURRENT_URL" != "http://localhost:$HOST_PORT" ]; then
docker-compose $DOCKER_COMPOSE_FILE_OPTIONS run --rm -u 33 $CLI option update siteurl "http://localhost:$HOST_PORT" --quiet
fi

# Configure site constants.
echo -e $(status_message "Configuring site constants...")
Copy link
Member Author

Choose a reason for hiding this comment

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

There is a lot of code duplication here. Commits which simplify it are warmly welcomed :)

Copy link
Contributor

Choose a reason for hiding this comment

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

We could use macro-like behaviour with the following:

$ A=hello; B=salut
$ VAR=A; eval echo \$$VAR
hello
$ VAR=B; eval echo \$$VAR
salut

@gziolo gziolo requested review from mcsf and oandregal March 12, 2019 11:19
@ellatrix
Copy link
Member

Why don't we just enable them by default?

@gziolo
Copy link
Member Author

gziolo commented Mar 12, 2019

e2e tests will fail, there are still React warnings coming from class methods which are marked as deprecated in the strict mode :(

@ellatrix
Copy link
Member

Maybe we can add an alternative command that includes these, in package.json?

@ellatrix
Copy link
Member

Just saying that when I'm setting up Gutenberg locally, I use it for development purposes. Sounds like we'd benefit from a less verbose setup command.

@gziolo
Copy link
Member Author

gziolo commented Mar 12, 2019

Feel free to add some changes to this PR if you have some ideas. I just wanted to be able to use SCRIPT_DEBUG myself :) In addition, @aduth wants to enable WP_DEBUG so we could catch PHP errors produced by plugin.

@aduth
Copy link
Member

aduth commented Mar 12, 2019

e2e tests will fail, there are still React warnings coming from class methods which are marked as deprecated in the strict mode :(

Is it reasonable to just override those temporarily for the end-to-end tests, to disable the script debug?

@gziolo
Copy link
Member Author

gziolo commented Mar 12, 2019

Is it reasonable to just override those temporarily for the end-to-end tests, to disable the script debug?

I think it makes a lot of sense. It didn't occur to me before :)

CONTRIBUTING.md Outdated Show resolved Hide resolved
@gziolo gziolo force-pushed the update/docker-install-constants branch from 7a1992c to 45b7fdf Compare March 14, 2019 15:18
@gziolo
Copy link
Member Author

gziolo commented Mar 14, 2019

I'm seeing the following on Travis:

Error: The constant 'WP_DEBUG_DISPLAY' is not defined in the 'wp-config.php' file.
The command "./bin/setup-local-env.sh" failed and exited with 1 during .

I added a commit which removed the change for WP_DEBUG_DISPLAY: 0eb93b6. It looks like this is a limitation of WP CLI as of today:
https://stackoverflow.com/questions/35711003/wp-cli-toggle-wp-debug/49105953#comment91168718_49105953

@gziolo
Copy link
Member Author

gziolo commented Mar 14, 2019

Hmmm, it's also being reported for SCRIPT_DEBUG:

Error: The constant 'SCRIPT_DEBUG' is not defined in the 'wp-config.php' file.

I plan to investigate whether we can set those constants inside Docker as explained in docker-library/wordpress#142.

@youknowriad youknowriad removed this from the 5.3 (Gutenberg) milestone Mar 18, 2019
@@ -1,6 +1,8 @@
#!/usr/bin/env bash

WP_VERSION=${WP_VERSION-latest}
WP_DEBUG=${WP_DEBUG-true}
Copy link
Member

Choose a reason for hiding this comment

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

Possible thought on the error: Is this the correct syntax for assigning the default? Is the colon : not required?

See:

Copy link
Member

Choose a reason for hiding this comment

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

Also a bit curious why we don't use a .env file: https://docs.docker.com/compose/env-file/

Copy link
Member Author

Choose a reason for hiding this comment

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

I followed other occurrences in the file. I think it works correctly, although I personally don't know which syntax would be preferred.

The issue was caused by the fact that PHP didn't have those constants defined and WP CLI's implementation is limited to updating existing constants ... c34d3c0 fixes it.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, re-reading the above document, the colon behavior is explained:

Omitting the colon results in a test only for a parameter that is unset. Put another way, if the colon is included, the operator tests for both parameter’s existence and that its value is not null; if the colon is omitted, the operator tests only for existence.

I expect it should be fine.

Copy link
Member

Choose a reason for hiding this comment

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

The issue was caused by the fact that PHP didn't have those constants defined and WP CLI's implementation is limited to updating existing constants ... c34d3c0 fixes it.

So, to clarify, despite the fact that in c34d3c0 you're hard-coding the constants, bin/install-wordpress.sh will subsequently update them according to the value of the environment variable? And it has to be hard-coded because otherwise WP-CLI will refuse to update them (as they don't otherwise exist in the file)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this is complex to explain but correct. Each constant needs to be defined in wp-config.php if we want to be able to update it with WP-CLI.

@gziolo gziolo force-pushed the update/docker-install-constants branch from cb9b766 to c34d3c0 Compare March 19, 2019 08:45
@gziolo
Copy link
Member Author

gziolo commented Mar 19, 2019

It works with the latest changes applied. I think this is an improvement over what we had before so I would be happy if we could land it after some testing.

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

This all looks reasonable, but I'm struggling with the previously-noted error in my own environment.

Stopping / removing all existing containers, then running ./bin/setup-local-env.sh, I see:

⇒ docker-compose down
⇒ ./bin/setup-local-env.sh
# ...
Error: The constant 'SCRIPT_DEBUG' is not defined in the 'wp-config.php' file.

Am I missing something, or can you think of some reason why the new environment values specified in docker-compose.yml might not take effect in my environment (would others expect to encounter similar)?

@@ -1,6 +1,8 @@
#!/usr/bin/env bash

WP_VERSION=${WP_VERSION-latest}
WP_DEBUG=${WP_DEBUG-true}
Copy link
Member

Choose a reason for hiding this comment

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

Ah, re-reading the above document, the colon behavior is explained:

Omitting the colon results in a test only for a parameter that is unset. Put another way, if the colon is included, the operator tests for both parameter’s existence and that its value is not null; if the colon is omitted, the operator tests only for existence.

I expect it should be fine.

@@ -1,6 +1,8 @@
#!/usr/bin/env bash

WP_VERSION=${WP_VERSION-latest}
WP_DEBUG=${WP_DEBUG-true}
Copy link
Member

Choose a reason for hiding this comment

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

The issue was caused by the fact that PHP didn't have those constants defined and WP CLI's implementation is limited to updating existing constants ... c34d3c0 fixes it.

So, to clarify, despite the fact that in c34d3c0 you're hard-coding the constants, bin/install-wordpress.sh will subsequently update them according to the value of the environment variable? And it has to be hard-coded because otherwise WP-CLI will refuse to update them (as they don't otherwise exist in the file)?

@gziolo
Copy link
Member Author

gziolo commented Mar 20, 2019

Am I missing something, or can you think of some reason why the new environment values specified in docker-compose.yml might not take effect in my environment (would others expect to encounter similar)?

No idea to be honest. It looks similar to the error we had on Travis before c34d3c0 was added. I personally restarted Docker to test it locally.

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

While I'm not able to test it, I strongly suspect my issues are local, and I'd not want to be the reason for this being blocked. Otherwise, everything appears in good order here. I might offer it that another person test it, though am comfortable with it being merged if you're confident about it.

@gziolo
Copy link
Member Author

gziolo commented Mar 21, 2019

I will restart Docker and try locally again before I merge tomorrow, thanks for your review 💯

@gziolo gziolo merged commit 2ebc98e into master Mar 22, 2019
@gziolo gziolo deleted the update/docker-install-constants branch March 22, 2019 08:04
@gziolo
Copy link
Member Author

gziolo commented Mar 22, 2019

I tested locally after system restarted. Everything works as expected.

@aduth
Copy link
Member

aduth commented Apr 5, 2019

e2e tests will fail, there are still React warnings coming from class methods which are marked as deprecated in the strict mode :(

I created a follow-up task at #14845

@gziolo
Copy link
Member Author

gziolo commented Apr 5, 2019

Thanks @aduth!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Build Tooling Issues or PRs related to build tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants