gpt4 book ai didi

ruby - MongoDB 服务器不会使用 gitlab-ci 从 gitlab 运行程序启动

转载 作者:行者123 更新时间:2023-12-03 23:16:45 25 4
gpt4 key购买 nike

现在我正在使用 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 runner 错误的结果
    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 而不是 localhost:27017 从测试中访问它。

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

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

关于ruby - MongoDB 服务器不会使用 gitlab-ci 从 gitlab 运行程序启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49391372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com