Deploy Neo4J's APOC plugin with code thanks to CARVEL vendir

adriens - Jul 5 '21 - - Dev Community

🚀Teaser

CARVEL

"provides a set of reliable, single-purpose, composable tools that aid in your application building, configuration, and deployment to Kubernetes."

Let's see how vendir, which is one of these tools can help deploy things easier, even if you don't work with kubernetes.

📑Introduction

Neo4J is a very nice way to play with a Graph Database.

Is is delivered as packages, as a Service and as a Docker image.

Neo4J features can be extended thanks to plugins, one of them is APOC :

GitHub logo neo4j-contrib / neo4j-apoc-procedures

Awesome Procedures On Cypher for Neo4j - codenamed "apoc"                     If you like it, please ★ above ⇧            

Discourse users Discord

Awesome Procedures for Neo4j 4.4.x

Introduction

apoc

Neo4j 3.x introduced the concept of user-defined procedures and functions Those are custom implementations of certain functionality, that can’t be (easily) expressed in Cypher itself. They are implemented in Java and can be easily deployed into your Neo4j instance, and then be called from Cypher directly.

The APOC library consists of many (about 450) procedures and functions to help with many different tasks in areas like data integration, graph algorithms or data conversion.

License

Apache License 2.0

"APOC" Name history

Apoc was the technician and driver on board of the Nebuchadnezzar in the Matrix movie. He was killed by Cypher.

APOC was also the first bundled A Package Of Component for Neo4j in 2009.

APOC also stands for "Awesome Procedures On Cypher"

Installation: With Neo4j Desktop

APOC Full can be installed with Neo4j Desktop, after creating your database, by going to the Manage

Here are some features APOC adds to Neo4J :

All you have to get done do is :

  1. Download the APOC library
  2. Drop the plugin in a specific directory

🎁Distribution flavors

Let's focus on two specific flavors :

  • The GUI mode
  • The docker mode

GUI mode

The GUI mode is very helpful and packages all install operations in a very smooth way, perfect to perform demos, explain each step, but requires a quite important amount of clicks. Also, you get wizard to install APOC library the proper way.

This mode is very well suited for live demos as it provide nice visuals that make it easier for you to explain concepts while playing with them.

🐳Docker mode

This mode makes it possible to run everything from the code. Still, you have to perform some additional an eventually manual tasks :

  1. Download the APOC jar
  2. Put the jar in the right directory and give the proper privileges

👉The aim of this post is to document this to make things even easier with a tool called CARVEL vendir

CARVEL vendir

The aim of vendir is to declaratively state directory's contents.

You can :

"Sync any number of data sources into a consistent structure by writing a YAML definition. Share the definition or generated lockfile and ensure that your whole team is working under the same expectations."

GitHub logo carvel-dev / vendir

Easy way to vendor portions of git repos, github releases, helm charts, docker image contents, etc. declaratively

logo

OpenSSF Best Practices

vendir

vendir allows you to declaratively state what should be in a directory. It can be used for vendoring software.

$ vendir sync # from a directory that contains vendir.yml
Enter fullscreen mode Exit fullscreen mode

Features:

Doing the whole thing from the shell

First, install vendir :

On linux :

brew tap vmware-tanzu/carvel
brew install vendir
Enter fullscreen mode Exit fullscreen mode

On Windows :

choco install vendir
Enter fullscreen mode Exit fullscreen mode

Next, create vendir.yml file with the following contents :

apiVersion: vendir.k14s.io/v1alpha1
kind: Config
directories:
- path: plugins/
  contents:
    - path: .
      githubRelease:
        slug: neo4j-contrib/neo4j-apoc-procedures
        tag: 4.3.0.0
        disableAutoChecksumValidation: true
        assetNames: ["apoc-*-all.jar"]
Enter fullscreen mode Exit fullscreen mode

Let's assume you have the following directory hierarchy :

vendir.yml
|__plugins
Enter fullscreen mode Exit fullscreen mode

🎆Next, let vendir do the job :

vendir sync
Enter fullscreen mode Exit fullscreen mode

Finally, run the docker image and enjoy a fully operational (customize the volumes mapping) Neo4J instance with pre-installed APOC :

docker run \
    --name vendir-loves-neo4j \
    -p7474:7474 -p7687:7687 \
    -d \
    -v $HOME/neo4j/data:/data \
    -v $HOME/neo4j/logs:/logs \
    -v /vagrant/import:/var/lib/neo4j/import \
    -v /vagrant/plugins:/plugins \
    --env NEO4J_AUTH=neo4j/S3CR37 \
    --env NEO4J_dbms_security_procedures_unrestricted=apoc.\\\* \
    neo4j:latest
Enter fullscreen mode Exit fullscreen mode

You're done and the installation process is totally automated and of course self-documented.

Now you can enjoy APOC extension. For an example, check how to import PostgreSQL relational model in Neo4J to run cypher queries and create nice looking Gephi graphs.

Conclusion

Hopefully this post has helped you make install process smoother, smarter, and made you discover CARVEL tools.

GitHub logo carvel-dev / carvel

Carvel provides a set of reliable, single-purpose, composable tools that aid in your application building, configuration, and deployment to Kubernetes. This repo contains information regarding the Carvel open-source community.

logo

OpenSSF Best Practices

Carvel

Carvel provides a set of reliable, single-purpose, composable tools that aid in your application building, configuration, and deployment to Kubernetes.

This is a list of repos associated with the Carvel project.

  • ytt - Template and overlay Kubernetes configuration via YAML structures, not text documents
  • kapp - Install, upgrade, and delete multiple Kubernetes resources as one "application"
  • kbld - Build or reference container images in Kubernetes configuration in an immutable way
  • imgpkg - Bundle and relocate application configuration (with images) via Docker registries
  • kapp-controller - Capture application deployment workflow in App CRD. Reliable GitOps experience powered by kapp.
  • vendir - Declaratively state what files should be in a directory.
  • secretgen-controller - Provides CRDs to specify what secrets need to be on a cluster (generated or not).

Experimental:

Installation:

Plugins:

Examples:

See what's planned in our backlog.


Join

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .