Gitlab CI 无法连接到服务

Gitlab CI can't connect to service

我正在尝试 运行 对我在 gitlab 上的容器进行集成测试。

为了尽可能减少事情,这里是我的 .gitlab-ci.yml

的相关部分
image: ubuntu:latest

coverage:
    stage: test
    dependencies:
        - build
    services:
        - postgres:latest
        - registry.gitlab.com/username/project/image:latest

当我尝试 运行 作业时,我收到容器运行状况检查警告。

2019-06-06T02:13:34.508595817Z FATAL: No HOST or PORT found

通常我会以标准 docker run -p port:port image:version 开始我的图像,但我不确定这些选项如何转化为 gitlab 服务。如何定义主机和端口?

下面是连接到 postgres 的示例管道。

容器将服务别名作为容器名称,除非您明确地使用别名 here

services:
- name: postgres:9.4


variables:
  # Configure postgres service (https://hub.docker.com/_/postgres/)
  POSTGRES_DB: $DB_NAME
  POSTGRES_USER: $DB_USER
  POSTGRES_PASSWORD: $DB_PASS

cache:
  paths:
  - node_modules/*

stages:
  - test
  - build


db-test:
  stage: test
  image: ubuntu:latest
  tags:
    - consultancy
    - shared
  script:
    #set server connection env vars
  - export PGPASSWORD=$POSTGRES_PASSWORD
  - apt-get update -y && apt-get install postgresql postgresql-contrib -y
  - psql -h "postgres" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "SELECT 'OK' AS status;" #ensure the service is running

node-test:
  stage: test
  image: node:latest
  tags:
  - consultancy
  - shared
  script:
    - npm install # Install Node dependencies
    - npm run test-unit # Execute unit testing suite
#
integration-tests:
  stage: test
  image: node:latest
  tags:
  - consultancy
  - shared
  script:
  - export PGUSER=$POSTGRES_USER
  - export PGHOST=postgres
  - export PGPASSWORD=$POSTGRES_PASSWORD
  - export PGDATABASE=postgres
  - export PGPORT=5432 #set the integration test env vars
  - npm install # Install Node dependencies
  - npm run test-integration # Execute integration testing suite

在我的例子中,没有 EXPOSE 的 Dockerfile 会在 ci runner 中给出错误的日志消息:

Health check error:
exit code 1

Health check container logs:
2020-05-12T03:42:49.645731131Z No HOST or PORT

已通过在 Dockerfile 中公开服务端口修复。