cypress-docker-images
cypress-docker-images copied to clipboard
Proposition: running as non-root non-node user is easy if...
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?
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?
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
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
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.
I get this error running on Github actions but setting the environment does't seem to help.
@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
Closing. The situation has changed since this issue was originally posted.