I currently have a GitHub Actions setup and run my Cypress integration tests against the default Github runner. This works well, but is becoming expensive.
I run other checks using self-hosted runners on AWS EC2 configured using the Philips Terraform Self-Hosted Runner for AWS, which works well and generally accomplishes the cost-savings we were looking for.
The issue is that the Cypress preconfigured runner expects a handful of dependencies to exist on the runner. Cypress docs do not provide any preconfigured setup for self-hosted runners, as the provided default GitHub runner already has all dependencies that Cypress expects, specifically Chrome browser (or whatever browser(s) you want to automate Cypress against).
There are preconfigured Chrome and Node/npm install actions, which would have worked, but they give the following error when run on Amazon’s flavor of Fedora Linux:
Unsupported OS: amzn
How can I set up these dependencies in order to run Cypress on my self-hosted runners?
Solution:
The following commands allowed me to successfully run my Cypress tests against Chrome in my self-hosted AWS runners. I modified my Terraform config to setup these resources on every runner; This is not mandatory and could be done on a per-job basis, or manually on each runner if your runners aren’t automated. Regardless, these are the commands to setup the necessary dependencies on a given machine:
# setup AWS runner (not needed for cypress, just for my specific GH Actions + AWS runner setup
wget https://github.com/cli/cli/releases/download/v2.39.2/gh_2.39.2_linux_amd64.rpm
sudo rpm -i gh_2.39.2_linux_amd64.rpm
# Install Cypress dependencies
sudo yum install -y xorg-x11-server-Xvfb gtk3-devel libnotify-devel nss libXScrnSaver alsa-lib
# Install NPM for test setup
sudo yum install -y nodejs npm
# Download Chrome and install
export BROWSERS_SRC_DIR="/usr/src/browsers"
mkdir -p $BROWSERS_SRC_DIR
sudo curl https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm --output $BROWSERS_SRC_DIR/google-chrome-stable_current_x86_64.rpm
sudo yum install -y -q $BROWSERS_SRC_DIR/google-chrome-stable_current_x86_64.rpm
How I got to that:
While the Cypress Github actions repo docs do not have info about the runner dependencies (or anything self-hosted related), @alexandroid’s answer led me to the Cypress linux prerequisites, which was the first necessary component:
sudo yum install -y xorg-x11-server-Xvfb gtk3-devel libnotify-devel nss libXScrnSaver alsa-lib
The second was actually getting chrome installed. There were several false leads here (Specifically, no answer using the dnf
tool seems to work on the Amazon linux, resulting in errors like Error: No matching repo to modify: google-chrome
). Ultimately the solution that worked was pulled directly from @alexandroid’s answer, using a similar approach to the much, much easier to find answers on this general Linux question about installing Chrome via CLI, but adapting it to pulling the RPM image for Amazon Linux specifically:
export BROWSERS_SRC_DIR="/usr/src/browsers"
mkdir -p $BROWSERS_SRC_DIR
sudo curl https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm --output $BROWSERS_SRC_DIR/google-chrome-stable_current_x86_64.rpm
sudo yum install -y -q $BROWSERS_SRC_DIR/google-chrome-stable_current_x86_64.rpm
The final piece was a combination of Matthew Herbst’s and Tim Fulmer’s answers to install Node/NPM:
sudo yum install -y nodejs npm
Combining these, I was able to successfully run my Cypress tests automatically via Github Actions on self-hosted runners in AWS EC2, with the following job configuration:
jobs:
cypress-run:
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@master
- name: Install dependencies
uses: cypress-io/github-action@v5
with:
working-directory: web
# just perform install
runTests: false
- name: Run e2e tests
uses: cypress-io/github-action@v5
with:
# we have already installed all dependencies above
install: false
browser: chrome
spec: cypress/ci/**/*.ts