Gitlab CI中的Mongodb连接

时间:2019-08-14 23:05:39

标签: mongodb git docker gitlab gitlab-ci

我正在尝试设置Gitlab持续集成以在使用MERN堆栈的应用上运行一些测试,我需要配置mongodb以使测试可以运行但我不能

这是我的.gitlab-ci.yml文件

    image: node:latest

    stages:
      - build
      - test

    cache:
      paths:
        - node_modules/
        - packages/back-end/node_modules
        - packages/front-end/node_modules

    install_dependencies:
      stage: build
      script:
        - npm install
        - npm run lerna bootstrap
      artifacts:
        paths:
          - node_modules/
          - packages/back-end/node_modules
          - packages/front-end/node_modules

    testing:
        image: docker:latest
        stage: test
        services:
          - docker:dind
          - mongo:latest
        variables:
            PORT: 3001
            URL_DB: "mongodb://mongodb@mongodb/todos"
        script:
          - docker run -d --network host --name todos -e MONGO_INITDB_ROOT_USERNAME=test -e MONGO_INITDB_ROOT_PASSWORD=test -p 27017:27017 -v "/usr/db:/data/db" mongo:latest
          - cd packages/back-end 
          - npm start
          - npm test

我在测试阶段遇到此错误:

Skipping Git submodules setup
Checking cache for default...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. 
Successfully extracted cache
Downloading artifacts for install_dependencies (28022)...
Downloading artifacts from coordinator... ok        id=28022 responseStatus=200 OK token=jy6ye2Q1
docker run -d --network host --name todos -e MONGO_INITDB_ROOT_USERNAME=test -e MONGO_INITDB_ROOT_PASSWORD=test -p 27017:27017 -v "/usr/db:/data/db" mongo:latest
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
ERROR: Job failed: command terminated with exit code 125

0 个答案:

没有答案