3

I'd like to run some integration tests against a real database, but I fail to start an additional container (for the db), because I need to mount a config file that is in my repo before it is starting up.

This is how I use the database on my local computer (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-

I guess I cannot use a service container as the code is not available at the time the service container is started, therefore it won't pick up my configuration.

That's why I tried to run a container within my container using --network host (see below) and the container seems to be running fine, still I'm not able to curl it.

- 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()"

According to the documentation about the job context the id of the container network should be available ({{job.container.network}}) but is empty if you don’t use any job-level service or container.

Any ideas what I could try next?

Daniel
  • 874
  • 10
  • 31
  • 1
    I suggest you use your docker-compose in GitHub Actions, as it produces reliable and predictable results that are testable in dev - see https://stackoverflow.com/questions/64364989/github-actions-how-to-run-test-inside-container/64373702#64373702 – DannyB Nov 05 '21 at 12:42
  • I wish there was a way to use a service container for this, but I guess you're right. The approach you've suggested is definitely cleaner than tinkering around with network settings to establish a connection between host and container. – Daniel Nov 08 '21 at 07:59

1 Answers1

0

This is what I ended up with: I'm now using docker-compose to run the integration tests (on my local computer as well as on GitHub Actions). I'm just mounting the entire directory/repo in the test container. Pulling the node:14-slim delays the build by some seconds, but I guess it's still the best option:

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

and I'm running them like this in my workflow:

- 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  

It's based on @DannyB's suggestion and his answer here so all props go to him.

Daniel
  • 874
  • 10
  • 31