Search code examples
bitbucket-pipelineswp-cli

Bitbucket Pipeline: run step as non-root


One of my steps in my Bitbucket deployment pipeline involves executing

- step:
    name: Start MaintenanceMode
    script:
      - php bin/wp-cli.phar mm_enter --ssh=[...]

However, understandably wp_cli.phar doesn't love being run as root. I can get rid of the error by using --allow-root, but I would prefer to simply not run anything in the step as root. Is there any way to run a step in a Bitbucket pipeline without root privileges?

I've looked at this similar question but that seems to only work because node creates a new user.

Here is the specific output from the line

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
If you'd like to run it as the user that this site is under, you can run the following to become the respective user:
    sudo -u USER -i -- wp <command>

Solution

  • You have several solutions

    1. Check the list of available users in the container - most of all your container already has a user

    2. Create a new user for yourself at the stage of building a container without root privileges