From 56936c403831b9b624711ca60c6a1a94d6121b35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Thu, 14 Feb 2019 16:05:30 +0100 Subject: [PATCH] Setup a routine how to create indices initially In order to create the indices programmatically we need to change the default password for security concerns. To create the user we need to start the neo4j database. So I decided to provide a bash script that let us do it once the container are started. In production we must change the NEO4J_PASSWORD. --- README.md | 2 +- docker-compose.override.yml | 7 +++++++ docker-compose.prod.yml | 9 +++++++++ docker-compose.yml | 7 ------- neo4j/Dockerfile | 1 + neo4j/migrate.sh | 4 ++++ src/bootstrap/neo4j.js | 2 +- src/graphql-schema.js | 2 +- src/schema.graphql | 2 +- 9 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 docker-compose.prod.yml create mode 100755 neo4j/migrate.sh diff --git a/README.md b/README.md index 1b12562d2..b1363a293 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ _.env_ ```yaml NEO4J_URI=bolt://localhost:7687 -NEO4J_USER=neo4j +NEO4J_USERNAME=neo4j NEO4J_PASSWORD=letmein ``` diff --git a/docker-compose.override.yml b/docker-compose.override.yml index ef7d52c7e..b972c31f6 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -11,6 +11,13 @@ services: - /nitro-backend/node_modules command: yarn run dev neo4j: + environment: + - NEO4J_AUTH=none ports: - 7687:7687 - 7474:7474 + volumes: + - neo4j-data:/data + +volumes: + neo4j-data: diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 000000000..c4f5dc4f5 --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,9 @@ +version: "3.7" + +services: + neo4j: + environment: + - NEO4J_PASSWORD=letmein + backend: + environment: + - NEO4J_PASSWORD=letmein diff --git a/docker-compose.yml b/docker-compose.yml index 6905bb893..1e8c9158c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,14 +27,7 @@ services: context: neo4j networks: - hc-network - volumes: - - neo4j-data:/data - environment: - - NEO4J_AUTH=none networks: hc-network: name: hc-network - -volumes: - neo4j-data: diff --git a/neo4j/Dockerfile b/neo4j/Dockerfile index cb7fd228f..f6e71811b 100644 --- a/neo4j/Dockerfile +++ b/neo4j/Dockerfile @@ -1,2 +1,3 @@ FROM neo4j:3.5.0 RUN wget https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/3.5.0.1/apoc-3.5.0.1-all.jar -P plugins/ +COPY migrate.sh /usr/local/bin/migrate diff --git a/neo4j/migrate.sh b/neo4j/migrate.sh new file mode 100755 index 000000000..30a58c306 --- /dev/null +++ b/neo4j/migrate.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e +echo "CALL dbms.security.changePassword('${NEO4J_PASSWORD}');" | cypher-shell --username neo4j --password neo4j +echo 'CALL db.index.fulltext.createNodeIndex("full_text_search",["Post"],["title", "content"]);' | cypher-shell --username neo4j --password $NEO4J_PASSWORD diff --git a/src/bootstrap/neo4j.js b/src/bootstrap/neo4j.js index 766c12065..929e62f23 100644 --- a/src/bootstrap/neo4j.js +++ b/src/bootstrap/neo4j.js @@ -9,7 +9,7 @@ export default function () { driver = neo4j.driver( process.env.NEO4J_URI || 'bolt://localhost:7687', neo4j.auth.basic( - process.env.NEO4J_USER || 'neo4j', + process.env.NEO4J_USERNAME || 'neo4j', process.env.NEO4J_PASSWORD || 'neo4j' ) ) diff --git a/src/graphql-schema.js b/src/graphql-schema.js index 8b5f369e0..c525d67d7 100644 --- a/src/graphql-schema.js +++ b/src/graphql-schema.js @@ -34,7 +34,7 @@ export const query = (cypher, session) => { }) }) } -const queryOne = (cypher, session) => { +export const queryOne = (cypher, session) => { return new Promise((resolve, reject) => { query(cypher, session) .then(res => { diff --git a/src/schema.graphql b/src/schema.graphql index 95e7b3d48..472b345d7 100644 --- a/src/schema.graphql +++ b/src/schema.graphql @@ -4,7 +4,7 @@ type Query { findPosts(filter: String!, limit: Int = 10): [Post]! @cypher( statement: """ CALL db.index.fulltext.queryNodes( - 'postTitleAndContent', $filter+'~') + 'full_text_search', $filter+'~') YIELD node AS node RETURN node ORDER BY node.createdAt DESC