我想对一个真实的数据库运行一些集成测试,但我无法启动一个额外的容器(用于db),因为我需要在启动之前挂载我的repo中的一个配置文件。
这是我在本地计算机上使用数据库的方式(docker-compose):
gremlin-server:
image: tinkerpop/gremlin-server:3.5
container_name: 'gremlin-server'
entrypoint: ./bin/gremlin-server.sh conf/gremlin-server-config.yaml
networks:
- graphdb_net
ports:
- 8182:8182
volumes:
- ./conf/gremlin-server-config.yaml:/opt/gremlin-server/conf/gremlin-server-config.yaml
- ./conf/tinkergraph-empty.properties:/opt/gremlin-server/conf/tinkergraph-我想我不能使用a service container,因为在启动服务容器时代码不可用,因此它不会选择我的配置。
这就是为什么我尝试使用--network host在我的容器中运行一个容器(见下文),容器似乎运行得很好,但我仍然不能卷曲它。
- name: Start DB for tests
run: |
docker run -d \
--network host \
-v ${{ github.workspace }}/dev/conf/gremlin-server-config.yaml:/opt/gremlin-server/conf/gremlin-server-config.yaml \
-v ${{ github.workspace }}/dev/conf/tinkergraph-empty.properties:/opt/gremlin-server/conf/tinkergraph-empty.properties \
tinkerpop/gremlin-server:3.5
- name: Test connection
run: |
curl "localhost:8182/gremlin?gremlin=g.V().valueMap()"根据关于the job context的文档,容器网络的id应该是可用的({{job.container.network}}),但如果您不使用任何作业级服务或容器,则容器网络的id为空。
你知道我下一步该怎么做吗?
发布于 2021-11-08 10:31:44
这就是我最终得到的结果:我现在使用docker-compose来运行集成测试(在我的本地计算机上以及在GitHub操作上)。我只是将整个目录/repo挂载到test容器中。拉取node:14-slim会将构建延迟几秒钟,但我认为这仍然是最好的选择:
version: "3.2"
services:
gremlin-server:
image: tinkerpop/gremlin-server:3.5
container_name: 'gremlin-server'
entrypoint: ./bin/gremlin-server.sh conf/gremlin-server-config.yaml
networks:
- graphdb_net
ports:
- 8182:8182
volumes:
- ./data/:/opt/gremlin-server/data/
- ./conf/gremlin-server-config.yaml:/opt/gremlin-server/conf/gremlin-server-config.yaml
- ./conf/tinkergraph-empty.properties:/opt/gremlin-server/conf/tinkergraph-empty.properties
- ./conf/initData.groovy:/opt/gremlin-server/scripts/initData.groovy
test:
image: node:14-slim
working_dir: /app
depends_on:
- gremlin-server
networks:
- graphdb_net
volumes:
- ../:/app
environment:
- NEPTUNE_CONNECTION_STRING=ws://gremlin-server:8182
command:
yarn test
networks:
graphdb_net:
driver: bridge我在我的工作流程中像这样运行它们:
- name: Spin up test environment
run: |
docker compose -f dev/docker-compose.yaml pull
docker compose -f dev/docker-compose.yaml build
- name: Run tests
run: |
docker compose -f dev/docker-compose.yaml run test 这是基于@DannyB的建议和他的回答here,所以所有的道具都给他。
https://stackoverflow.com/questions/69852476
复制相似问题