Skip to content

Allowing root user for wp-env #76564

@Saggre

Description

@Saggre

Hi! 👋

Firstly, thanks for your work on this project! 🙂

I am also using GitLab CI like this person: #69864

Because my GitLab runner runs as root, I need to use a hacky solution, like below, to get wp-env to work with root. I wish there was a way to allow root via wp-env.json or via a cli flag.

Here is the diff that solved my problem:

diff --git a/node_modules/@wordpress/env/lib/runtime/docker/build-docker-compose-config.js b/node_modules/@wordpress/env/lib/runtime/docker/build-docker-compose-config.js
index 735f0c6..4234601 100644
--- a/node_modules/@wordpress/env/lib/runtime/docker/build-docker-compose-config.js
+++ b/node_modules/@wordpress/env/lib/runtime/docker/build-docker-compose-config.js
@@ -225,6 +225,7 @@ module.exports = function buildDockerComposeConfig( config ) {
 				...dbEnv.credentials,
 				...dbEnv.development,
 				WP_TESTS_DIR: '/wordpress-phpunit',
+				WP_CLI_ALLOW_ROOT: '1',
 			},
 			volumes: developmentMounts,
 			extra_hosts: [ 'host.docker.internal:host-gateway' ],
@@ -242,6 +243,7 @@ module.exports = function buildDockerComposeConfig( config ) {
 				...dbEnv.credentials,
 				...dbEnv.development,
 				WP_TESTS_DIR: '/wordpress-phpunit',
+				WP_CLI_ALLOW_ROOT: '1',
 			},
 			extra_hosts: [ 'host.docker.internal:host-gateway' ],
 		},
@@ -303,6 +305,7 @@ module.exports = function buildDockerComposeConfig( config ) {
 				...dbEnv.credentials,
 				...dbEnv.tests,
 				WP_TESTS_DIR: '/wordpress-phpunit',
+				WP_CLI_ALLOW_ROOT: '1',
 			},
 			volumes: testsMounts,
 			extra_hosts: [ 'host.docker.internal:host-gateway' ],
@@ -320,6 +323,7 @@ module.exports = function buildDockerComposeConfig( config ) {
 				...dbEnv.credentials,
 				...dbEnv.tests,
 				WP_TESTS_DIR: '/wordpress-phpunit',
+				WP_CLI_ALLOW_ROOT: '1',
 			},
 			extra_hosts: [ 'host.docker.internal:host-gateway' ],
 		};

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions