Search code examples
cypressvagrant-provision

Cypress is unable to find Vagrant provided server in Github Actions


Relevant link: https://github.com/freeipa/freeipa-webui/pull/186

I am trying to run cypress tests on ipa server installed in Vagrant. I output the Vagrant's IP after the installation to /etc/hosts, which, I presume, is a host file used by GitHub runner. However, cypress does not seem to be able to find the running server. Previously (about a month ago), the runners were using 192.168.x.y IP and the vagrant provisioning has been consistently running on an assigned static address. This has changed recently and the vagrant provisioning is running on 10.0.x.y address. With 192.168.x.y address, cypress had no issue finding the server.

What I tried:

  • http and https for baseUrl param of cypress config
  • setting host with the IP as a env param for cypress step (see gating.yml in the PR above)
  • using wait-on with server's url (server.ipa.demo) in gating.yml

Relevant code:

cypress.config.ts

e2e: {
    specPattern: "**/*.feature",
    baseUrl: "http://server.ipa.demo",

gating.yml

      - name: Cache Vagrant boxes
        uses: actions/cache@v3
        with:
          path: ~/.vagrant.d/boxes
          key: ${{ runner.os }}-vagrant-${{ hashFiles('Vagrantfile') }}
          restore-keys: |
            ${{ runner.os }}-vagrant-

      - name: Cleanup running Vagrant boxes in case they are running
        run: vagrant destroy --force

      - name: Run vagrant up
        run: vagrant up --no-provision

      - name: Run vagrant provision
        run: vagrant provision

      - name: Put IPA Server's IP to /etc/hosts
        run: sudo echo "$(vagrant ssh -c "hostname -I") server.ipa.demo" | sudo tee -a /etc/hosts

      - name: Save server's IP address to env
        run: echo "SERVER_IP=$(vagrant ssh -c "hostname -I")" >> $GITHUB_ENV

      - name: Print exported variable
        run: echo "$SERVER_IP"

      - name: Run Cypress tests
        uses: cypress-io/github-action@v6
        with:
          browser: firefox
          env: host="https://${{ env.SERVER_IP  }}"

The error:

Cypress could not verify that this server is running:

  > https://server.ipa.demo/

We are verifying this server because it has been configured as your baseUrl.

Cypress automatically waits until your server is accessible before running tests.

We will try connecting to it 3 more times...
We will try connecting to it 2 more times...
We will try connecting to it 1 more time...

Solution

  • I have managed to resolve this issue using following steps:

    1. replace mac-os runner by ubuntu.

    When running Vagrant from mac-os, Vagrant was assigned only 10.0.2.15 address, which was not usable for connecting to the server running in Vagrant.

    When using ubuntu, Vagrant gets assigned both 10.0.2.15 and 192.168.x.y addresses, where 192... works in the internal network.

    1. For putting servers IP address into /etc/hosts, I have used following step
          - name: Put IPA Server's IP to /etc/hosts
            run: sudo echo "$(vagrant ssh -c "hostname -I|sed 's/10\.0\.2\.15//'") server.ipa.demo" | sudo tee -a /etc/hosts
    

    You can see PR#186 for details.