Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
268 views
in Technique[技术] by (71.8m points)

Backend server in gitlab-ci docker cypress e2e

I am new to gitlab ci. I want to run integrated tests of my app using cypress. E2E tests require frontend (ionic, cypress) and backend (django, postgis). Running in my local machine everything works fine. First launch the backend server, and then run tests. Now I wanted to use gitLab CI but I don't know how to launch the backend server (i've been googling around but found nothing to my case), before launching the tests in the docker container (I'm also new to docker). I'm using a gitlab-ci.yaml I got from the cypress-gitlab network

stages:
  - build
  - test

# to cache both npm modules and Cypress binary we use environment variables
# to point at the folders we can list as paths in "cache" job settings
variables:
  npm_config_cache: "$CI_PROJECT_DIR/.npm"
  CYPRESS_CACHE_FOLDER: "$CI_PROJECT_DIR/cache/Cypress"

# cache using branch name
# https://gitlab.com/help/ci/caching/index.md
cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - .npm
    - cache/Cypress
    - node_modules

# this job installs NPM dependencies and Cypress
install:
  image: cypress/base:10
  stage: build

  script:
    - npm ci
    # show where the Cypress test runner binaries are cached
    - $(npm bin)/cypress cache path
    # show all installed versions of Cypress binary
    - $(npm bin)/cypress cache list
    - $(npm bin)/cypress verify

# two jobs that run after "install" job finishes
# NPM dependencies and Cypress binary should be already installed
cypress-e2e:
  image: cypress/base:10
  stage: test
  script:
    - $(npm bin)/cypress run
  artifacts:
    expire_in: 1 week
    when: always
    paths:
    - cypress/screenshots
    - cypress/videos
    reports:
      junit:
        - results/TEST-*.xml

cypress-e2e-chrome:
  image: cypress/browsers:chrome67
  stage: test
  script:
    - $(npm bin)/cypress run --browser chrome
  artifacts:
    expire_in: 1 week
    when: always
    paths:
    - cypress/screenshots
    - cypress/videos
    reports:
      junit:
        - results/TEST-*.xml

The install job runs fine. The error occur on the job cypress-e2e. The error seems auto-explanatory and logic to me - no server running. My problem is I don't know how to introduce in the script the launch of the service. The output of the pipeline:

Running with gitlab-runner 13.8.0-rc1 (28e2e34a)
  on docker-auto-scale 0277ea0f
Preparing the "docker+machine" executor
00:37
Using Docker executor with image cypress/base:10 ...
Pulling docker image cypress/base:10 ...
Using docker image sha256:071155d6ed07a321ae5c7a453c1fd1f04ff65bd5eeae97281c1a2088c26acf0a for cypress/base:10 with digest cypress/base@sha256:7fb73651d4a48762d5f370a497a155891eba90605ea395a4d86cafdefb153f8c ...
Preparing environment
00:03
Running on runner-0277ea0f-project-23892759-concurrent-0 via runner-0277ea0f-srm-1611586309-ee0dc093...
Getting source from Git repository
00:03
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/ctavar01/advisor_app/.git/
Created fresh repository.
Checking out 9e8a00a2 as master...
Skipping Git submodules setup
Restoring cache
00:26
Checking cache for master...
Downloading cache.zip from https://storage.googleapis.com/gitlab-com-runners-cache/project/23892759/master 
Successfully extracted cache
Executing "step_script" stage of the job script
00:23
$ $(npm bin)/cypress run
Cypress could not verify that this server is running:
  > http://localhost:8100
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...
Cypress failed to verify that your server is running.
Please start this server and then run Cypress again.
Uploading artifacts for failed job
00:05
Uploading artifacts...
cypress/screenshots: found 14 matching files and directories 
cypress/videos: found 8 matching files and directories 
Uploading artifacts as "archive" to coordinator... ok  id=984717879 responseStatus=201 Created token=FCQbsg-q
Uploading artifacts...
WARNING: results/TEST-*.xml: no matching files     
ERROR: No files to upload                          
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1

Thanks for any help

question from:https://stackoverflow.com/questions/65887431/backend-server-in-gitlab-ci-docker-cypress-e2e

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...