Skip to content
This repository has been archived by the owner on Oct 15, 2023. It is now read-only.

Add gremlin-console containers to compose configuration and support in entrypoint #21

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 32 additions & 15 deletions 0.2/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ JANUS_PROPS="${JANUS_CONFIG_DIR}/janusgraph.properties"
GREMLIN_YAML="${JANUS_CONFIG_DIR}/gremlin-server.yaml"

# running as root; step down to run as janusgraph user
if [ "$1" == 'janusgraph' ] && [ "$(id -u)" == "0" ]; then
if [[ "$(id -u)" == "0" ]] && [[ "$1" == 'janusgraph' || "$1" == 'gremlin-console' || "$1" == 'gremlin-console-remote' ]]; then
echo "Running root setup steps for '$1'"
mkdir -p ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}
chown -R janusgraph:janusgraph ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}
usermod -d ${JANUS_HOME} janusgraph
chmod 700 ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}

exec chroot --skip-chdir --userspec janusgraph:janusgraph / "${BASH_SOURCE}" "$@"
fi

# running as non root user
if [ "$1" == 'janusgraph' ]; then
if [[ "$1" == 'janusgraph' || "$1" == 'gremlin-console' || "$1" == 'gremlin-console-remote' ]] ; then
echo "Running non-root setup steps for '$1'"
# setup config directory
mkdir -p ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}
cp conf/gremlin-server/janusgraph-${JANUS_PROPS_TEMPLATE}-server.properties ${JANUS_CONFIG_DIR}/janusgraph.properties
Expand All @@ -40,6 +43,11 @@ if [ "$1" == 'janusgraph' ]; then
chmod 700 ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}
chmod -R 600 ${JANUS_CONFIG_DIR}/*

# override hosts for remote connections with Gremlin Console
if ! [ -z "${GREMLIN_REMOTE_HOSTS:-}" ]; then
sed -i "s/hosts\s*:.*/hosts: [$GREMLIN_REMOTE_HOSTS]/" ${JANUS_HOME}/conf/remote.yaml
fi

# apply configuration from environment
while IFS='=' read -r envvar_key envvar_val; do
if [[ "${envvar_key}" =~ janusgraph\. ]] && [[ ! -z ${envvar_val} ]]; then
Expand Down Expand Up @@ -68,22 +76,31 @@ if [ "$1" == 'janusgraph' ]; then
cat "$GREMLIN_YAML"
exit 0
else
# wait for storage
if ! [ -z "${JANUS_STORAGE_TIMEOUT:-}" ]; then
F="$(mktemp --suffix .groovy)"
echo "graph = JanusGraphFactory.open('${JANUS_CONFIG_DIR}/janusgraph.properties')" > $F
timeout "${JANUS_STORAGE_TIMEOUT}s" bash -c \
"until bin/gremlin.sh -e $F > /dev/null 2>&1; do echo \"waiting for storage...\"; sleep 5; done"
rm -f "$F"
if [ "$1" == 'janusgraph' ] ; then
# wait for storage
if ! [ -z "${JANUS_STORAGE_TIMEOUT:-}" ]; then
F="$(mktemp --suffix .groovy)"
echo "graph = JanusGraphFactory.open('${JANUS_CONFIG_DIR}/janusgraph.properties')" > $F
timeout -k 10 "${JANUS_STORAGE_TIMEOUT}s" bash -c \
"until bin/gremlin.sh -e $F > /dev/null 2>&1; do echo \"waiting for storage...\"; sleep 5; done"
rm -f "$F"
fi
echo "Starting janusgraph gremlin server"
exec ${JANUS_HOME}/bin/gremlin-server.sh ${JANUS_CONFIG_DIR}/gremlin-server.yaml
fi

exec ${JANUS_HOME}/bin/gremlin-server.sh ${JANUS_CONFIG_DIR}/gremlin-server.yaml
fi
fi
if [ "$1" == 'gremlin-console-remote' ] ; then
echo "Starting gremlin remote console"
exec ${JANUS_HOME}/bin/gremlin.sh -i scripts/remote-connect.groovy
fi

# override hosts for remote connections with Gremlin Console
if ! [ -z "${GREMLIN_REMOTE_HOSTS:-}" ]; then
sed -i "s/hosts\s*:.*/hosts: [$GREMLIN_REMOTE_HOSTS]/" ${JANUS_HOME}/conf/remote.yaml
if [ "$1" == 'gremlin-console' ] ; then
echo "Starting gremlin console"
C=$(mktemp --suffix .groovy)
echo "graph = JanusGraphFactory.open('${JANUS_CONFIG_DIR}/janusgraph.properties')" > $C
exec ${JANUS_HOME}/bin/gremlin.sh -i $C
fi
fi
fi

exec "$@"
47 changes: 32 additions & 15 deletions 0.3/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ JANUS_PROPS="${JANUS_CONFIG_DIR}/janusgraph.properties"
GREMLIN_YAML="${JANUS_CONFIG_DIR}/gremlin-server.yaml"

# running as root; step down to run as janusgraph user
if [ "$1" == 'janusgraph' ] && [ "$(id -u)" == "0" ]; then
if [[ "$(id -u)" == "0" ]] && [[ "$1" == 'janusgraph' || "$1" == 'gremlin-console' || "$1" == 'gremlin-console-remote' ]]; then
echo "Running root setup steps for '$1'"
mkdir -p ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}
chown -R janusgraph:janusgraph ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}
usermod -d ${JANUS_HOME} janusgraph
chmod 700 ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}

exec chroot --skip-chdir --userspec janusgraph:janusgraph / "${BASH_SOURCE}" "$@"
fi

# running as non root user
if [ "$1" == 'janusgraph' ]; then
if [[ "$1" == 'janusgraph' || "$1" == 'gremlin-console' || "$1" == 'gremlin-console-remote' ]] ; then
echo "Running non-root setup steps for '$1'"
# setup config directory
mkdir -p ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}
cp conf/gremlin-server/janusgraph-${JANUS_PROPS_TEMPLATE}-server.properties ${JANUS_CONFIG_DIR}/janusgraph.properties
Expand All @@ -40,6 +43,11 @@ if [ "$1" == 'janusgraph' ]; then
chmod 700 ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}
chmod -R 600 ${JANUS_CONFIG_DIR}/*

# override hosts for remote connections with Gremlin Console
if ! [ -z "${GREMLIN_REMOTE_HOSTS:-}" ]; then
sed -i "s/hosts\s*:.*/hosts: [$GREMLIN_REMOTE_HOSTS]/" ${JANUS_HOME}/conf/remote.yaml
fi

# apply configuration from environment
while IFS='=' read -r envvar_key envvar_val; do
if [[ "${envvar_key}" =~ janusgraph\. ]] && [[ ! -z ${envvar_val} ]]; then
Expand Down Expand Up @@ -68,22 +76,31 @@ if [ "$1" == 'janusgraph' ]; then
cat "$GREMLIN_YAML"
exit 0
else
# wait for storage
if ! [ -z "${JANUS_STORAGE_TIMEOUT:-}" ]; then
F="$(mktemp --suffix .groovy)"
echo "graph = JanusGraphFactory.open('${JANUS_CONFIG_DIR}/janusgraph.properties')" > $F
timeout "${JANUS_STORAGE_TIMEOUT}s" bash -c \
"until bin/gremlin.sh -e $F > /dev/null 2>&1; do echo \"waiting for storage...\"; sleep 5; done"
rm -f "$F"
if [ "$1" == 'janusgraph' ] ; then
# wait for storage
if ! [ -z "${JANUS_STORAGE_TIMEOUT:-}" ]; then
F="$(mktemp --suffix .groovy)"
echo "graph = JanusGraphFactory.open('${JANUS_CONFIG_DIR}/janusgraph.properties')" > $F
timeout -k 10 "${JANUS_STORAGE_TIMEOUT}s" bash -c \
"until bin/gremlin.sh -e $F > /dev/null 2>&1; do echo \"waiting for storage...\"; sleep 5; done"
rm -f "$F"
fi
echo "Starting janusgraph gremlin server"
exec ${JANUS_HOME}/bin/gremlin-server.sh ${JANUS_CONFIG_DIR}/gremlin-server.yaml
fi

exec ${JANUS_HOME}/bin/gremlin-server.sh ${JANUS_CONFIG_DIR}/gremlin-server.yaml
fi
fi
if [ "$1" == 'gremlin-console-remote' ] ; then
echo "Starting gremlin remote console"
exec ${JANUS_HOME}/bin/gremlin.sh -i scripts/remote-connect.groovy
fi

