Skip to content

Commit

Permalink
Add docker compose
Browse files Browse the repository at this point in the history
Signed-off-by: Siddharth Golecha <[email protected]>
Signed-off-by: Oleksandr Porunov <[email protected]>
  • Loading branch information
Siddharth Golecha authored and porunov committed Feb 16, 2025
1 parent 5df3cb1 commit b3a84fe
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 51 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GREMLIN_HOST=janusgraph
GREMLIN_PORT=8182
62 changes: 11 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ This project is to visualize the graph network corresponding to a gremlin query.
### Quick start guide

Below is a quick start guide to start JanusGraph, load the testing graph, and start visualization to show the graph.
Notice, this guide uses Docker image, but it's possible to start JanusGraph and visualization tool without (see `Setting Up JanusGraph Visualizer` section below).

1. Start JanusGraph on your host machine: `docker run --name janusgraph-default -p 8182:8182 --network=host janusgraph/janusgraph:latest`
2. Open second terminal and start gremlin console: `docker run --rm --network=host -e GREMLIN_REMOTE_HOSTS=localhost -it janusgraph/janusgraph:latest ./bin/gremlin.sh`
3. Connect to JanusGraph Server from your running Gremlin Console: `:remote connect tinkerpop.server conf/remote.yaml`
4. Instruct Gremlin Console to send all requests to the connected remote server: `:remote console`
5. Load JanusGraph testing graph via Gremlin Console: `GraphOfTheGodsFactory.load(graph)`
6. Exit Gremlin Console because it's no longer needed: `:exit`
7. Start JanusGraph-Visualizer: `docker run --rm -d -p 3000:3000 -p 3001:3001 --name=janusgraph-visualizer --network=host janusgraph/janusgraph-visualizer:latest`
8. Open your browser and enter address `http://localhost:3001/`
9. Click `EXECUTE` button. You should see the same graph as the one specified on the image above.
Notice, this guide uses Docker compose, but it's possible to start JanusGraph and visualization tool without (see `Setting Up JanusGraph Visualizer` section below).

1. Start the docker services using `docker compose up` for the starting the Janusgraph service, loading the test data and starting the visualization service.
2. (Optional) If you want to specially build the visualizer from the source code, use `docker compose up --build`.
3. Open your browser and enter address `http://localhost:3001/`
4. Click `EXECUTE` button. You should see the same graph as the one specified on the image above.
5. The Docker containers can be stopped by calling `docker compose down`.

### Setting Up JanusGraph Visualizer
To setup JanusGraph visualizer, you need to have `node.js` and `npm` installed in your system.
Expand All @@ -40,55 +36,19 @@ http://localhost:3000

Note - Frontend starts on port 3000 and simple Node.js server also starts on port 3001. If you need to change the ports, configure in `package.json`, `proxy-server.js`, `src/constants`

#### Setting up with Docker

You can build a Docker image of the JanusGraph visualizer with the included `Dockerfile`.
This will use the current version of the `main` branch of the source GitHub repository.
The Docker image can be built by calling the `docker build -f full.Dockerfile` command, for example:

```sh
docker build --tag=janusgraph-visualizer:latest -f full.Dockerfile .
```

If you had already built node project on your host then you can create a Docker image faster by using `Dockerfile` instead of `full.Dockerfile`:

```sh
docker build --tag=janusgraph-visualizer:latest .
```

