Skip to content

Instantly share code, notes, and snippets.

@jjkavalam
Created August 26, 2024 13:01
Show Gist options
  • Save jjkavalam/afa340133440b59536de31f1f449720e to your computer and use it in GitHub Desktop.
Save jjkavalam/afa340133440b59536de31f1f449720e to your computer and use it in GitHub Desktop.
How to correctly create a Dockerfile for Cypress test
# Pick a suitable base image matching the node version you need.
# https://hub.docker.com/r/cypress/browsers/tags is a good place to search
# I have chosen node version 22.7.0; the image comes bundled with Chrome, Firefox, Edge browsers
# with the version as indicated below
FROM cypress/browsers:node-22.7.0-chrome-127.0.6533.119-1-ff-129.0.1-edge-127.0.2651.98-1
# Now we will add our test code to this image along with any dependencies.
# We will be adding many files to this image in the steps that follow.
#
# Important! We want those files to be accessible to the UNIX user the container will run as.
# It is known that this user is going to be 1001:1001
#
# How did I identify the user to be 1001:1001.
# For that inspect the layers of the base image we imported above and
# investigate the entrypoint script. You may also find it out by running the
# base image directly and executing the "id" command.
# copy the project files ensuring they are owned by the right user
COPY --chown=1001:1001 . ./
# set up the project dependencies and perform a "cypress verify" to ensure everything is good.
# Take care to run the whole process as the same user that the container will run as.
RUN su - 1001 -c "npm ci && npx cypress verify"
# If there are more setup steps, add them below. Just ensure that you are running those
# as user 1001.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment