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

wp-env - Unable to install WordPress CLI Packages #32784

Open
igorradovanov opened this issue Jun 17, 2021 · 6 comments
Open

wp-env - Unable to install WordPress CLI Packages #32784

igorradovanov opened this issue Jun 17, 2021 · 6 comments
Labels
[Package] Env /packages/env [Type] Bug An existing feature does not function as intended

Comments

@igorradovanov
Copy link
Contributor

Description

wp-env Docker environment is unable to install new WordPress CLI packages due to a permission denied issue.

Step-by-step reproduction instructions

  1. wp-env start
  2. wp-env run cli package install 10up/mu-migration

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)

image

WordPress information

  • WordPress version: 5.7.2
  • Gutenberg version: 10.8.2
  • Are all plugins except Gutenberg deactivated? Yes
  • Are you using a default theme (e.g. Twenty Twenty-One)? Yes

Device information

  • Device: Dekstop
  • Operating system: Windows 10
  • Browser: Chrome 91.0.4472.106
@hideokamoto
Copy link
Contributor

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.

@Nikschavan
Copy link
Contributor

Nikschavan commented Jun 21, 2021

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 -

environment: {
...dbEnv.credentials,
...dbEnv.development,
},

@skorasaurus skorasaurus added [Package] Env /packages/env [Type] Bug An existing feature does not function as intended labels Jun 21, 2021
@hideokamoto
Copy link
Contributor

Is it possible to inject value like this?

docker-compose run -e DEBUG=1 web python console.py

Ref: https://docs.docker.com/compose/environment-variables/#set-environment-variables-with-docker-compose-run

@Nikschavan
Copy link
Contributor

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?

@andreiglingeanu
Copy link
Contributor

andreiglingeanu commented Jul 8, 2022

@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

@mikey242
Copy link

mikey242 commented Nov 23, 2022

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Env /packages/env [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

6 participants