首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Github操作工作流中使用挂载的配置文件启动数据库容器

在Github操作工作流中使用挂载的配置文件启动数据库容器
EN

Stack Overflow用户
提问于 2021-11-05 11:21:39
回答 1查看 46关注 0票数 0

我想对一个真实的数据库运行一些集成测试,但我无法启动一个额外的容器(用于db),因为我需要在启动之前挂载我的repo中的一个配置文件。

这是我在本地计算机上使用数据库的方式(docker-compose):

代码语言:javascript
复制
 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在我的容器中运行一个容器(见下文),容器似乎运行得很好,但我仍然不能卷曲它。

代码语言:javascript
复制
- 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为空。

你知道我下一步该怎么做吗?

EN

回答 1

Stack Overflow用户

发布于 2021-11-08 10:31:44

这就是我最终得到的结果:我现在使用docker-compose来运行集成测试(在我的本地计算机上以及在GitHub操作上)。我只是将整个目录/repo挂载到test容器中。拉取node:14-slim会将构建延迟几秒钟,但我认为这仍然是最好的选择:

代码语言:javascript
复制
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

我在我的工作流程中像这样运行它们:

代码语言:javascript
复制
- 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,所以所有的道具都给他。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69852476

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档