# override hosts for remote connections with Gremlin Console
if ! [ -z "${GREMLIN_REMOTE_HOSTS:-}" ]; then
sed -i "s/hosts\s*:.*/hosts: [$GREMLIN_REMOTE_HOSTS]/" ${JANUS_HOME}/conf/remote.yaml
if [ "$1" == 'gremlin-console' ] ; then
echo "Starting gremlin console"
C=$(mktemp --suffix .groovy)
echo "graph = JanusGraphFactory.open('${JANUS_CONFIG_DIR}/janusgraph.properties')" > $C
exec ${JANUS_HOME}/bin/gremlin.sh -i $C
fi
fi
fi

exec "$@"
47 changes: 32 additions & 15 deletions 0.4/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ JANUS_PROPS="${JANUS_CONFIG_DIR}/janusgraph.properties"
GREMLIN_YAML="${JANUS_CONFIG_DIR}/gremlin-server.yaml"

# running as root; step down to run as janusgraph user
if [ "$1" == 'janusgraph' ] && [ "$(id -u)" == "0" ]; then
if [[ "$(id -u)" == "0" ]] && [[ "$1" == 'janusgraph' || "$1" == 'gremlin-console' || "$1" == 'gremlin-console-remote' ]]; then
echo "Running root setup steps for '$1'"
mkdir -p ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}
chown -R janusgraph:janusgraph ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}
usermod -d ${JANUS_HOME} janusgraph
chmod 700 ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}

exec chroot --skip-chdir --userspec janusgraph:janusgraph / "${BASH_SOURCE}" "$@"
fi

# running as non root user
if [ "$1" == 'janusgraph' ]; then
if [[ "$1" == 'janusgraph' || "$1" == 'gremlin-console' || "$1" == 'gremlin-console-remote' ]] ; then
echo "Running non-root setup steps for '$1'"
# setup config directory
mkdir -p ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}
cp conf/gremlin-server/janusgraph-${JANUS_PROPS_TEMPLATE}-server.properties ${JANUS_CONFIG_DIR}/janusgraph.properties
Expand All @@ -40,6 +43,11 @@ if [ "$1" == 'janusgraph' ]; then
chmod 700 ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}
chmod -R 600 ${JANUS_CONFIG_DIR}/*

# override hosts for remote connections with Gremlin Console
if ! [ -z "${GREMLIN_REMOTE_HOSTS:-}" ]; then
sed -i "s/hosts\s*:.*/hosts: [$GREMLIN_REMOTE_HOSTS]/" ${JANUS_HOME}/conf/remote.yaml
fi

# apply configuration from environment
while IFS='=' read -r envvar_key envvar_val; do
if [[ "${envvar_key}" =~ janusgraph\. ]] && [[ ! -z ${envvar_val} ]]; then
Expand Down Expand Up @@ -68,22 +76,31 @@ if [ "$1" == 'janusgraph' ]; then
cat "$GREMLIN_YAML"
exit 0
else
# wait for storage
if ! [ -z "${JANUS_STORAGE_TIMEOUT:-}" ]; then
F="$(mktemp --suffix .groovy)"
echo "graph = JanusGraphFactory.open('${JANUS_CONFIG_DIR}/janusgraph.properties')" > $F
timeout "${JANUS_STORAGE_TIMEOUT}s" bash -c \
"until bin/gremlin.sh -e $F > /dev/null 2>&1; do echo \"waiting for storage...\"; sleep 5; done"
rm -f "$F"
if [ "$1" == 'janusgraph' ] ; then
# wait for storage
if ! [ -z "${JANUS_STORAGE_TIMEOUT:-}" ]; then
F="$(mktemp --suffix .groovy)"
echo "graph = JanusGraphFactory.open('${JANUS_CONFIG_DIR}/janusgraph.properties')" > $F
timeout -k 10 "${JANUS_STORAGE_TIMEOUT}s" bash -c \
"until bin/gremlin.sh -e $F > /dev/null 2>&1; do echo \"waiting for storage...\"; sleep 5; done"
rm -f "$F"
fi
echo "Starting janusgraph gremlin server"
exec ${JANUS_HOME}/bin/gremlin-server.sh ${JANUS_CONFIG_DIR}/gremlin-server.yaml
fi

