最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp env - wp-env fails in GitLab CI with “YIKES! It looks like you’re running this as root”

programmeradmin6浏览0评论

I’m trying to run wp-env in a GitLab CI pipeline using Docker, but I’m running into an issue where WP-CLI blocks execution because it’s running as root.

Here is my current .gitlab-ci.yml config:

    image: docker:24.0.7

    services:
      - docker:24.0.7-dind

    variables:
      DOCKER_HOST: tcp://docker:2375
      DOCKER_TLS_CERTDIR: ""

    before_script:
      - apk add --no-cache nodejs npm git
      - npm install -g @wordpress/env

    stages:
      - test

    wp_env_test:
      stage: test
      script:
        - wp-env start

The job fails with the following error:

    $ wp-env start
    ✖ Error while running docker compose command.
     Container f7bac6f1efb5e91b42d96b3a3f7663b0-mysql-1  Running
     Container f7bac6f1efb5e91b42d96b3a3f7663b0-wordpress-1  Created
     Container f7bac6f1efb5e91b42d96b3a3f7663b0-wordpress-1  Starting
     Container f7bac6f1efb5e91b42d96b3a3f7663b0-wordpress-1  Started
    Error: YIKES! It looks like you're running this as root. You probably meant to run this as the user that your WordPress installation exists under.
    If you REALLY mean to run this as root, we won't stop you, but just bear in mind that any code on this site will then have full control of your server, making it quite DANGEROUS.
    If you'd like to continue as root, please run this again, adding this flag:  --allow-root

However, there’s no way (that I know of) to pass the --allow-root flag directly to the internal WP-CLI commands executed by wp-env.

What I’ve tried: • Creating a .env file with WP_CLI_ALLOW_ROOT=1 → didn’t work

Is there a clean and supported way to get wp-env running in GitLab CI when the environment runs as root? Or any reliable workaround to allow WP-CLI to run without failing in this context?

Thanks in advance!

I’m trying to run wp-env in a GitLab CI pipeline using Docker, but I’m running into an issue where WP-CLI blocks execution because it’s running as root.

Here is my current .gitlab-ci.yml config:

    image: docker:24.0.7

    services:
      - docker:24.0.7-dind

    variables:
      DOCKER_HOST: tcp://docker:2375
      DOCKER_TLS_CERTDIR: ""

    before_script:
      - apk add --no-cache nodejs npm git
      - npm install -g @wordpress/env

    stages:
      - test

    wp_env_test:
      stage: test
      script:
        - wp-env start

The job fails with the following error:

    $ wp-env start
    ✖ Error while running docker compose command.
     Container f7bac6f1efb5e91b42d96b3a3f7663b0-mysql-1  Running
     Container f7bac6f1efb5e91b42d96b3a3f7663b0-wordpress-1  Created
     Container f7bac6f1efb5e91b42d96b3a3f7663b0-wordpress-1  Starting
     Container f7bac6f1efb5e91b42d96b3a3f7663b0-wordpress-1  Started
    Error: YIKES! It looks like you're running this as root. You probably meant to run this as the user that your WordPress installation exists under.
    If you REALLY mean to run this as root, we won't stop you, but just bear in mind that any code on this site will then have full control of your server, making it quite DANGEROUS.
    If you'd like to continue as root, please run this again, adding this flag:  --allow-root

However, there’s no way (that I know of) to pass the --allow-root flag directly to the internal WP-CLI commands executed by wp-env.

What I’ve tried: • Creating a .env file with WP_CLI_ALLOW_ROOT=1 → didn’t work

Is there a clean and supported way to get wp-env running in GitLab CI when the environment runs as root? Or any reliable workaround to allow WP-CLI to run without failing in this context?

Thanks in advance!

Share Improve this question edited Mar 28 at 7:30 bueltge 17.1k7 gold badges62 silver badges97 bronze badges asked Mar 27 at 15:47 GTWGP AntoGTWGP Anto 211 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

In some quick testing, I found that if I defined WP_CLI_ALLOW_ROOT=1 after I was already running as root, then WP CLI wouldn't complain. I don't know a lot about GitLab CI, unfortunately, but I'd try this to see if it works:

    image: docker:24.0.7

    services:
      - docker:24.0.7-dind

    variables:
      DOCKER_HOST: tcp://docker:2375
      DOCKER_TLS_CERTDIR: ""

    before_script:
      - apk add --no-cache nodejs npm git
      - npm install -g @wordpress/env

    stages:
      - test

    wp_env_test:
      stage: test
      script:
        - export WP_CLI_ALLOW_ROOT=1
        - wp-env start

...unless, of course, that's what you already tried.

发布评论

评论列表(0)

  1. 暂无评论