cypress-docker-images icon indicating copy to clipboard operation
cypress-docker-images copied to clipboard

Proposition: running as non-root non-node user is easy if...

Open jehon opened this issue 1 year ago • 5 comments

Running as user 1001 (or other) is easy if the HOME variable is set to "/root"

I propose to add in the Dockerfile:

ENV HOME=/root

Indeed, there are no particularities for each user.

That allow running docker with --user $( id -u ) and receive test reports under the correct user.

PS: Documentation could be enhanced, and the whole chapter about user may be replaced.

Maybe examples could be removed too?

jehon avatar Mar 03 '23 09:03 jehon

I've tried this in this branch: unknown-non-root

It successfully fixed it when cypress is installed globally, but the issue persisted when cypress was installed by the user.

I tried messing with the file permission of the /opt dir (where we installed cypress) but no luck. Any more suggestions?

mjhenkes avatar Mar 06 '23 14:03 mjhenkes

You are right, when installing cypress in the docker image, it is more complex. I couldn't make it work at first. I will look at it later

jehon avatar Mar 09 '23 09:03 jehon

In Github Actions, the HOME variable is overridden by the job runner to /github/home. The solution I found that seems to work the best is to specify a new HOME for the step that runs Cypress, but not other steps (otherwise npm ci will try to use /root/.npm and fail due to permission errors.

      - name: ✅ Run E2E tests
        env:
          HOME: /root
          CYPRESS_BASE_URL: http://localhost:5000
        run: npm run cy:run

Uses a job container like this:

    container:
      image: cypress/included:12.8.1
      options: --user 4300

oscar-b avatar Mar 20 '23 16:03 oscar-b

Small summary:

  • for the end user, it is possible to run cypress/included as any user as long as HOME is set to /root example: mind the -e HOME=/root docker run -it -v $PWD:/e2e -w /e2e -e HOME=/root cypress/included:3.4.0 This command can run as any user.

Possible changes to the Cypress project? Some of:

  • documentation: add this information to the documentation
  • docker image: add a HOME default value to /root
  • testing my idea in the build chain?

Why is it important?

  • On GitHub actions, you run as user 1001, which fail.

jehon avatar Apr 20 '23 09:04 jehon

I get this error running on Github actions but setting the environment does't seem to help.

tyler36 avatar Jul 07 '23 02:07 tyler36

@jehon

Why is it important?

  • On GitHub actions, you run as user 1001, which fail.

https://github.com/cypress-io/github-action/blob/master/.github/workflows/example-docker.yml demonstrates successfully setting options: --user 1001. Do you have an example in GitHub Actions where this fails?

    container:
      image: cypress/browsers:node-20.5.0-chrome-114.0.5735.133-1-ff-114.0.2-edge-114.0.1823.51-1
      options: --user 1001

MikeMcC399 avatar Jun 10 '24 10:06 MikeMcC399

Closing. The situation has changed since this issue was originally posted.

MikeMcC399 avatar Jun 14 '24 09:06 MikeMcC399