cypress-io / circleci-orb

Install, cache and run Cypress.io tests on CircleCI with minimal configuration.
https://circleci.com/orbs/registry/orb/cypress-io/cypress
MIT License
160 stars 101 forks source link

Cypress failed to verify that your server is running #318

Closed daniel-moya closed 3 years ago

daniel-moya commented 3 years ago

The orb does not work as expected

what version of the orb are you currently using?

cypress-io/cypress@1.26.0

config.yml

version: 2.1

orbs:
  cypress: cypress-io/cypress@1.26.0

environment: &gcp_environment
  GOOGLE_PROJECT_ID: dation
  GOOGLE_COMPUTE_ZONE: europe-west4-a
  CONTAINER_REGISTRY: eu.gcr.io/dation

references:
  working_directory: &working_directory ~/dation-portal

  default_config: &default_config
    working_directory: *working_directory
    docker:
      - image: circleci/node:10
        environment:
          TZ: "Europe/Amsterdam"

  acceptance_config: &acceptance_config
    working_directory: *working_directory
    docker:
      - image: cypress/base:14.7.0

  restore_repo: &restore_repo
    restore_cache:
      name: Restoring Dation portal source from cache
      keys:
        - v1-repo-{{ .Branch }}-{{ .Revision }}
        - v1-repo-{{ .Branch }}
        - v1-repo

  restore_npm_cache: &restore_npm_cache
    restore_cache:
      name: Restoring npm cache
      key: node-v1-{{ checksum "package.json" }}-{{ arch }}-${CIRCLE_BUILD_NUM}

  save_npm_cache: &save_npm_cache
    save_cache:
      key: node-v1-{{ checksum "package.json" }}-{{ arch }}-${CIRCLE_BUILD_NUM}
      paths:
        - ~/node_modules
        - ~/.cache
        - ~/.npm

commands:
  build_image:
    parameters:
      configuration:
        type: string
    steps:
    - run:
        name: Build the production docker image.
        command: |
          npm install

          # Set CI to false to stop treating warnings as errors and failing the build.
          CI=false npm run build:<< parameters.configuration >>

          # Allow failure of cache loads
          set +o pipefail
          docker load -i ./portal-app-nginx.tar | true
          set -eo pipefail

          docker build . -f ./.docker/nginx/Dockerfile \
            -t portal-app-nginx \
            --cache-from=portal-app-nginx

          docker save -o ./portal-app-nginx.tar portal-app-nginx

  upload_source_maps_to_rollbar:
    parameters:
      accessToken:
        type: string
    steps:
    - run:
        name: Upload JS source maps to Rollbar
        command: |
          for path in $(find build/static/js -name "*.js"); do
            # URL of the JavaScript file on the web server.
            url=https://$APP_HOST/${path}

            # The path to the corresponding source map file.
            source_map="@$path.map"

            curl --silent --show-error https://api.rollbar.com/api/1/sourcemap \
              -F access_token=<< parameters.accessToken >> \
              -F version=$CIRCLE_SHA1 \
              -F minified_url=$url \
              -F source_map=$source_map \
            > /dev/null
          done

aliases:

  - &save_docker_image_cache
    save_cache:
      key: docker-image-{{ epoch }}
      paths:
        - ./portal-app-nginx.tar

  - &persist_docker_image
    persist_to_workspace:
      root: .
      paths:
        - portal-app-nginx.tar

  - &authenticate_gcloud
    run:
      name: Load google service account credentials
      command: |
        echo $GCLOUD_SERVICE_KEY | gcloud auth activate-service-account --key-file=-
        gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
        gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE}

        gcloud container clusters get-credentials dation --project=dation --zone=europe-west4-a

  - &push_image
    run:
      name: Tag and push images to GCP repository
      command: |
        docker load -i ./portal-app-nginx.tar

        export NGINX_TAG=$CONTAINER_REGISTRY/portal-app-nginx:${CIRCLE_SHA1}

        docker tag portal-app-nginx $NGINX_TAG

        gcloud auth configure-docker eu.gcr.io
        docker push $NGINX_TAG

  - &install_helm
    run:
      name: Install Helm v3
      command: |
        curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
        chmod 700 get_helm.sh
        ./get_helm.sh

  - &helm_upgrade
    run:
      name: Deploy the portal based on previously constructed image.
      command: |
        helm upgrade portal-app \
          ./.k8s/charts/portal-app/ \
          --namespace $K8S_NAMESPACE \
          --install \
          --set app.image.repository=$CONTAINER_REGISTRY \
          --set app.image.tag=$CIRCLE_SHA1 \
          --set app.react.version=$CIRCLE_SHA1 \
          --set app.react.apiHost=$REACT_APP_API_HOST \
          --set app.react.firebase.apiKey=$REACT_APP_FIREBASE_API_KEY \
          --set app.react.firebase.messagingSenderId=$REACT_APP_FIREBASE_MESSAGING_SENDER_ID \
          --set app.react.firebase.appId=$REACT_APP_FIREBASE_APP_ID \
          --set app.react.firebase.authDomain=$REACT_APP_FIREBASE_AUTH_DOMAIN \
          --set app.react.firebase.databaseUrl=$REACT_APP_FIREBASE_DATABASE_URL \
          --set app.react.firebase.projectId=$REACT_APP_FIREBASE_PROJECT_ID \
          --set app.react.firebase.storageBucket=$REACT_APP_FIREBASE_STORAGE_BUCKET \
          --set app.react.rollbarAccessToken=$ROLLBAR_ACCESS_TOKEN \
          --set app.react.intercomAppId=$REACT_APP_INTERCOM_APP_ID