exec ${JANUS_HOME}/bin/gremlin-server.sh ${JANUS_CONFIG_DIR}/gremlin-server.yaml
fi
fi
if [ "$1" == 'gremlin-console-remote' ] ; then
echo "Starting gremlin remote console"
exec ${JANUS_HOME}/bin/gremlin.sh -i scripts/remote-connect.groovy
fi

# override hosts for remote connections with Gremlin Console
if ! [ -z "${GREMLIN_REMOTE_HOSTS:-}" ]; then
sed -i "s/hosts\s*:.*/hosts: [$GREMLIN_REMOTE_HOSTS]/" ${JANUS_HOME}/conf/remote.yaml
if [ "$1" == 'gremlin-console' ] ; then
echo "Starting gremlin console"
C=$(mktemp --suffix .groovy)
echo "graph = JanusGraphFactory.open('${JANUS_CONFIG_DIR}/janusgraph.properties')" > $C
exec ${JANUS_HOME}/bin/gremlin.sh -i $C
fi
fi
fi

exec "$@"
30 changes: 21 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,30 @@ gremlin> :> g.V().values('name')

### Using Docker Compose

Start a JanusGraph Server instance using [`docker-compose.yml`](docker-compose.yml):
Two docker-compose configurations are available, each supports different storage backend configuration:

`docker-compose.yml` - Runs Janusgraph using only the Berkeley DB storage backend.
`docker-compose-cql-es.yml` - Runs Janusgraph server with Cassandra + CQL for storage and Elasticearch for indexing.

Start a JanusGraph Server instance using one of the above compose files:

```bash
docker-compose -f docker-compose.yml up
# BerkeleyDB
docker-compose up
# OR
# Cassandra + CQL and Elasticsearch
docker-compose -f docker-compose-cql-es.yml up
```

Start a JanusGraph container running Gremlin Console in the same network using
[`docker-compose.yml`](docker-compose.yml):
The compose configurations also include a JanusGraph container running Gremlin Console in the same network.
You can attach to the console and start using it:

```bash
docker-compose -f docker-compose.yml run --rm \
-e GREMLIN_REMOTE_HOSTS=janusgraph janusgraph ./bin/gremlin.sh
# BerkeleyDB
docker attach janusgraph-default-gremlin-console
# OR
# Cassandra + CQL and Elasticsearch
docker attach jce-gremlin-console
```

### Generate Config
Expand Down Expand Up @@ -90,9 +102,9 @@ The environment variables supported by the JanusGraph image are summarized below

The `JANUS_PROPS_TEMPLATE` environment variable is used to define the base JanusGraph
properties file. Values in the template properties file are used unless an alternate value
for a given property is provided in the environment. The common usage will be to specify
a template for the general environment (e.g., `cassandra-es`) and then provide additional
individual configuration to override/extend the template. The available templates depend
for a given property is provided in the environment. The common usage will be to specify
a template for the general environment (e.g., `cassandra-es`) and then provide additional
individual configuration to override/extend the template. The available templates depend
on the JanusGraph version (see [`conf/gremlin-server/janusgraph*.properties`][JG_TEMPLATES]).

| `JANUS_PROPS_TEMPLATE` | Supported Versions |
Expand Down
47 changes: 32 additions & 15 deletions build/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ JANUS_PROPS="${JANUS_CONFIG_DIR}/janusgraph.properties"
GREMLIN_YAML="${JANUS_CONFIG_DIR}/gremlin-server.yaml"

# running as root; step down to run as janusgraph user
if [ "$1" == 'janusgraph' ] && [ "$(id -u)" == "0" ]; then
if [[ "$(id -u)" == "0" ]] && [[ "$1" == 'janusgraph' || "$1" == 'gremlin-console' || "$1" == 'gremlin-console-remote' ]]; then
echo "Running root setup steps for '$1'"
mkdir -p ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}
chown -R janusgraph:janusgraph ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}
usermod -d ${JANUS_HOME} janusgraph
chmod 700 ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}

exec chroot --skip-chdir --userspec janusgraph:janusgraph / "${BASH_SOURCE}" "$@"
fi

