This repository contains the back end for the Zerobase smart tracing platform. Refer to the smart-tracing repo for the front end. We are using Kotlin and Neo4j with cloud storage on Heroku. We are using Dropwizard for the REST framework. Kotlin requires Java and Maven.
Any commands shown in this read-me are written in bash. If you are on Windows or use an alternate shell, like fish, please adjust the commands accordingly.
There are other README files throughout the project. They are located in the source folders that most closely align with the readme contents.
The backend is written in Kotlin. While you can work on it in any editor, such as vim or VS Code, it is significantly easier to use an IDE. We recommend IntelliJ. If you are using Intellij, the Kotlin plugin must be at least 1.3.70.
This project targets the current LTS version of Java: 11. You are welcome to use any of the JDK implementations locally, but deployments
will be done using an AdoptOpenJDK build. If you want to use Oracle's official JDK, it can be dowloaded here.
We recommend, however, that you install the JDK using a package manager, such as brew
on macOS, to easily stay up to date.
Maven is a dependency management and build tool that is commonly used in the Java world. It is available for installation via package
managers, such as brew
on macOS, for easy updating (recommended way) but can also be installed manually.
Docker is used to run external services locally for front-end development or tests instead of requiring access to a cloud environment. Some of the resources can be run without docker, but some don't really have local install options. Install docker manually by following this guide or via a package manager.
We have a docker compose file that will spin up all the pieces necessary and expose the API on your local machine. There are several environment variables that can be used to configure it:
DB_PORT
: Used if you want to connect to the gremlin server manually and play with the graph.APP_VERSION
: By default, it will use latest. If you need to run a specific version, or one that isn't in DockerHub yet, set this to the version tag you want.To run the backend when not intending to work on it (useful if you are working only on the front end or testing it) you can pull it in from dockerhub with
docker-compose -f docker-compose-full-stack.yml upp app
Alternately, run just dependencies from docker-compose and build/develop on your machine
$ mvn clean install
$ docker-compose -f ./docker-compose-dependencies.yml up database aws
$ docker pull tinkerpop/gremlin-server
$ docker run -d \
-p 8182:8182 \
-v $(pwd)/src/test/resources/tinkergraph-overrides.properties:/opt/gremlin-server/conf/tinkergraph-empty.properties \
--name=zerobase-db \
tinkerpop/gremlin-server:latest
By default, there are no credentials for the local install
Follow their startup documentation: https://github.com/localstack/localstack.
$ docker run -d --name=zerobase-api \
-e WRITE_ENDPOINT=<gremlin-api host> \
-e DB_PORT=<gremlin mapped port> \
-e AWS_SES_ENDPOINT=<localstack ses http url (including port)>
zerobaseio/smart-tracing-api:<version>
If you're unable to use Docker to run Gremlin, there is an alternative available. The desktop version can be downloaded from here. The configuration instructions are found here. The default configuration should suffice.
Follow the documentation for a non-Docker SES fake. Here's one: https://github.com/csi-lk/aws-ses-local
After cloning the project there are multiple ways to deploy it locally: from dockerhub, using an IDE or via the command line. There is also a docker-compose for setting up all dependencies. By default, the app listens on
port 9000. You can override that with an environment variable of PORT
if you need to. The local-config.yml
defaults to localhost
and 8182
for the database. Both can be overriden with environment variables, using WRITE_ENDPOINT
and DB_PORT
respectively.
Running in an IDE
The following directions use Intellij as the IDE, but the steps should be similar if you are using a different IDE.
Main.kt
Main.kt
, click on the run button next to main and select Create Main.kt
to create a run configuration.local-config.yml
instead of
config.yml
. The configuration will target running locally against Gremlin, while the normal config will target AWS Neptune.server <the config file you want to use>
. Options for config files are:
src/main/resources/config.yml
src/main/resources/local-config.yml
local-config.yml
expects the database to be running at localhost:8182
. If you need to override the port,
set an environment variable of DB_PORT
to the port your gremlin server is running on.OK
and run the configuration you just made.Running from the command line.
From the project's root directory, build the project.
$ mvn clean install
Alternately, to do a build with fewer checks
mvn package -Dbasepom.check.skip-all
Set the environment variables (if needed), either as an export or inline, and run the jar.
You should not have to set environment variables at all if running the default configuration for dependencies via docker-compose-dependencies
$ export DB_PORT=12345 $ java -jar target/smart-tracing-api.jar server target/classes/local-config.yml
* Inline
```sh
$ DB_PORT=12345 java -jar target/smart-tracing-api.jar server target/classes/local-config.yml
http://localhost:8081
in your browser. You
shoudl see a simple page that exposes metrics and healthcheck results. You can also curl http://localhost:8081/healthchecks
if
you prefer the command line.http://localhost:9000