gitlab ci错误无法将主机名“ postgres”转换为地址:名称无法解析

问题描述 投票:2回答:2

我在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

。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

似乎无法找到postgres服务正在运行,或者由于某种原因数据库服务未正确运行,我想gitlab-ci中的某些内部组件已更改。

ruby-on-rails gitlab-ci gitlab-ci-runner
2个回答
1
投票

编辑:这是对图像的预期更改,you now must set a password or configure further:

如果您知道自己不安全(即任何人都可以在没有密码的情况下从任何地方进行连接),则选择采用POSTGRES_HOST_AUTH_METHOD = trust。


这似乎是在将Docker映像升级到new releases时引入的。

您可以暂时拉出10.11图像以避免此问题:

services:
- postgres:10.11

不确定为什么会这样,但是从last docker image update开始,我们正在经历同样的事情。我发现从12.1到12.2也是如此。


0
投票

postgres具有两个必需的环境变量名称POSTGRES_USERPOSTGRES_PASSWORD(如果未提供),则容器将不会运行。

gitlab-ci documentation about services

© www.soinside.com 2019 - 2024. All rights reserved.