MongoDB 服务器无法使用 gitlab-ci 在 gitlab runner 上启动

2024-03-04

现在我正在使用 Ruby 和 Mongo 开发一个应用程序。但是当我使用 gitlab-ci 部署应用程序时,我陷入了困境,似乎 mongo 服务器没有在 gitlab runner 的测试环境中启动。

这是我的 gitlab-ci.yml

stages :
- test
- deploy

services:
  - mongo:latest

unitTest:API:
  image: ruby:2.6.10
  stage: test
  cache: 
    paths:
      - API/vendor/
  before_script:
    - ruby -v
    - gem install bundler --no-ri --no-rdoc
    - bundle install --gemfile=API/Gemfile --path vendor
  script:
    - RAILS_ENV=test rspec API/spec
    - RAILS_ENV=test rubocop API
  artifacts:
    paths:
      - coverage/

deploy_coba:
  stage: deploy
  before_script:
    - cd API
  script: 
    - gem install dpl
    - dpl --provider=heroku --app=exhibisi-cobacoba --api-key=68b12c2b-cfbc-4478-b943-f26552fb907e
  only:
    - coba_coba

staging:
  stage: deploy
  before_script:
    - cd API
  script: 
    - gem install dpl
    - dpl --provider=heroku --app=exhibisi-staging --api-key=68b12c2b-cfbc-4478-b943-f26552fb907e
  only:
    - sit_uat

production:
  stage: deploy
  before_script:
    - cd API
  script:
    - gem install dpl
    - dpl --provider=heroku --app=exhibisi-prod --api-key=68b12c2b-cfbc-4478-b943-f26552fb907e
  only:
    - master

pages:
  stage: deploy
  script:
    - mv coverage/ public/
  artifacts:
    paths:
      - public
    expire_in: 30 days

这是 gitlab 运行程序错误的结果

    Running with gitlab-runner 10.6.0-rc1 (0a9d5de9)
on docker-auto-scale e11ae361
Using Docker executor with image ruby:2.3.0 ...
Starting service mongo:2.6.10 ...
Pulling docker image mongo:2.6.10 ...
Using docker image sha256:54fb6f9984dde283c9ff55f5aba7d883355793dd7997b0f9f75bb31e89607311 for mongo:2.6.10 ...
Waiting for services to be up and running...
Pulling docker image ruby:2.3.0 ...
Using docker image sha256:7ca70eb2dfea00e9e3eaece33024ad5c06b7473728d559e1a3a574629de95a6a for ruby:2.3.0 ...
Running on runner-e11ae361-project-5550018-concurrent-0 via runner-e11ae361-srm-1521565965-49af3740...
Cloning repository...
Cloning into '/builds/cymon1997/ppl-coba'...
Checking out 61333b01 as US02_menampilkan_daftar_produk...
Skipping Git submodules setup
Checking cache for default...
FATAL: file does not exist                         
Failed to extract cache
$ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
$ gem install bundler --no-ri --no-rdoc
Successfully installed bundler-1.16.1
1 gem installed
$ bundle install --gemfile=API/Gemfile --path vendor
Fetching gem metadata from http://rubygems.org/..........
Fetching rake 12.3.0
Installing rake 12.3.0
Fetching concurrent-ruby 1.0.5
Installing concurrent-ruby 1.0.5
Fetching i18n 0.9.5
Installing i18n 0.9.5
Fetching minitest 5.11.3
Installing minitest 5.11.3
Fetching thread_safe 0.3.6
Installing thread_safe 0.3.6
Fetching tzinfo 1.2.5
Installing tzinfo 1.2.5
Fetching activesupport 5.1.5
Installing activesupport 5.1.5
Fetching activemodel 5.1.5
Installing activemodel 5.1.5
Fetching ast 2.4.0
Installing ast 2.4.0
Fetching bson 4.3.0
Installing bson 4.3.0 with native extensions
Using bundler 1.16.1
Fetching diff-lcs 1.3
Installing diff-lcs 1.3
Fetching docile 1.1.5
Installing docile 1.1.5
Fetching json 2.1.0
Installing json 2.1.0 with native extensions
Fetching mongo 2.5.1
Installing mongo 2.5.1
Fetching mongoid 6.3.0
Installing mongoid 6.3.0
Fetching mustermann 1.0.2
Installing mustermann 1.0.2
Fetching parallel 1.12.1
Installing parallel 1.12.1
Fetching parser 2.5.0.3
Installing parser 2.5.0.3
Fetching powerpack 0.1.1
Installing powerpack 0.1.1
Fetching rack 2.0.4
Installing rack 2.0.4
Fetching rack-protection 2.0.1
Installing rack-protection 2.0.1
Fetching rack-test 0.8.2
Installing rack-test 0.8.2
Fetching racksh 1.0.0
Installing racksh 1.0.0
Fetching rainbow 3.0.0
Installing rainbow 3.0.0
Fetching rspec-support 3.7.1
Installing rspec-support 3.7.1
Fetching rspec-core 3.7.1
Installing rspec-core 3.7.1
Fetching rspec-expectations 3.7.0
Installing rspec-expectations 3.7.0
Fetching rspec-mocks 3.7.0
Installing rspec-mocks 3.7.0
Fetching rspec 3.7.0
Installing rspec 3.7.0
Fetching rspec-json_expectations 2.1.0
Installing rspec-json_expectations 2.1.0
Fetching ruby-progressbar 1.9.0
Installing ruby-progressbar 1.9.0
Fetching unicode-display_width 1.3.0
Installing unicode-display_width 1.3.0
Fetching rubocop 0.53.0
Installing rubocop 0.53.0
Fetching shotgun 0.9.2
Installing shotgun 0.9.2
Fetching simplecov-html 0.10.2
Installing simplecov-html 0.10.2
Fetching simplecov 0.15.1
Installing simplecov 0.15.1
Fetching tilt 2.0.8
Installing tilt 2.0.8
Fetching sinatra 2.0.1
Installing sinatra 2.0.1
Bundle complete! 10 Gemfile dependencies, 39 gems now installed.
Bundled gems are installed into `./vendor`
$ RAILS_ENV=test rspec API/spec
...FFFF.

