Skip to content

Commit

Permalink
added support for installing plugins such as apocat runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Jefferson committed Jun 20, 2019
1 parent 645130a commit 9c30aee
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<user/organisation>/<repository-name>` 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.
2 changes: 1 addition & 1 deletion src/3.5/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
20 changes: 20 additions & 0 deletions src/3.5/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}

Expand Down
37 changes: 37 additions & 0 deletions test/test-apoc-download
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9c30aee

Please sign in to comment.