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

Fix Error: Could not process the 'wp-config.php' transformation #29800

Merged
merged 9 commits into from
Mar 12, 2021
31 changes: 29 additions & 2 deletions packages/env/lib/build-docker-compose-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,26 +176,41 @@ module.exports = function buildDockerComposeConfig( config ) {
image: 'mariadb',
ports: [ '3306' ],
environment: {
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes',
MYSQL_ROOT_PASSWORD: 'password',
MYSQL_DATABASE: 'wordpress',
},
volumes: [ 'mysql:/var/lib/mysql' ],
},
'tests-mysql': {
Copy link
Member

Choose a reason for hiding this comment

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

Not a big fan of adding an extra MySQL container. It will mean there's a lot of extra memory usage and startup time.

Copy link
Member

Choose a reason for hiding this comment

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

How about we keep to a single container and create two databases ourselves using wp db create?

https://developer.wordpress.org/cli/commands/db/create/

Copy link
Member

Choose a reason for hiding this comment

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

Could that be a follow-up task? It seems higher effort than the current approach

Copy link
Member

Choose a reason for hiding this comment

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

Yep absolutely.

Copy link
Contributor

Choose a reason for hiding this comment

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

How about using one database, and different table prefixes for dev and tests, respectively? The wordpress docker image supports a WORDPRESS_TABLE_PREFIX env variable for that purpose.

image: 'mariadb',
ports: [ '3306' ],
Copy link
Member

Choose a reason for hiding this comment

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

This port is already being used by the mysql container above.

Copy link
Member Author

@ribaricplusplus ribaricplusplus Mar 11, 2021

Choose a reason for hiding this comment

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

I think those ports just denote which ports are exposed within a container. Ports are isolated within individual containers, so if I'm not mistaken there should be no conflict.

EDIT: According to compose specification this short notation means that the port 3306 inside the container is going to be assigned an ephemeral port on the host machine. Still, that means there should be no trouble.

environment: {
MYSQL_ROOT_PASSWORD: 'password',
MYSQL_DATABASE: 'tests-wordpress',
},
volumes: [ 'mysql-test:/var/lib/mysql' ],
},
wordpress: {
build: '.',
depends_on: [ 'mysql' ],
image: developmentWpImage,
ports: [ developmentPorts ],
environment: {
WORDPRESS_DB_NAME: 'wordpress',
WORDPRESS_DB_USER: 'root',
WORDPRESS_DB_PASSWORD: 'password',
},
volumes: developmentMounts,
},
'tests-wordpress': {
depends_on: [ 'mysql' ],
depends_on: [ 'tests-mysql' ],
image: testsWpImage,
ports: [ testsPorts ],
environment: {
WORDPRESS_DB_NAME: 'tests-wordpress',
WORDPRESS_DB_USER: 'root',
WORDPRESS_DB_PASSWORD: 'password',
WORDPRESS_DB_HOST: 'tests-mysql',
},
volumes: testsMounts,
},
Expand All @@ -204,12 +219,23 @@ module.exports = function buildDockerComposeConfig( config ) {
image: developmentWpCliImage,
volumes: developmentMounts,
user: cliUser,
environment: {
WORDPRESS_DB_NAME: 'wordpress',
WORDPRESS_DB_USER: 'root',
WORDPRESS_DB_PASSWORD: 'password',
},
},
'tests-cli': {
depends_on: [ 'tests-wordpress' ],
image: testsWpCliImage,
volumes: testsMounts,
user: cliUser,
environment: {
WORDPRESS_DB_NAME: 'tests-wordpress',
WORDPRESS_DB_USER: 'root',
WORDPRESS_DB_PASSWORD: 'password',
WORDPRESS_DB_HOST: 'tests-mysql',
},
},
composer: {
image: 'composer',
noahtallen marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -235,6 +261,7 @@ module.exports = function buildDockerComposeConfig( config ) {
...( ! config.coreSource && { wordpress: {} } ),
...( ! config.coreSource && { 'tests-wordpress': {} } ),
mysql: {},
'mysql-test': {},
'phpunit-uploads': {},
},
};
Expand Down
21 changes: 21 additions & 0 deletions packages/env/lib/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,27 @@ module.exports = async function start( { spinner, debug, update, xdebug } ) {
: [],
} );

await dockerCompose.exec( 'wordpress', 'chown www-data:www-data wp-config.php', {
config: dockerComposeConfigPath,
log: debug,
} )

await dockerCompose.exec( 'wordpress', 'chmod 777 wp-config.php', {
config: dockerComposeConfigPath,
log: debug,
} )

await dockerCompose.exec( 'tests-wordpress', 'chown www-data:www-data wp-config.php', {
config: dockerComposeConfigPath,
log: debug,
} )

await dockerCompose.exec( 'tests-wordpress', 'chmod 777 wp-config.php', {
config: dockerComposeConfigPath,
log: debug,
} )


Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure that manually changing permissions for wp-config.php is the right fix, see discussion at #29770 😅

Copy link
Member Author

@ribaricplusplus ribaricplusplus Mar 11, 2021

Choose a reason for hiding this comment

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

I think you have a good point that configuration should be set idiomatically via docker-compose configuration.

However, I think it would still make sense to fix wp-config.php permissions, because currently wp-config.php is owned by root and so any commands that need to use the config for any reason would fail.

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

We've had to update permissions for some of these files to get them to work in wp-env before, so I'm not against it

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should use WORDPRESS_CONFIG_EXTRA because the wordpress image will only use that variable if wp-config.php doesn't already exist which isn't very flexible for developers. For example: you wouldn't be able to update WP_DEBUG in .wp-env.json, restart wp-env, and see WordPress running in debug mode.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should use WORDPRESS_CONFIG_EXTRA because the wordpress image will only use that variable if wp-config.php doesn't already exist

I'm not totally sure, but I think that's no longer true per docker-library/wordpress#557, which has wp-config.php read those values dynamically from the docker env (using a getenv() helper); see e.g.

// Only run WordPress install/configuration when config has changed.
if ( shouldConfigureWp ) {
spinner.text = 'Configuring WordPress.';
Expand Down