繁体   English   中英

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

[英]Start database container with mounted config file in Github actions workflow

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

这是我在本地计算机 (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-

我想我不能使用服务容器,因为在服务容器启动时代码不可用,因此它不会选择我的配置。

这就是为什么我尝试使用--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()"

根据有关作业上下文的文档,容器网络的 id 应该可用( {{job.container.network}} )但如果​​您不使用任何作业级服务或容器,则为空。

任何想法我接下来可以尝试什么?

这就是我的结果:我现在使用 docker-compose 来运行集成测试(在我的本地计算机以及 GitHub Actions 上)。 我只是在test容器中安装整个目录/repo。 拉动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 的建议和他在此处的回答因此所有道具都归他所有。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM