Skip to content

Commit b3a84fe

Browse files
Siddharth Golechaporunov
authored andcommitted
Add docker compose
Signed-off-by: Siddharth Golecha <[email protected]> Signed-off-by: Oleksandr Porunov <[email protected]>
1 parent 5df3cb1 commit b3a84fe

File tree

5 files changed

+151
-51
lines changed

5 files changed

+151
-51
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GREMLIN_HOST=janusgraph
2+
GREMLIN_PORT=8182

README.md

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@ This project is to visualize the graph network corresponding to a gremlin query.
66
### Quick start guide
77

88
Below is a quick start guide to start JanusGraph, load the testing graph, and start visualization to show the graph.
9-
Notice, this guide uses Docker image, but it's possible to start JanusGraph and visualization tool without (see `Setting Up JanusGraph Visualizer` section below).
10-
11-
1. Start JanusGraph on your host machine: `docker run --name janusgraph-default -p 8182:8182 --network=host janusgraph/janusgraph:latest`
12-
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`
13-
3. Connect to JanusGraph Server from your running Gremlin Console: `:remote connect tinkerpop.server conf/remote.yaml`
14-
4. Instruct Gremlin Console to send all requests to the connected remote server: `:remote console`
15-
5. Load JanusGraph testing graph via Gremlin Console: `GraphOfTheGodsFactory.load(graph)`
16-
6. Exit Gremlin Console because it's no longer needed: `:exit`
17-
7. Start JanusGraph-Visualizer: `docker run --rm -d -p 3000:3000 -p 3001:3001 --name=janusgraph-visualizer --network=host janusgraph/janusgraph-visualizer:latest`
18-
8. Open your browser and enter address `http://localhost:3001/`
19-
9. Click `EXECUTE` button. You should see the same graph as the one specified on the image above.
9+
Notice, this guide uses Docker compose, but it's possible to start JanusGraph and visualization tool without (see `Setting Up JanusGraph Visualizer` section below).
10+
11+
1. Start the docker services using `docker compose up` for the starting the Janusgraph service, loading the test data and starting the visualization service.
12+
2. (Optional) If you want to specially build the visualizer from the source code, use `docker compose up --build`.
13+
3. Open your browser and enter address `http://localhost:3001/`
14+
4. Click `EXECUTE` button. You should see the same graph as the one specified on the image above.
15+
5. The Docker containers can be stopped by calling `docker compose down`.
2016

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

