Ali*_*ghi 10 ruby-on-rails gitlab-ci gitlab-ci-runner
我在我的 rails 应用程序中使用 gitlab-ci,它一直运行到昨天,但它没有通过,因为:
rake aborted!
PG::ConnectionBad: could not translate host name "postgres" to address: Name does not resolve
/usr/local/bundle/gems/pg-1.1.4/lib/pg.rb:56:in `initialize'
/usr/local/bundle/gems/pg-1.1.4/lib/pg.rb:56:in `new'
/usr/local/bundle/gems/pg-1.1.4/lib/pg.rb:56:in `connect'
....
Tasks: TOP => db:schema:load => db:check_protected_environments
Run Code Online (Sandbox Code Playgroud)
.gitlab-ci.yml :
rspec:
stage: test
services:
- postgres:10
variables:
DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB"
POSTGRES_DB: db_test
RAILS_ENV: test
before_script:
- ruby -v
script:
- cp config/application.sample.yml config/application.yml
- cp config/database.sample.yml config/database.yml
- bundle exec rake db:schema:load
- bundle exec rspec spec
Run Code Online (Sandbox Code Playgroud)
似乎找不到正在运行的 postgres 服务,或者由于某种原因数据库服务没有正确运行,我猜 gitlab-ci 中的某些内部结构发生了变化。
brx*_*xck 12
编辑:这是对图像的有意更改,您现在必须设置密码或进一步配置:
如果您知道自己想要不安全(即任何人都可以从任何地方无需密码即可连接),那么 POSTGRES_HOST_AUTH_METHOD=trust 就是您选择加入的方式。
这似乎是在 docker 镜像升级到新版本时引入的。
您可以改为拉取 10.11 镜像,暂时避免此问题:
services:
- postgres:10.11
Run Code Online (Sandbox Code Playgroud)
不知道为什么会发生这种情况,但自上次 docker image update以来,我们遇到了同样的情况。我发现从 12.1 到 12.2 也是如此。