连接使用gitlab ci中的Postgres拒绝使用Elixir/Phoenix
在试图在Gitlab CI中构建测试管道时,我面临Postgres服务的连接问题。
工作执行的输出是:
$ mix ecto.setup
19:42:34.864 [error] GenServer #PID<0.345.0> terminating
** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
(db_connection) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
(connection) lib/connection.ex:622: Connection.enter_connect/5
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: nil
** (Mix) The database for Gerard.Repo couldn't be created: killed
这就是我的.gitlab-ci.yml
看起来像:
.gitlab-ci.yml
before_script:
- mix local.rebar --force
- mix local.hex --force
- mix deps.get --only test
- mix compile
test:
stage: test
image: elixir:1.7.4
services:
- redis:5.0.4
- rabbitmq:3-management
- localstack/localstack:latest
- postgres
variables:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: gerard_test
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
MIX_ENV: "test"
cache:
paths:
- _build
- deps
script:
- mix ecto.setup
- mix ecto.create
- mix ecto.migrate
- mix test
,这就是我的的方式test.exs
文件外观:
test.exs
config :gerard, Gerard.Repo,
username: System.get_env("GERARD_TEST_DB_USERNAME") || "postgres",
password: System.get_env("GERARD_TEST_DB_PASSWORD") || "postgres",
database: System.get_env("GERARD_TEST_DB") || "gerard_test",
hostname: System.get_env("GERARD_TEST_DB_HOSTNAME") || "localhost",
ownership_timeout: 900_000,
timeout: 900_000,
pool: Ecto.Adapters.SQL.Sandbox
还试图将postgres_host更改为db
,127.0.0.0.1
和Postgres:// Postgres:Postgres@Postgres/gerard_test?
bot eres erv
While trying to build a test pipeline in Gitlab CI I faced a connection problem with the postgres service.
The output from the job execution is this:
$ mix ecto.setup
19:42:34.864 [error] GenServer #PID<0.345.0> terminating
** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
(db_connection) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
(connection) lib/connection.ex:622: Connection.enter_connect/5
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: nil
** (Mix) The database for Gerard.Repo couldn't be created: killed
This is how my .gitlab-ci.yml
looks like:
.gitlab-ci.yml
before_script:
- mix local.rebar --force
- mix local.hex --force
- mix deps.get --only test
- mix compile
test:
stage: test
image: elixir:1.7.4
services:
- redis:5.0.4
- rabbitmq:3-management
- localstack/localstack:latest
- postgres
variables:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: gerard_test
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
MIX_ENV: "test"
cache:
paths:
- _build
- deps
script:
- mix ecto.setup
- mix ecto.create
- mix ecto.migrate
- mix test
and this is how my test.exs
file looks:
test.exs
config :gerard, Gerard.Repo,
username: System.get_env("GERARD_TEST_DB_USERNAME") || "postgres",
password: System.get_env("GERARD_TEST_DB_PASSWORD") || "postgres",
database: System.get_env("GERARD_TEST_DB") || "gerard_test",
hostname: System.get_env("GERARD_TEST_DB_HOSTNAME") || "localhost",
ownership_timeout: 900_000,
timeout: 900_000,
pool: Ecto.Adapters.SQL.Sandbox
Also tried to change the POSTGRES_HOST to db
, 127.0.0.1
and postgres://postgres:postgres@postgres/gerard_test?
bot none of these worked
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从
.gitlab-ci.yml
中删除postgres_host = localhost
。 SETGerard_test_db_hostname = Postgres
。请参阅: gitlab docs:访问服务
Remove
POSTGRES_HOST=localhost
from.gitlab-ci.yml
. SetGERARD_TEST_DB_HOSTNAME=postgres
.See: GitLab Docs: Accessing the Services