Failures:

1) ListProductController GET to /products returns status 200 OK
    Failure/Error: expect(last_response).to be_ok
    expected `#<Rack::MockResponse:0x0056395b78af10 @original_headers={"Content-Type"=>"text/html", "Content-Length...bled the <code>show_exceptions</code> setting.</p>\n  </div> <!-- /WRAP -->\n  </body>\n</html>\n"]>.ok?` to return true, got false
    # ./API/spec/controllers/listproduct_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

2) ListProductController GET to /products show a list of product's name and its icon
    Failure/Error:
    Product.each do |product|
        payload.push({ exhibit_name: product.exhibit_name, icon: product.icon })
    end

    Mongo::Error::NoServerAvailable:
    No server is available matching preference: #<Mongo::ServerSelector::Primary:0x47402175180100 tag_sets=[] max_staleness=nil> using server_selection_timeout=30 and local_threshold=0.015
    # ./API/vendor/ruby/2.3.0/gems/mongo-2.5.1/lib/mongo/server_selector/selectable.rb:119:in `select_server'
    # ./API/vendor/ruby/2.3.0/gems/mongo-2.5.1/lib/mongo/collection/view/iterable.rb:41:in `block in each'
    # ./API/vendor/ruby/2.3.0/gems/mongo-2.5.1/lib/mongo/retryable.rb:44:in `read_with_retry'
    # ./API/vendor/ruby/2.3.0/gems/mongo-2.5.1/lib/mongo/collection/view/iterable.rb:40:in `each'
    # ./API/vendor/ruby/2.3.0/gems/mongoid-6.3.0/lib/mongoid/query_cache.rb:222:in `each'
    # ./API/vendor/ruby/2.3.0/gems/mongoid-6.3.0/lib/mongoid/contextual/mongo.rb:132:in `each'
    # ./API/vendor/ruby/2.3.0/gems/mongoid-6.3.0/lib/mongoid/contextual.rb:20:in `each'
    # ./API/vendor/ruby/2.3.0/gems/mongoid-6.3.0/lib/mongoid/findable.rb:15:in `each'
    # ./API/spec/controllers/listproduct_controller_spec.rb:15:in `block (3 levels) in <top (required)>'

3) ListProductController GET to /:id returns status 200 OK
    Failure/Error: expect(last_response).to be_ok
    expected `#<Rack::MockResponse:0x0056395c8565b0 @original_headers={"Content-Type"=>"text/html", "Content-Length...bled the <code>show_exceptions</code> setting.</p>\n  </div> <!-- /WRAP -->\n  </body>\n</html>\n"]>.ok?` to return true, got false
    # ./API/spec/controllers/listproduct_controller_spec.rb:31:in `block (3 levels) in <top (required)>'

