无法在GitLab CI docker-in-docker中对neo4j数据库运行测试
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无法在GitLab CI docker-in-docker中对neo4j数据库运行测试相关的知识,希望对你有一定的参考价值。
问题
我正在尝试在GitLab CI中运行单元测试。对于我的测试设置,我正在使用docker-compose启动包含三个neo4j实例的数据库集群,然后通过本地主机在docker主机上运行测试。
在我的机器上,这很好用,所以我尝试在GitLab CI上做同样的事情。我最初在使docker-compose在CI容器中运行时遇到了一些问题,但是我设法通过以下.gitlab-ci.yaml来实现:
image: "tiangolo/docker-with-compose:latest"
before_script:
- apk add --update nodejs npm
- npm install npm@latest -g
- npm install
services:
- docker:dind
run-test:
script:
- docker-compose up -d --build
- npm test
安装依赖项,docker-compose成功启动数据库,npm test
运行我的单元测试。到目前为止,一切都很好。 但是所有以某种形式使用数据库连接的测试均失败,因为它们无法通过localhost:7687到达它]。我收到以下错误消息
Neo4jError: Could not perform discovery. No routing servers available. Known routing table: RoutingTable[database=default database, expirationTime=0, currentTime=1588275075260, routers=[], readers=[], writers=[]]
请记住,我在本地计算机上使用相同的docker-compose.yaml,并且一切正常,因此数据库配置应该不会有问题。
我已经尝试过的内容
我认为我的测试正在完全启动数据库之前运行,所以我像这样添加了sleep 120
run-test: script: - docker-compose up -d --build - sleep 120 - npm test
我什至测量了群集在CI容器内启动所花费的时间,并选择了适当的超时时间,但是没有运气,测试仍然失败。
然后我看了看docker网络,看那里是否出了问题
$ cat /etc/hosts 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters 172.17.0.2 docker 3590cde9c5df runner-k3xtxnwc-project-17881831-concurrent-0-6d9d78b64ad6df95-docker-0 172.17.0.3 runner-k3xtxnwc-project-17881831-concurrent-0 $ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' core1 172.19.0.2 $ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' core2 172.19.0.4
但是那对我来说很好。然后,我尝试用
localhost:7678
,docker:7678
甚至172.0.0.1
替换$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' core1):7678
。但是它们都不起作用。
尝试到curl localhost:7474
(neo4j http控制台)将返回Failed to connect to localhost port 7474: Connection refused
编辑:
我的docker-compose.yaml
version: '3' services: dbc1: build: ./database container_name: core1 hostname: core1 ports: - 7474:7474 - 7687:7687 environment: - NEO4J_dbms_mode=CORE - NEO4J_causal__clustering_minimum__core__cluster__size__at__formation=3 - NEO4J_causal__clustering_minimum__core__cluster__size__at__runtime=3 - NEO4J_causal__clustering_initial__discovery__members=core1:5000,core2:5000,core3:5000 - NEO4J_ACCEPT_LICENSE_AGREEMENT=yes - NEO4J_dbms_connector_bolt_advertised__address=localhost:7687 - NEO4J_dbms_connector_http_advertised__address=localhost:7474 volumes: - dbdata1:/data ulimits: nofile: soft: 40000 hard: 40000 dbc2: build: ./database container_name: core2 hostname: core2 ports: - 8474:7474 - 8687:7687 environment: - NEO4J_dbms_mode=CORE - NEO4J_causal__clustering_minimum__core__cluster__size__at__formation=3 - NEO4J_causal__clustering_minimum__core__cluster__size__at__runtime=3 - NEO4J_causal__clustering_initial__discovery__members=core1:5000,core2:5000,core3:5000 - NEO4J_ACCEPT_LICENSE_AGREEMENT=yes - NEO4J_dbms_connector_bolt_advertised__address=localhost:8687 - NEO4J_dbms_connector_http_advertised__address=localhost:8474 volumes: - dbdata2:/data ulimits: nofile: soft: 40000 hard: 40000 dbc3: build: ./database container_name: core3 hostname: core3 ports: - 9474:7474 - 9687:7687 environment: - NEO4J_dbms_mode=CORE - NEO4J_causal__clustering_minimum__core__cluster__size__at__formation=3 - NEO4J_causal__clustering_minimum__core__cluster__size__at__runtime=3 - NEO4J_causal__clustering_initial__discovery__members=core1:5000,core2:5000,core3:5000 - NEO4J_ACCEPT_LICENSE_AGREEMENT=yes - NEO4J_dbms_connector_bolt_advertised__address=localhost:9687 - NEO4J_dbms_connector_http_advertised__address=localhost:9474 volumes: - dbdata3:/data ulimits: nofile: soft: 40000 hard: 40000 volumes: dbdata1: driver: local dbdata2: driver: local dbdata3: driver: local
我的数据库Dockerfile(位于./database中:]]
FROM graphfoundation/ongdb:3.6 RUN echo "* soft nofile 40000" >> /etc/security/limits.conf RUN echo "* hard nofile 40000" >> /etc/security/limits.conf ## inject password change into startup script # create alternative startup script RUN echo "#!/bin/bash -eu" >> /docker-entrypoint-modified.sh # add command to change password RUN echo "bin/neo4j-admin set-initial-password testpassword" >> /docker-entrypoint-modified.sh # copy the contents of docker-entrypoint.sh, but skip the first line RUN tail -n +2 /docker-entrypoint.sh >> /docker-entrypoint-modified.sh # replace docker-entrypoint.sh with docker-entrypoint-modify RUN cat /docker-entrypoint-modified.sh > /docker-entrypoint.sh EXPOSE 7474 7473 7687
我正在尝试在GitLab CI中运行单元测试的问题。对于我的测试设置,我正在使用docker-compose启动包含三个neo4j实例的数据库集群,然后在docker上运行测试...
原来我对docker-in-docker有一些误解,我通过更改.gitlab-ci.yaml
中的以下行,通过将localhost“重新路由到docker-in-docker服务,解决了该问题:
services:
- docker:dind
以上是关于无法在GitLab CI docker-in-docker中对neo4j数据库运行测试的主要内容,如果未能解决你的问题,请参考以下文章
Gitlab CI runner 无法暴露嵌套 Docker 容器的端口
无法在 Windows 服务器上使用 docker 为 gitlab-ci 运行构建