diff --git a/.env.example b/.env.example index c642e10..965171a 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,12 @@ +# Define which compose files to use +# see: https://www.perplexity.ai/search/6d5732a8-89ba-479b-bdf6-00c93d19b9a9?s=u + +# Director only (no dashboard etc) +COMPOSE_FILE=docker-compose.network.yml,docker-compose.director.yml + +# The full stack with dashboard etc +#COMPOSE_FILE=docker-compose.network.yml,docker-compose.full.yml + # SSH configuration SSH_IP=1.1.1.1 SSH_PORT=22 diff --git a/README.md b/README.md index 5f7a0af..6bb544f 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,54 @@ Authentication is done using basic auth, which is set up based on environment va ## Setting up sorry-cypress 1. Follow the [sorry-cypress setup instructions](https://docs.sorry-cypress.dev/guide/get-started) + - `npm i cypress-cloud` + - Edit `cypress` CLI for `cypress-coud` [see docs](https://docs.sorry-cypress.dev/guide/get-started#running-cypress-tests-in-parallel) + - Add `cloudPlugin` to `cypress.config.js` 2. Set `cloudServiceUrl` in your `currents.config.js` to `https://your_user:your_password@sorry-cypress-director.your_domain.com` 3. See `.github-actions.example.yml` for an example for how to set up a parallel resting CI on Github +### Example usage in Github actions + +You can use the director in Github Actions by setting `currents.config.js` to: + +```js +module.exports = { + projectId: "APP NAME", // the projectId, can be any values for sorry-cypress users + recordKey: "xxx", // the record key, can be any value for sorry-cypress users + cloudServiceUrl: "%%cypress_cloud_service_url%%", // Sorry Cypress users - set the director service URL +} +``` + +And in Github Actions add the URL with authentication using: + +```bash +sed -i "s;%%cypress_cloud_service_url%%;${{ secrets.CYPRESS_CLOUD_SERVICE_URL }};g" currents.config.js +``` + +You can then run parallel testing using: + +```yml +strategy: + fail-fast: false + matrix: + # run 3 copies of the current job in parallel + containers: [ 1, 2, 3 ] +``` + +You can save the artifacts of the containers for debugging by using: + +```yml +# If CI failed, upload the videos for debugging +- name: Upload cypress video files +if: always() # you can optionally set this to failure() +uses: actions/upload-artifact@v3 +with: + name: cypress-videos ${{ matrix.containers }} + path: | + cypress/videos + cypress/screenshots +``` + ## Notes **Buildjet is highly recommended** diff --git a/docker-compose.director.yml b/docker-compose.director.yml new file mode 100644 index 0000000..3ad21a0 --- /dev/null +++ b/docker-compose.director.yml @@ -0,0 +1,72 @@ +version: '3' + +services: + + ## ############### + ## Infra services + ## ############### + + # MongoDB service, this is used by the cypress services to store data + mongo: + image: mongo:4.4 + container_name: mongo + volumes: + - ./data/data-mongo-cypress:/data/db + networks: + - internal + restart: unless-stopped + + # Reverse proxy service, this is used to expose the cypress services to the world securely + swag: + image: lscr.io/linuxserver/swag:latest + container_name: swag + cap_add: + - NET_ADMIN + environment: + # Environment setup + - PUID=1000 + - PGID=1000 + - TZ=Europe/London + # Automatic SSL certificate provisioning + - URL=${PROXY_SERVER_DOMAIN} + - VALIDATION=http + - SUBDOMAINS=${PROXY_DIRECTOR_SUBDOMAIN},${PROXY_API_SUBDOMAIN},${PROXY_DASHBOARD_SUBDOMAIN} + - ONLY_SUBDOMAINS=true + volumes: + - ./swag:/config + ports: + - 443:443 + - 80:80 + depends_on: + - director + - mongo + networks: + - internal + - external + restart: unless-stopped + + + ## ############### + ## Cypress services + ## ############### + + # Cypress director (required) + # Coordinates & parallelizes tests, saves test results, this is the container that the cypress test runner connects to + # This is the only **required** service to run parallel tests, see: https://docs.sorry-cypress.dev/configuration/in-memory + director: + image: agoldis/sorry-cypress-director:latest + container_name: sorry-cypress-director + environment: + MONGODB_URI: 'mongodb://mongo:27017' + MONGODB_DATABASE: 'sorry-cypress' + EXECUTION_DRIVER: '../execution/mongo/driver' + GITLAB_JOB_RETRIES: 'false' + #S3_REGION: us-east-1 + PROBE_LOGGER: "false" + ports: + - 1234:1234 + networks: + - internal + depends_on: + - mongo + restart: unless-stopped diff --git a/docker-compose.yml b/docker-compose.full.yml similarity index 94% rename from docker-compose.yml rename to docker-compose.full.yml index 9a92914..f2d8e14 100644 --- a/docker-compose.yml +++ b/docker-compose.full.yml @@ -1,13 +1,5 @@ version: '3' -# Network configuration, we'll make one internal network for the cypress container, and one publicly available network for the proxy -networks: - internal: - name: internal - # internal: true - external: - name: external - services: ## ############### @@ -138,4 +130,5 @@ services: - minio networks: - internal + - external # note that the dashboard requires this to make calls from the frontend restart: unless-stopped diff --git a/docker-compose.network.yml b/docker-compose.network.yml new file mode 100644 index 0000000..07e22a1 --- /dev/null +++ b/docker-compose.network.yml @@ -0,0 +1,9 @@ +version: '3' + +# Network configuration, we'll make one internal network for the cypress container, and one publicly available network for the proxy +networks: + internal: + name: internal + internal: true + external: + name: external