Open igorradovanov opened 3 years ago
I've tried the same command and I saw the same error.
I'm using wp-env version 4.0.5
.
$ wp-env run cli package install 10up/mu-migration
ℹ Starting 'package install 10up/mu-migration' on the cli container.
Creating d0b5cd3d272c8fd42f784483dc906a37_cli_run ... done
Error: Composer directory '/etc/X11/fs/.wp-cli/packages' for packages couldn't be created: mkdir(): Permission denied
ERROR: 1
✖ Command failed with exit code 1
Command failed with exit code 1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
And I think there is no directory.
% wp-env run cli "ls -la /etc/X11"
Creating d0b5cd3d272c8fd42f784483dc906a37_cli_run ... done
ls: /etc/X11: No such file or directory
ERROR: 1
✖ Command failed with exit code 1
Command failed with exit code 1
Probably the wp package
command has not supported in the container yet.
One solution could be to change the packages directory to a writable path by setting the environment variable WP_CLI_PACKAGES_DIR
- https://developer.wordpress.org/cli/commands/package/install/
It looks like though there is no way to set new environment variables when setting up the docker-compose - https://github.com/WordPress/gutenberg/blob/b332c75bd291b3bd2087b7a0d50ab172a5803970/packages/env/lib/build-docker-compose-config.js#L222-L225
Is it possible to inject value like this?
docker-compose run -e DEBUG=1 web python console.py
I could install the extension by setting the env variable like above by directly accessing docker-compose
> $ docker-compose -f /Users/Nik/.wp-env/9c90d286a625a650e4f4ef94e6a9344b/docker-compose.yml run -e WP_CLI_PACKAGES_DIR=.wp-cli --rm cli wp package install 10up/mu-migration
Creating 9c90d286a625a650e4f4ef94e6a9344b_cli_run ... done
Installing package 10up/mu-migration (dev-master)
Updating /var/www/html/.wp-cli/composer.json to require the package...
Using Composer to install the package...
---
Loading composer repositories with package information
Updating dependencies
Generating rules
Resolving dependencies through SAT
Looking at all rules.
Something's changed, looking at all rules again (pass #1)
Dependency resolution completed in 0.006 seconds
Analyzed 838 packages to resolve dependencies
Analyzed 908 rules to resolve dependencies
Nothing to modify in lock file
Installing dependencies from lock file
Nothing to install, update or remove
Generating autoload files
4 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
---
Success: Package installed.
But the same did not work when trying the wp-env
command wrapper -
> $ npm run env-run cli -e WP_CLI_PACKAGES_DIR=.wp-cli wp package install anhskohbo/wp-cli-themecheck
> astra@3.6.1 env-run /Users/Nik/Projects/wpcore/app/public/wp-content/themes/astra
> wp-env run "cli" "WP_CLI_PACKAGES_DIR=.wp-cli" "wp" "package" "install" "anhskohbo/wp-cli-themecheck"
ℹ Starting 'WP_CLI_PACKAGES_DIR=.wp-cli wp package install anhskohbo/wp-cli-themecheck' on the cli container.
Notice it misses the -e
when actually running the command. I debugged and this is not received by the run command. I wonder if this needs to be escaped someway.
To fix this I think wp-env
can set the WP_CLI_PACKAGES_DIR
from docker-compose.yml
(maybe /var/www/html/.wp-cli
?)
Also, maybe it would be nice to add more environment variables from .wp-env.json
? so that in similar edge cases the environment can be customised to fix the issues?
@Nikschavan agree — passing custom environment variables via .wp-env.json
should be possible. Not only for the WP CLI packages problem
Wondering if a PR would be accepted for adding such a capability
Has anyone figured out a solution to this? I tried putting quotation marks around the run command with an -e flag for WP_CLI_PACKAGES_DIR but it just hangs on creating the container.
npm run wp-env run cli "-e WP_CLI_PACKAGES_DIR=/custom/dir wp package install git@github.com:nlemoine/wp-cli-fixtures.git"
Description
wp-env Docker environment is unable to install new WordPress CLI packages due to a permission denied issue.
Step-by-step reproduction instructions
Expected behaviour
The package should be installed and ready to be used via WordPress CLI.
Actual behaviour
An error occurs: Error: Composer directory '/etc/X11/fs/.wp-cli/packages' for packages couldn't be created: mkdir(): Permission denied
Screenshots or screen recording (optional)
WordPress information
Device information