The image can also be downloaded from Docker hub: [`janusgraph/janusgraph-visualizer:latest`](https://hub.docker.com/r/janusgraph/janusgraph-visualizer).

```sh
docker pull janusgraph/janusgraph-visualizer:latest
```

The Docker image can then be run by calling `docker run` and exposing the necessary ports for communication. See [Docker's documentation](https://docs.docker.com/engine/reference/commandline/run/) for more options on how to run the image.

```sh
# if you built the image yourself
docker run --rm -d -p 3000:3000 -p 3001:3001 --name=janusgraph-visualizer --network=host janusgraph-visualizer:latest
# if you downloaded from Docker Hub
docker run --rm -d -p 3000:3000 -p 3001:3001 --name=janusgraph-visualizer --network=host janusgraph/janusgraph-visualizer:latest
```
Note that `--network=host` is not needed if you don't run your gremlin server in the host machine.

* Open the browser and navigate to
```sh
http://localhost:3001
```

The Docker container can be stopped by calling `docker stop janusgraph-visualizer`.
See [docs/docker-build.md](docs/docker-build.md) to learn how to build the project directly using Docker images.

### Supported Environment Variables

* `GREMLIN_HOST` - sets gremlin server hostname for connection. Default is `localhost`.
* `GREMLIN_HOST` - sets gremlin server hostname for connection. Default is `janusgraph` if started via `docker compose up` (`docker-compose.yml` receives this value from `.env` file) or `localhost` if started directly via `docker run`.
* `GREMLIN_PORT` - sets gremlin server port for connection. Default is `8182`.
* `GREMLIN_TRAVERSAL_SOURCE` - sets default graph traversal source name to be used for queries. Default is `g`.
* `GREMLIN_DEFAULT_QUERY` - sets default query to show in visualizer. Default is `g.V()`.

You can change these values in the .env file.

### Usage
* Start JanusGraph-Visualizer as mentioned above
* Start or tunnel a gremlin server
* Specify the host and port of the gremlin server
* Write a gremlin query to retrieve a set of nodes (eg. `g.V()`)

Expand Down
61 changes: 61 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
services:
janusgraph:
image: docker.io/janusgraph/janusgraph:latest
container_name: janusgraph
networks:
- janus_bridge
ports:
- "8182:8182"
healthcheck:
test: ["CMD", "./bin/gremlin.sh", "-e", "scripts/remote-connect.groovy"]
interval: 5s
timeout: 10s
retries: 20
start_period: 5s
volumes:
- "janusgraph-data:/var/lib/janusgraph"

gremlin-console:
image: docker.io/janusgraph/janusgraph:latest
container_name: gremlin-console
networks:
- janus_bridge
depends_on:
janusgraph:
condition: service_healthy
env_file:
- .env
entrypoint: >
bash -c "
./bin/gremlin.sh -e /scripts/load_gods_script.groovy
"
volumes:
- ./scripts:/scripts

janusgraph-visualizer:
build:
context: .
dockerfile: full.Dockerfile
image: docker.io/janusgraph/janusgraph-visualizer
container_name: janusgraph-visualizer
depends_on:
gremlin-console:
condition: service_completed_successfully
janusgraph:
condition: service_healthy
ports:
- "3001:3001"
- "3000:3000"
networks:
- janus_bridge
env_file:
- .env
environment:
NODE_ENV: production

networks:
janus_bridge:
driver: bridge
volumes:
janusgraph-data:

39 changes: 39 additions & 0 deletions docs/docker-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#### Setting up with Docker (without docker-compose usage)

You can build a Docker image of the JanusGraph visualizer with the included `Dockerfile`.
This will use the current version of the `main` branch of the source GitHub repository.
The Docker image can be built by calling the `docker build -f full.Dockerfile` command, for example:

```sh
docker build --tag=janusgraph-visualizer:latest -f full.Dockerfile .
```

If you had already built node project on your host then you can create a Docker image faster by using `Dockerfile` instead of `full.Dockerfile`:

```sh
docker build --tag=janusgraph-visualizer:latest .
```

The image can also be downloaded from Docker hub: [`janusgraph/janusgraph-visualizer:latest`](https://hub.docker.com/r/janusgraph/janusgraph-visualizer).

```sh
docker pull janusgraph/janusgraph-visualizer:latest
```

The Docker image can then be run by calling `docker run` and exposing the necessary ports for communication. See [Docker's documentation](https://docs.docker.com/engine/reference/commandline/run/) for more options on how to run the image.

```sh
# if you built the image yourself
docker run --rm -d -p 3000:3000 -p 3001:3001 --name=janusgraph-visualizer --network=host janusgraph-visualizer:latest
# if you downloaded from Docker Hub
docker run --rm -d -p 3000:3000 -p 3001:3001 --name=janusgraph-visualizer --network=host janusgraph/janusgraph-visualizer:latest
```
Note that `--network=host` is not needed if you don't run your gremlin server in the host machine.

* Open the browser and navigate to
```sh
http://localhost:3001
```

The Docker container can be stopped by calling `docker stop janusgraph-visualizer`.

38 changes: 38 additions & 0 deletions scripts/load_gods_script.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
def runScript() {
import org.apache.tinkerpop.gremlin.driver.Client
import org.apache.tinkerpop.gremlin.driver.Cluster

def environmentVariables = System.getenv();
def gremlinHost = environmentVariables['GREMLIN_HOST'] ?: 'localhost'
def gremlinPort = environmentVariables['GREMLIN_PORT'] ?: '8182'

println "Connecting to Gremlin Server at $gremlinHost:$gremlinPort"

Cluster cluster = Cluster.build(gremlinHost).port(Integer.parseInt(gremlinPort)).create()
Client client = cluster.connect()

// Fetch vertex count - returns List<Result>
def results = client.submit('g.V().count()').all().get()
if (results.isEmpty()) {
throw new RuntimeException("Failed to retrieve vertex count.")
}

// Extract the value from the Result object
def vertexCount = results[0].getLong() // getLong() converts the underlying number to a Long
println "Vertex count: $vertexCount"

// Load the graph only if it's empty
if (vertexCount == 0) {
println "Loading the graph as it's empty..."
client.submit('GraphOfTheGodsFactory.load(graph)').all().get()
println "Data loaded successfully!"
} else {
println "Graph already contains data. Skipping load."
}

// Close the connection
client.close()
cluster.close()
}

runScript()

0 comments on commit b3a84fe

Please sign in to comment.