4) ListProductController GET to /:id displays the product's profil
    Failure/Error: product = Product.find_by(exhibit_id: "EXH1")

    Mongo::Error::NoServerAvailable:
    No server is available matching preference: #<Mongo::ServerSelector::Primary:0x69881936872840 tag_sets=[] max_staleness=nil> using server_selection_timeout=30 and local_threshold=0.015
    # ./API/vendor/ruby/2.3.0/gems/mongo-2.5.1/lib/mongo/server_selector/selectable.rb:119:in `select_server'
    # ./API/vendor/ruby/2.3.0/gems/mongo-2.5.1/lib/mongo/collection/view/iterable.rb:41:in `block in each'
    # ./API/vendor/ruby/2.3.0/gems/mongo-2.5.1/lib/mongo/retryable.rb:44:in `read_with_retry'
    # ./API/vendor/ruby/2.3.0/gems/mongo-2.5.1/lib/mongo/collection/view/iterable.rb:40:in `each'
    # ./API/vendor/ruby/2.3.0/gems/mongoid-6.3.0/lib/mongoid/query_cache.rb:222:in `each'
    # ./API/vendor/ruby/2.3.0/gems/mongoid-6.3.0/lib/mongoid/contextual/mongo.rb:278:in `first'
    # ./API/vendor/ruby/2.3.0/gems/mongoid-6.3.0/lib/mongoid/contextual/mongo.rb:278:in `find_first'
    # ./API/vendor/ruby/2.3.0/gems/mongoid-6.3.0/lib/mongoid/contextual.rb:20:in `find_first'
    # ./API/vendor/ruby/2.3.0/gems/mongoid-6.3.0/lib/mongoid/findable.rb:114:in `find_by'
    # ./API/spec/controllers/listproduct_controller_spec.rb:35:in `block (3 levels) in <top (required)>'

Finished in 7 minutes 2 seconds (files took 1.31 seconds to load)
8 examples, 4 failures

Failed examples:

rspec ./API/spec/controllers/listproduct_controller_spec.rb:7 # ListProductController GET to /products returns status 200 OK
rspec ./API/spec/controllers/listproduct_controller_spec.rb:12 # ListProductController GET to /products show a list of product's name and its icon
rspec ./API/spec/controllers/listproduct_controller_spec.rb:29 # ListProductController GET to /:id returns status 200 OK
rspec ./API/spec/controllers/listproduct_controller_spec.rb:33 # ListProductController GET to /:id displays the product's profil

Coverage report generated for RSpec to /builds/cymon1997/ppl-coba/coverage. 44 / 56 LOC (78.57%) covered.
ERROR: Job failed: exit code 

这是我的 mongoid.yml 文件:

development:
  options:
    raise_not_found_error: false
  clients:
    default:
      database: mongoid_dev
      hosts:
        - localhost:27017
test:
  options:
    raise_not_found_error: false
  clients:
    default:
      database: mongoid_dev
      hosts:
        - localhost:27017

谁能告诉我我错过了什么。我到处搜索 gitlab-ci 和数据库,但只搜索了 mysql 和 postgre sql 。我是否错过了在测试中运行 mongo 服务器?或者我应该从代码本身运行服务器吗?或者是另一个问题?


您的 MongoDB 很可能在 GitlabCI 上运行,但它是在单独的 Docker 容器中执行的。必须使用以下命令从测试中访问它mongo:27017, not localhost:27017.

检查这里:https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#accessing-the-services https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#accessing-the-services

所以你应该适当地修复你的配置(mongoid.yml)。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

MongoDB 服务器无法使用 gitlab-ci 在 gitlab runner 上启动 的相关文章

