Advice on JanusGraph Docker Image Startup Scripts

26 Views Asked by At

I would like to have an idempotent startup script which initializes my database. In particular, I would like to define the schema (labels, properties, indexes, and constraints). I am using JanusGraph inside of a Docker container, and I am required to frequently teardown/rebuild from the container image. I have a very sloppy working approach, but I have been unable to improve upon it.

I have read this question, but my use case is different since I am trying to configure the database, rather than simply load data. I have also read the section of the JanusGraph documentation on using .groovy scripts to populate data, but similarly this doesn't cover my use case. As defined in the section on defining a schema, I would like to create labels/properties/indexes/constraints, and I want this to be done automatically when the database starts.

My current setup is very poor. I connect to the JanusGraph instance similarly to how you do in the Gremlin console with :remote connect tinkerpop.server conf/remote.yaml. Below is my current setup:

version: '3.8'

services:
  btc_janus:
    build:
      context: ./janusgraph/
    container_name: btc_janus
    shm_size: 2g
    ports:
      - "${JANUSGRAPH_PORT:-8182}:${JANUSGRAPH_PORT:-8182}"
      - "8484:8184"
      - "8081:8081"
    networks:
      - btc-network
    volumes:
      - ${GRAPH_DB_FOLDER:-./data/btc_janus}:/var/lib/janusgraph
    healthcheck:
      test: ["CMD", "bin/gremlin.sh", "-e", "scripts/remote-connect.groovy"]
      interval: 10s
      timeout: 60s
      retries: 4
    environment:
      janusgraph.storage.backend: berkeleyje
      janusgraph.tx.log-tx: true
      janusgraph.tx.max-commit-time: 100000000000
#  ./janusgraph/Dockerfile

FROM janusgraph/janusgraph:latest

ENV JAVA_OPTS=" -Xss4096k "
ENV JAVA_OPTIONS="-Xss4096k"
ENV JVM_OPTS="-Xss4096k"

# Copy the index creation script
COPY create_index.groovy /docker-entrypoint-initdb.d/create_index.groovy
// ./janusgraph/create_index.groovy

:remote connect tinkerpop.server conf/remote.yaml
:remote console

:> graph.tx().rollback(); mgmt = graph.openManagement(); idKey = mgmt.containsPropertyKey('output_id') ? mgmt.getPropertyKey('output_id') : mgmt.makePropertyKey('output_id').dataType(Integer.class).make(); addressKey = mgmt.containsPropertyKey('address_id') ? mgmt.getPropertyKey('address_id') : mgmt.makePropertyKey('address_id').dataType(Integer.class).make(); if (!mgmt.containsGraphIndex('byOutputIdComposite')) { mgmt.buildIndex('byOutputIdComposite', Vertex.class).addKey(idKey).buildCompositeIndex(); }; if (!mgmt.containsGraphIndex('byAddressIdComposite')) { mgmt.buildIndex('byAddressIdComposite', Vertex.class).addKey(addressKey).buildCompositeIndex(); }; mgmt.commit();

As you can see, the above approach is very messy. Everything is forced to be on one line. Adding any more schema specifications would be challenging. Is there a better approach to creating JanusGraph startup scripts?

0

There are 0 best solutions below