4137
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`
4238

43-
#### Setting up with Docker
44-
45-
You can build a Docker image of the JanusGraph visualizer with the included `Dockerfile`.
46-
This will use the current version of the `main` branch of the source GitHub repository.
47-
The Docker image can be built by calling the `docker build -f full.Dockerfile` command, for example:
48-
49-
```sh
50-
docker build --tag=janusgraph-visualizer:latest -f full.Dockerfile .
51-
```
52-
53-
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`:
54-
55-
```sh
56-
docker build --tag=janusgraph-visualizer:latest .
57-
```
58-
59-
The image can also be downloaded from Docker hub: [`janusgraph/janusgraph-visualizer:latest`](https://hub.docker.com/r/janusgraph/janusgraph-visualizer).
60-
61-
```sh
62-
docker pull janusgraph/janusgraph-visualizer:latest
63-
```
64-
65-
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.
66-
67-
```sh
68-
# if you built the image yourself
69-
docker run --rm -d -p 3000:3000 -p 3001:3001 --name=janusgraph-visualizer --network=host janusgraph-visualizer:latest
70-
# if you downloaded from Docker Hub
71-
docker run --rm -d -p 3000:3000 -p 3001:3001 --name=janusgraph-visualizer --network=host janusgraph/janusgraph-visualizer:latest
72-
```
73-
Note that `--network=host` is not needed if you don't run your gremlin server in the host machine.
74-
75-
* Open the browser and navigate to
76-
```sh
77-
http://localhost:3001
78-
```
79-
80-
The Docker container can be stopped by calling `docker stop janusgraph-visualizer`.
39+
See [docs/docker-build.md](docs/docker-build.md) to learn how to build the project directly using Docker images.
8140

8241
### Supported Environment Variables
8342

84-
* `GREMLIN_HOST` - sets gremlin server hostname for connection. Default is `localhost`.
43+
* `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`.
8544
* `GREMLIN_PORT` - sets gremlin server port for connection. Default is `8182`.
8645
* `GREMLIN_TRAVERSAL_SOURCE` - sets default graph traversal source name to be used for queries. Default is `g`.
8746
* `GREMLIN_DEFAULT_QUERY` - sets default query to show in visualizer. Default is `g.V()`.
8847

48+
You can change these values in the .env file.
49+
8950
### Usage
9051
* Start JanusGraph-Visualizer as mentioned above
91-
* Start or tunnel a gremlin server
9252
* Specify the host and port of the gremlin server
9353
* Write a gremlin query to retrieve a set of nodes (eg. `g.V()`)
9454

docker-compose.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
services:
2+
janusgraph:
3+
image: docker.io/janusgraph/janusgraph:latest
4+
container_name: janusgraph
5+
networks:
6+
- janus_bridge
7+
ports:
8+
- "8182:8182"
9+
healthcheck:
10+
test: ["CMD", "./bin/gremlin.sh", "-e", "scripts/remote-connect.groovy"]
11+
interval: 5s
12+
timeout: 10s
13+
retries: 20
14+
start_period: 5s
15+
volumes:
16+
- "janusgraph-data:/var/lib/janusgraph"
17+
18+
gremlin-console:
19+
image: docker.io/janusgraph/janusgraph:latest
20+
container_name: gremlin-console
21+
networks:
22+
- janus_bridge
23+
depends_on:
24+
janusgraph:
25+
condition: service_healthy
26+
env_file:
27+
- .env
28+
entrypoint: >
29+
bash -c "
30+
./bin/gremlin.sh -e /scripts/load_gods_script.groovy
31+
"
32+
volumes:
33+
- ./scripts:/scripts
34+
35+
janusgraph-visualizer:
36+
build:
37+
context: .
38+
dockerfile: full.Dockerfile
39+
image: docker.io/janusgraph/janusgraph-visualizer
40+
container_name: janusgraph-visualizer
41+
depends_on:
42+
gremlin-console:
43+
condition: service_completed_successfully
44+
janusgraph:
45+
condition: service_healthy
46+
ports:
47+
- "3001:3001"
48+
- "3000:3000"
49+
networks:
50+
- janus_bridge
51+
env_file:
52+
- .env
53+
environment:
54+
NODE_ENV: production
55+
56+
networks:
57+
janus_bridge:
58+
driver: bridge
59+
volumes:
60+
janusgraph-data:
61+

docs/docker-build.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#### Setting up with Docker (without docker-compose usage)
2+
3+
You can build a Docker image of the JanusGraph visualizer with the included `Dockerfile`.
4+
This will use the current version of the `main` branch of the source GitHub repository.
5+
The Docker image can be built by calling the `docker build -f full.Dockerfile` command, for example:
6+
7+
```sh
8+
docker build --tag=janusgraph-visualizer:latest -f full.Dockerfile .
9+
```
10+
11+
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`:
12+
13+
```sh
14+
docker build --tag=janusgraph-visualizer:latest .
15+
```
16+
17+
The image can also be downloaded from Docker hub: [`janusgraph/janusgraph-visualizer:latest`](https://hub.docker.com/r/janusgraph/janusgraph-visualizer).
18+
19+
```sh
20+
docker pull janusgraph/janusgraph-visualizer:latest
21+
```
22+
23+
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.
24+
25+
```sh
26+
# if you built the image yourself
27+
docker run --rm -d -p 3000:3000 -p 3001:3001 --name=janusgraph-visualizer --network=host janusgraph-visualizer:latest
28+
# if you downloaded from Docker Hub
29+
docker run --rm -d -p 3000:3000 -p 3001:3001 --name=janusgraph-visualizer --network=host janusgraph/janusgraph-visualizer:latest
30+
```
31+
Note that `--network=host` is not needed if you don't run your gremlin server in the host machine.
32+
33+
* Open the browser and navigate to
34+
```sh
35+
http://localhost:3001
36+
```
37+
38+
The Docker container can be stopped by calling `docker stop janusgraph-visualizer`.
39+

scripts/load_gods_script.groovy

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
def runScript() {
2+
import org.apache.tinkerpop.gremlin.driver.Client
3+
import org.apache.tinkerpop.gremlin.driver.Cluster
4+
5+
def environmentVariables = System.getenv();
6+
def gremlinHost = environmentVariables['GREMLIN_HOST'] ?: 'localhost'
7+
def gremlinPort = environmentVariables['GREMLIN_PORT'] ?: '8182'
8+
9+
println "Connecting to Gremlin Server at $gremlinHost:$gremlinPort"
10+
11+
Cluster cluster = Cluster.build(gremlinHost).port(Integer.parseInt(gremlinPort)).create()
12+
Client client = cluster.connect()
13+
14+
// Fetch vertex count - returns List<Result>
15+
def results = client.submit('g.V().count()').all().get()
16+
if (results.isEmpty()) {
17+
throw new RuntimeException("Failed to retrieve vertex count.")
18+
}
19+
20+
// Extract the value from the Result object
21+
def vertexCount = results[0].getLong() // getLong() converts the underlying number to a Long
22+
println "Vertex count: $vertexCount"
23+
24+
// Load the graph only if it's empty
25+
if (vertexCount == 0) {
26+
println "Loading the graph as it's empty..."
27+
client.submit('GraphOfTheGodsFactory.load(graph)').all().get()
28+
println "Data loaded successfully!"
29+
} else {
30+
println "Graph already contains data. Skipping load."
31+
}
32+
33+
// Close the connection
34+
client.close()
35+
cluster.close()
36+
}
37+
38+
runScript()

0 commit comments

Comments
 (0)