# running as non root user
if [ "$1" == 'janusgraph' ]; then
if [[ "$1" == 'janusgraph' || "$1" == 'gremlin-console' || "$1" == 'gremlin-console-remote' ]] ; then
echo "Running non-root setup steps for '$1'"
# setup config directory
mkdir -p ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}
cp conf/gremlin-server/janusgraph-${JANUS_PROPS_TEMPLATE}-server.properties ${JANUS_CONFIG_DIR}/janusgraph.properties
Expand All @@ -36,6 +39,11 @@ if [ "$1" == 'janusgraph' ]; then
chmod 700 ${JANUS_DATA_DIR} ${JANUS_CONFIG_DIR}
chmod -R 600 ${JANUS_CONFIG_DIR}/*

# override hosts for remote connections with Gremlin Console
if ! [ -z "${GREMLIN_REMOTE_HOSTS:-}" ]; then
sed -i "s/hosts\s*:.*/hosts: [$GREMLIN_REMOTE_HOSTS]/" ${JANUS_HOME}/conf/remote.yaml
fi

# apply configuration from environment
while IFS='=' read -r envvar_key envvar_val; do
if [[ "${envvar_key}" =~ janusgraph\. ]] && [[ ! -z ${envvar_val} ]]; then
Expand Down Expand Up @@ -64,22 +72,31 @@ if [ "$1" == 'janusgraph' ]; then
cat "$GREMLIN_YAML"
exit 0
else
# wait for storage
if ! [ -z "${JANUS_STORAGE_TIMEOUT:-}" ]; then
F="$(mktemp --suffix .groovy)"
echo "graph = JanusGraphFactory.open('${JANUS_CONFIG_DIR}/janusgraph.properties')" > $F
timeout "${JANUS_STORAGE_TIMEOUT}s" bash -c \
"until bin/gremlin.sh -e $F > /dev/null 2>&1; do echo \"waiting for storage...\"; sleep 5; done"
rm -f "$F"
if [ "$1" == 'janusgraph' ] ; then
# wait for storage
if ! [ -z "${JANUS_STORAGE_TIMEOUT:-}" ]; then
F="$(mktemp --suffix .groovy)"
echo "graph = JanusGraphFactory.open('${JANUS_CONFIG_DIR}/janusgraph.properties')" > $F
timeout -k 10 "${JANUS_STORAGE_TIMEOUT}s" bash -c \
"until bin/gremlin.sh -e $F > /dev/null 2>&1; do echo \"waiting for storage...\"; sleep 5; done"
rm -f "$F"
fi
echo "Starting janusgraph gremlin server"
exec ${JANUS_HOME}/bin/gremlin-server.sh ${JANUS_CONFIG_DIR}/gremlin-server.yaml
fi

exec ${JANUS_HOME}/bin/gremlin-server.sh ${JANUS_CONFIG_DIR}/gremlin-server.yaml
fi
fi
if [ "$1" == 'gremlin-console-remote' ] ; then
echo "Starting gremlin remote console"
exec ${JANUS_HOME}/bin/gremlin.sh -i scripts/remote-connect.groovy
fi

# override hosts for remote connections with Gremlin Console
if ! [ -z "${GREMLIN_REMOTE_HOSTS:-}" ]; then
sed -i "s/hosts\s*:.*/hosts: [$GREMLIN_REMOTE_HOSTS]/" ${JANUS_HOME}/conf/remote.yaml
if [ "$1" == 'gremlin-console' ] ; then
echo "Starting gremlin console"
C=$(mktemp --suffix .groovy)
echo "graph = JanusGraphFactory.open('${JANUS_CONFIG_DIR}/janusgraph.properties')" > $C
exec ${JANUS_HOME}/bin/gremlin.sh -i $C
fi
fi
fi

exec "$@"
16 changes: 16 additions & 0 deletions docker-compose-cql-es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ services:
- "9200:9200"
networks:
- jce-network
gremlin-console:
image: janusgraph/janusgraph:latest
container_name: jce-gremlin-console
environment:
GREMLIN_REMOTE_HOSTS: janusgraph
JANUS_PROPS_TEMPLATE: cassandra-es
janusgraph.storage.backend: cql
janusgraph.storage.hostname: jce-cassandra
janusgraph.index.search.hostname: jce-elastic
stdin_open: yes
tty: yes
command: gremlin-console
networks:
- jce-network
depends_on:
- janusgraph

networks:
jce-network:
Expand Down
Loading