From 9c30aeee54b9c5fc54ae3b164155b4d01f181823 Mon Sep 17 00:00:00 2001 From: Andrew Jefferson Date: Thu, 20 Jun 2019 21:35:23 +0100 Subject: [PATCH] added support for installing plugins such as apocat runtime --- README.md | 6 ++++++ src/3.5/Dockerfile | 2 +- src/3.5/docker-entrypoint.sh | 20 +++++++++++++++++++ test/test-apoc-download | 37 ++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100755 test/test-apoc-download diff --git a/README.md b/README.md index 2c8d37fc..eab11803 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,12 @@ docker run \ neo4j:3.0 ``` +# Plugins + +## Installation on container startup + +Plugins can be installed from github during container startup. Set the `NEO4JPLUGINS` environment variable to a json list of plugins to install in the form `/` e.g. `neo4j-contrib/neo4j-apoc-procedures`. The plugin repository must have a compatible `versions.json` file on its master branch. + # Getting support and contributing Please create issues and pull requests in the Github repository. diff --git a/src/3.5/Dockerfile b/src/3.5/Dockerfile index 58c9b773..cbbd1ac9 100644 --- a/src/3.5/Dockerfile +++ b/src/3.5/Dockerfile @@ -13,7 +13,7 @@ RUN addgroup --system neo4j && adduser --system --no-create-home --home "${NEO4J COPY ./local-package/* /tmp/ RUN apt update \ - && apt install -y curl gosu \ + && apt install -y curl gosu jq \ && curl -L --fail --silent --show-error "https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini" > /sbin/tini \ && echo "${TINI_SHA256} /sbin/tini" | sha256sum -c --strict --quiet \ && chmod +x /sbin/tini \ diff --git a/src/3.5/docker-entrypoint.sh b/src/3.5/docker-entrypoint.sh index d9b88d5d..2da72dcf 100755 --- a/src/3.5/docker-entrypoint.sh +++ b/src/3.5/docker-entrypoint.sh @@ -119,6 +119,20 @@ function check_mounted_folder_with_chown fi } +function load_plugin_from_github +{ +# Load a plugin at runtime. The provided github repository must have a versions.json on the master branch with the +# correct format. + local _repository="${1}" #e.g. neo4j-contrib/neo4j-apoc-procedures + local _destination_jar="${_repository/\//_}.jar" + local _neo4j_version="$(neo4j --version | cut -d' ' -f2)" + local _plugins_dir="${NEO4J_dbms_directories_plugins:-./plugins}" + + # Now we call out to github to find the url for the plugin + local _plugin_jar_url="$(curl -L "https://github.com/${_repository}/raw/master/versions.json" | jq --raw-output ".[] | select(.neo4j==\"${_neo4j_version}\") | .jar")" + curl -o "${_plugins_dir}/${_destination_jar}" -L "${_plugin_jar_url}" +} + # If we're running as root, then run as the neo4j user. Otherwise # docker is running with --user and we simply use that user. Note # that su-exec, despite its name, does not replicate the functionality @@ -339,6 +353,12 @@ for i in $( set | grep ^NEO4J_ | awk -F'=' '{print $1}' | sort -rn ); do fi done +if [[ ! -z "${NEO4JPLUGINS:-}" ]]; then + # NEO4JPLUGINS should be a json array of repositories like '["neo4j-contrib/neo4j-graph-algorithms", "neo4j-contrib/neo4j-apoc-procedures"]' + for repo in $(echo "${NEO4JPLUGINS}" | jq --raw-output '.[]'); do + load_plugin_from_github "${repo}" + done +fi [ -f "${EXTENSION_SCRIPT:-}" ] && . ${EXTENSION_SCRIPT} diff --git a/test/test-apoc-download b/test/test-apoc-download new file mode 100755 index 00000000..5642b9ee --- /dev/null +++ b/test/test-apoc-download @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +set -o errexit -o nounset +[[ -n "${TRACE:-}" ]] && set -o xtrace + +. "$(dirname "$0")/helpers.sh" + +readonly image="$1" +readonly series="$2" +readonly cname="neo4j-$(uuidgen)" + +readonly result="$(docker run --rm --name "${cname}" --env NEO4JPLUGINS='["neo4j-contrib/neo4j-apoc-procedures"]' "${image}" ls plugins)" + +if [[ "${result}" == *"neo4j-contrib_neo4j-apoc-procedures.jar"* ]]; then + echo "apoc jar in plugins." +else + echo >&2 "missing apoc jar 1" + exit 1 +fi + +readonly cname2="neo4j-$(uuidgen)" +readonly plugins="$(mktemp -d)" +readonly result2="$(docker run --rm --name "${cname2}" --env NEO4JPLUGINS='["neo4j-contrib/neo4j-apoc-procedures"]' -v "${plugins}:/plugins" "${image}" ls /plugins)" + +echo "${result2}" +if [[ "${result2}" == *"neo4j-contrib_neo4j-apoc-procedures.jar"* ]]; then + echo "apoc jar in plugins." +else + echo >&2 "missing apoc jar 2" + exit 1 +fi + +if [[ ! -f "${plugins}/neo4j-contrib_neo4j-apoc-procedures.jar" ]]; then + echo >&2 "missing apoc jar 3" + exit 1 +fi + +# TODO: test calling an apoc procedure