Skip to content

Deployment

Alexandre P Francisco edited this page Jun 20, 2023 · 7 revisions

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow packaging up an application with all the parts it needs, such as libraries and other dependencies, and deploy it as one package. By doing so, the application will run on any other Linux machine containing docker, regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.

To use Docker to deploy our solution, the following steps must be performed:

  1. Build the solution jars

    The algorithms project contains the user defined procedures that shall be used by the Neo4j database. To build the respective jar of this project, it is needed to execute the command mvn package -Dmaven.test.skip=true on the algorithms project folder. This will produce a jar at /target directory.

    The phylodb project contains the api. To build the respective jar of this project, it is needed to execute the command gradlew bootJar on the phylodb project folder. This will produce a jar at build/libs directory. (For this example to work, the key spring.data.neo4j.uri, in application.properties, must have the value bolt://db:7687)

  2. Download apoc jar

    Our solution uses the Neo4j apoc library, hence we need to download its jar.

  3. Create the folders to use in docker bind mount

    The solution will hold data such as, database data, logs, plugins and configuration, as well as the application logs. To maintain this data we must create the respective folders, that will be bind mounted by docker later. The creation of these folders must accomplish the following structure:

    \$HOME\instance1
       \db
          \data
          \logs
          \plugins
       \app
          \logs
    
  4. Copy algorithms and apoc jars to bind mount plugin folder

    The algorithms and apoc jars must be copied to the previously created plugins folder. Then we will have our folder structure as the following:

    \$HOME\instance1
       \db
          \data
          \logs
          \plugins
             algorithms-1.0.jar
             apoc-x.x.x.jar
       \app
          \logs
    
  5. Build phylodb docker image

    We must create our docker application image, to run the respective application container. To do so, we need to navigate to the phylodb project folder, open terminal and run the command docker build -t phylodb .. This command will search for a dockerfile in the current directory, build the respective image and tag it as 'phylodb:latest'

  6. Run docker-compose file

    Now we run our containers with the database and application. To do so, we need to navigate to the first solution folder and run the command USER=$(id -u):$(id -g) DB_PATH=$HOME/instance1/db APP_PATH=$HOME/instance1/app docker-compose up -d. This will start two containers, one with the phylodb application and the other with the Neo4j database. The USER=$(id -u):$(id -g) means that the container user will have the same permissions as the current user, the DB_PATH=$HOME/instance1/db and APP_PATH=$HOME/instance1/app are the directories that we created before and will now be used to bind mount. We also need to make sure that the database connection at application properties of phylodb project contains the name of the database service used in docker-compose file. At this moment we have our solution up and running.

  7. Initiate database

    After the database is started we need to initiate it with an admin user and with the schema. These scripts are in the solution folder in '/scripts/init'. Now we need to run the command docker exec -it {CONTAINER ID} bash , where the 'CONTAINER ID' is the id of the database container, and start the Neo4j cypher shell by running cypher-shell -u neo4j -p password. Once this is executed, we can now run the initiation scripts to the database.

There is a video which demonstrates how to deploy.