Rya*_*yan 9 gitlab gitlab-ci gitlab-ci-runner
我正在尝试在 gitlab 上对我的容器运行集成测试。
为了使事情尽可能简单,以下是我的相关部分.gitlab-ci.yml
image: ubuntu:latest
coverage:
stage: test
dependencies:
- build
services:
- postgres:latest
- registry.gitlab.com/username/project/image:latest
Run Code Online (Sandbox Code Playgroud)
当我尝试运行该作业时,我收到容器运行状况检查警告。
2019-06-06T02:13:34.508595817Z FATAL: No HOST or PORT found
通常我会从标准开始我的图像docker run -p port:port image:version,但我不确定这些选项如何转化为 gitlab 服务。如何定义主机和端口?
小智 9
就我而言,没有 的 DockerfileEXPOSE会在 ci runner 中给出错误的日志消息:
Health check error:
exit code 1
Health check container logs:
2020-05-12T03:42:49.645731131Z No HOST or PORT
Run Code Online (Sandbox Code Playgroud)
通过在 Dockerfile 中公开服务端口来修复。
小智 1
下面是连接到 postgres 的示例管道。
容器将服务别名为容器名称,除非您明确指定别名,如下所示
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
Run Code Online (Sandbox Code Playgroud)