连接使用gitlab ci中的Postgres拒绝使用Elixir/Phoenix

发布于 2025-01-23 08:44:22 字数 1908 浏览 0 评论 0原文

在试图在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更改为db127.0.0.0.1Postgres:// 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撑一把青伞 2025-01-30 08:44:22

.gitlab-ci.yml中删除postgres_host = localhost。 SET Gerard_test_db_hostname = Postgres

请参阅: gitlab docs:访问服务

Remove POSTGRES_HOST=localhost from .gitlab-ci.yml. Set GERARD_TEST_DB_HOSTNAME=postgres.

See: GitLab Docs: Accessing the Services

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文