jobs:
  build:
    <<: *default_config
    steps:
      - *restore_repo
      - checkout
      - save_cache:
          name: Save Dation Portal source to cache
          key: v1-repo={{ .Branch }}-{{ .Revision }}
          paths:
            - .

  npm:
    <<: *default_config
    steps:
      - *restore_repo
      - *restore_npm_cache
      - run:
          command: npm ci
      - *save_npm_cache

  build_acceptance:
    <<: *acceptance_config
    steps:
      - checkout
      - run:
          name: Install Dependencies
          command: npm install
      - save_cache:
          key: cache-{{ .Branch }}-{{ checksum "package.json" }}
          paths:
            - ~/.npm
            - ~/.cache
      - persist_to_workspace:
          root: ~/
          paths:
            - app
            - .cache/Cypress

  test:
    <<: *default_config
    steps:
      - *restore_repo
      - *restore_npm_cache
      - run:
          name: jest tests
          command: npm run test

  build_release:
    <<: *default_config
    parameters:
      configuration:
        type: string
      rollbarAccessToken:
        type: string
    steps:
      - setup_remote_docker
      - *restore_repo
      - checkout
      - *restore_npm_cache
      - build_image:
          configuration: << parameters.configuration >>
      - upload_source_maps_to_rollbar:
          accessToken: << parameters.rollbarAccessToken >>
      - *save_docker_image_cache
      - *save_npm_cache
      - *persist_docker_image

  deploy: &deploy
    docker:
      - image: google/cloud-sdk
    steps:
      - checkout
      - setup_remote_docker
      - attach_workspace:
          at: .
      - *authenticate_gcloud
      - *push_image
      - *install_helm
      - *helm_upgrade

  deploy_demo:
    <<: *deploy
    environment:
      <<: *gcp_environment
      K8S_NAMESPACE: portal-demo
      APP_HOST: demo.certificateportal.eu

  deploy_prod:
    <<: *deploy
    environment:
      <<: *gcp_environment
      K8S_NAMESPACE: portal-prod
      APP_HOST: certificateportal.eu

workflows:
  test:
    jobs:
      - build
      - npm:
          requires:
            - build
  run_acceptance:
    jobs:
      - cypress/run

  deploy_demo:
    jobs:
      - build_release:
          configuration: demo
          rollbarAccessToken: $ROLLBAR_ACCESS_TOKEN_DEMO
          filters:
            branches:
              only:
                - rc
      - deploy_demo:
          requires:
            - build_release

  deploy_prod:
    jobs:
      - build_release:
          rollbarAccessToken: $ROLLBAR_ACCESS_TOKEN_PROD
          filters:
            branches:
              only:
                - master
          configuration: dist
      - deploy_approval:
          type: approval
          requires:
            - build_release
      - deploy_prod:
          requires:
            - deploy_approval

#  build_and_test_acceptance:
#    jobs:
#      - build_acceptance
#      - run_acceptance:
#          requires:
#            - build_acceptance

Expected behaviur

command cypress run should work as expected

Failed at the end of tests

Cypress failed to verify that your server is running.
   Please start this server and then run Cypress again.

image

jennifer-shehane commented 3 years ago

You are responsible for starting your web server at your baseUrl before calling cypress run. Do you have any code that does that?

You could try using https://www.npmjs.com/package/wait-on or https://github.com/bahmutov/start-server-and-test