随机推荐

  • 存储过程的命名约定是什么? [关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • 如何在 GitHub 上使用 Laravel 包的 PR?

    当我想在 GitHub 上对 Laravel 包发出拉取请求时 我会按以下方式进行操作 创建新的 Laravel 项目 需要并安装包 从供应商文件夹中的项目中删除附加文件 Fork GitHub 并将文件克隆到项目文件夹中 更改打包并测试所
  • AJAX DJango 从多个文件字段获取文件

    我正在使用 AJAX 和 DJango 进行多个文件上传 但遇到问题 如何从字段输入获取文件并将其推送到data HTML
  • NLTK 使用语料库标记西班牙语单词

    我正在尝试学习如何使用 NLTK 标记西班牙语单词 来自NLTK书 http nltk org book ch05 html 使用它们的示例来标记英语单词非常容易 因为我对 nltk 和所有语言处理都很陌生 所以我对如何进行感到非常困惑 我
  • 在 Java 中分割命令行

    在 Java 中解析类似 shell 的命令行的推荐方法是什么 我的意思并不是说在选项已经处于数组形式时处理选项 例如处理 x 等 已经有很多关于此的问题和答案 不 我的意思是把完整的命令字符串分割成 令牌 我需要转换一个字符串 例如 us
  • 如何在 django 模板中减去两个 datetime.time 值,以及如何将持续时间格式化为小时、分钟

    在 django 应用程序中 我发送了一个列表Entry对象到模板 每个Entry对象有一个开始时间和结束时间 它们是 datetime time 值 从TimeFields在表单上 在列出条目对象时 我需要显示每个条目的持续时间 在模型中
  • 将 UserControl 序列化为 xaml,但不序列化其子控件?

    NET 4 0 中的 XAML 序列化堆栈进行了相当多的更改 其中一项更改是 当序列化 UserControl 时 您不仅可以获得控件本身 还可以获得其所有子控件 var sb new StringBuilder var writer Xm
  • 创建链接服务器和数据库别名

    我有两台服务器 Server1 和 Server2 在两台服务器上我都有一个名为 QAI 的数据库 有没有一种方法可以创建一个链接服务器 其别名从 Server2 到 Server1 而不是 服务器1 QAI dbo tbBlah 将其别名
  • 使用 Windows 调度程序运行 jar 文件

    我有 jar 文件 我想从 Windows 7 中的 Windows 调度程序运行该文件 我已经给出了路径java exe在路径 脚本中和 jar c abc ab jar在参数字段中 但它不运行 我也曾在bat文件的帮助下尝试过 但它无法
  • Bash:在 OS X 下查找字符串中字符的位置

    有没有办法找到字符串中第一个字符的位置Bash under Mac OS X 就像是 stringZ abcABC123ABCabc 6 echo expr index stringZ C12 C position 如中所述高级 Bash
  • 如何在 Python 中重新运行代码?

    我有这个单词解扰器游戏 仅在 CMD 或 python shell 中运行 当用户正确或错误地猜测单词时 它会显示 按任意键再次播放 我怎样才能让它重新开始 在评估用户的输入后不要让程序退出 相反 在循环中执行此操作 例如 一个甚至不使用函
  • CSS:在同一行有3个div,中间的div占据剩余空间

    我正在构建一个工具栏 我希望以下示例中的黄色部分占据整个左侧空间 白色 http jsfiddle net MWjGH 1 http jsfiddle net MWjGH 1 div class left Some content div
  • 一起运行 Tkinter 窗口和 PysTray 图标

    我正在构建一个 tkinter gui 项目 并且正在寻找使用 tkinter 窗口运行托盘图标的方法 我发现 Pystray 库可以做到这一点 但现在我正在尝试弄清楚如何将这个库 托盘图标 与 tkinter 窗口一起使用 我设置了当用户
  • 如何使用 OpenPyXL 设置带标题的列格式

    我正在尝试以日期格式设置某些列的格式 我能够使用以下命令成功更改单个单元格的格式 date style Style number format M D YYYY ws E7 style date style 但是除了标题之外 是否有更简单的
  • 由各种分隔符分割,同时保留分隔符?

    我想分割文本 过公元年 因为无论你如何选择 简体字危及了对古代文学的研究输入 使用这三个 或更多 字符作为分隔符 我当然可以这样做 lines preg split u body 但是我不想让结果行保留其结束分隔符 一个句子也可能这样结束啊
  • 如何检查 Bigquery 上列表的某个项目是否在另一个列表项目中?

    我有一个专栏 比如 11999999999 12999999999 31999999999 和另一列 例如 5511777777777 5512888888888 5531999999999 我想做一个CASE WHEN如果第一列上的任何项
  • model.fit 上的尺寸数量错误

    我正在尝试运行这个 SimpleRNN model add SimpleRNN init uniform output dim 1 input dim len pred frame columns model compile loss ms
  • 使用一个 Iron-ajax 元素处理多个请求

    理论上来说 应该可以使用一个iron ajax通过设置多个请求的元素auto属性 然后重复设置url元素上的属性 iron ajax有一个属性叫做activeRequests 这是一个只读数组 因此它似乎支持同时对多个请求进行排队 但实际上
  • 使用 Ruby 将 XML 请求发送到 Web 服务器

    恐怕我在通过网络服务器发布文档 例如 XML 方面没有太多经验 所以如果我对 HTTP 缺乏了解 我深表歉意 我在 ruby 应用程序中设置了一个基本的 Mongrel Web 服务器127 0 0 1 port 2000 服务器 我在同一
  • MongoDB 服务器无法使用 gitlab-ci 在 gitlab runner 上启动

    现在我正在使用 Ruby 和 Mongo 开发一个应用程序 但是当我使用 gitlab ci 部署应用程序时 我陷入了困境 似乎 mongo 服务器没有在 gitlab runner 的测试环境中启动 这是我的 gitlab ci yml