bigbite / wp-cypress

WordPress end to end testing with Cypress.io.
MIT License
86 stars 18 forks source link

Add No Docker Mode #109

Closed jasonagnew closed 7 months ago

jasonagnew commented 1 year ago

Add No Docker Mode

Description

Running Docker on a CI can be tricky, there is often limitations due to security. Most notable CircleCI doesn't support volumes unless you use a VM which is very slow. As most CIs allow you to load docker image there should be option to start WP Cypress without docker as CI image should have everything needed to run WordPress & Cypress.

Change Log

Types of changes (if applicable):

How to use.

The feature can be tested/used easily on CircleCI. There is Big Bite docker image that can be used as example of what you need. Replacing << parameters.host >> with cypress domain for example project.client.co and replacing << parameters.port >> with port being used (defaults to 80)

version: 2.1

jobs:
  main:
    docker:
      - image: 'bigbite/ci-orb-project:php-7.4'
      - image: 'cimg/mysql:8.0'
    steps:
      - checkout
      - run: |
          echo 'export NVM_DIR=$HOME/.nvm' >> $BASH_ENV
          echo 'source $NVM_DIR/nvm.sh' >> $BASH_ENV
      - run: npm ci
      - run: |
          echo 127.0.0.1 << parameters.host >> | tee -a /etc/hosts
          sed -i 's/80/<< parameters.port >>/' /etc/apache2/ports.conf
          sed -i 's/80/<< parameters.port >>/' /etc/apache2/sites-enabled/000-default.conf
          service apache2 start
          echo 'export WP_CYPRESS_WORKING_DIR="/var/www"' >> $BASH_ENV
          echo 'export WP_CYPRESS_NO_DOCKER_MODE="true"' >> $BASH_ENV
          echo 'export WP_CYPRESS_DB_HOST="127.0.0.1"' >> $BASH_ENV
          echo 'export WP_CYPRESS_DB_NAME="circle_test"' >> $BASH_ENV
          echo 'export WP_CYPRESS_DB_USER="root"' >> $BASH_ENV
          echo 'export WP_CYPRESS_DB_PASS=""' >> $BASH_ENV
      - run: npx wp-cypress start
      - run: npx cypress run

workflows:
  workflow:
    jobs:
      - build:
          filters:
            branches:
              ignore: /^.*-built$/

You can also use the bigbite orb which makes it even easier to use:

version: 2.1

orbs:
  project: bigbite/project@0.0.39

jobs:
  build:
    executor:
      name: project/default
      php: '7.4'
    steps:
      - checkout
      - project/setup
      - project/npm-install:
          path: "./"
      - project/wp-cypress-start:
          path: "./"
          host: "project.client.co"
          port: 3333
      - project/cypress-run:
          path: "./"

workflows:
  workflow:
    jobs:
      - build:
          filters:
            branches:
              ignore: /^.*-built$/
g-elwell commented 7 months ago

This works great for both myself and @chrishbite on separate repos with a variety of tests. Good to merge!

We should ensure this feature is covered in docs at some point, ref #76