Skip to content

Commit 4b654eb

Browse files
committed
Document how to setup a local environment
1 parent 272f680 commit 4b654eb

File tree

13 files changed

+176
-38
lines changed

13 files changed

+176
-38
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ yarn-error.log*
2525
*.swp
2626
.idea*
2727

28-
ui-react/package
28+
ui-react/package
29+
30+
# local db
31+
neo4j/config/
32+
neo4j/data/

README.md

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,87 @@
1-
# Graphgist Portal - v3
1+
# GraphGist Portal v3
22

3-
This project was started with [GRANDstack](https://grandstack.io) (GraphQL, React, Apollo, Neo4j Database). There are two components for the portal, the [`UI application`](/ui-react) (in React) and the [`API app`](/api) (GraphQL server).
3+
This project was started with [GRANDstack](https://grandstack.io) (GraphQL, React, Apollo, Neo4j Database).
4+
There are two components for the portal:
45

5-
## API
6+
- `ui-react`: the UI application in React
7+
- `api`: the API application (GraphQL server)
8+
9+
### API
610

711
![GraphQL API diagram](./diagram.png)
812

13+
## Local install
14+
15+
### Requirements
16+
17+
- Node.js 12 (`lts/erbium`)
18+
- Docker and `docker-compose`
19+
20+
### Run GraphGist portal
21+
22+
Create a copy of `ui-react/.env-example` and `api/.env-example` within the same directory using the name `.env`.
23+
24+
```
25+
cp ./ui-react/.env-example ./ui-react/.env
26+
cp ./api/.env-example ./api/.env
27+
```
28+
29+
#### Using Docker Compose
30+
31+
Using `docker-compose`:
32+
33+
```
34+
docker-compose up -d
35+
```
36+
37+
This will take some time on the first run.
38+
Once the containers have been started, you can check the log to check if the UI is up and running using:
39+
40+
```
41+
docker logs -f graphgist-portal-ui
42+
```
43+
44+
The `docker-compose up -d` will start 3 services:
45+
46+
- Neo4j database with the Neo4j Browser available via HTTP at http://localhost:7474/browser/
47+
- Web interface available at http://localhost:3000/
48+
- GraphQL API available at http://localhost:4001/graphql
49+
50+
#### Using npm
51+
52+
```
53+
npm i --prefix ui-react
54+
npm i --prefix api
55+
```
56+
57+
It's recommanded to run the database using Docker to use a compatible version with the Neo4j APOC library enabled:
58+
59+
```
60+
docker-compose run --service-ports neo4j
61+
```
62+
63+
Once the database is up and running, open a new terminal and execute:
64+
65+
```
66+
npm run start --prefix api
67+
```
68+
69+
Open a third terminal and execute:
70+
71+
```
72+
npm run start --prefix ui-react
73+
```
74+
75+
### Switch to admin
76+
77+
Once you've created an account, you can manually update the associated user to become an admin using the following Cypher query:
78+
79+
```
80+
MATCH (p:User {email: '[email protected]'})
81+
SET p.admin = true
82+
RETURN p
83+
```
84+
985
## Deployment
1086

1187
This is currently deployed to Heroku, since this repository contains both API and UI repository we need to individually push each one, to achieve that we can create a subtree branch with only that specific folder:

api/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
*~
2+
node_modules/
3+
build/

api/.env-example

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
NEO4J_URI=""
1+
NODE_ENV=development
2+
3+
NEO4J_URI="bolt://localhost:7687"
24
NEO4J_USER=neo4j
3-
NEO4J_PASSWORD=""
5+
NEO4J_PASSWORD=secret
46

57
GRAPHQL_LISTEN_PORT=4001
68
GRAPHQL_URI=http://localhost:4001/graphql
@@ -11,11 +13,11 @@ AWS_ACCESS_KEY_ID=""
1113
AWS_SECRET_ACCESS_KEY=""
1214
AWS_REGION="eu-west-1"
1315

14-
AUTH0_DOMAIN=""
15-
AUTH0_CLIENT_ID=""
16+
AUTH0_DOMAIN=ap2-tsl.auth0.com
17+
AUTH0_CLIENT_ID=sDiVDqggZV01En6i2PaJWDzdiFpZ9V7v
1618

1719
SENTRY_DSN=""
1820

1921
IMAGEKIT_PUBLIC_KEY=''
2022
IMAGEKIT_PRIVATE_KEY=''
21-
IMAGEKIT_URL_ENDPOINT=https://ik.imagekit.io/ggp
23+
IMAGEKIT_URL_ENDPOINT=https://ik.imagekit.io/ggp

api/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM node:12
33
RUN mkdir -p /app
44
WORKDIR /app
55

6-
COPY package.json .
6+
COPY package*.json ./
77
RUN npm install
88
COPY . .
99

api/package-lock.json

Lines changed: 48 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"scripts": {
1010
"test": "jest",
1111
"start-dev": "./node_modules/.bin/nodemon --watch src --ext js,graphql --exec babel-node src/index.js",
12-
"build": "babel src -d build && shx cp .env-example build && shx cp src/schema.graphql build && shx cp src/graphgists/notify_admins_about_creation.ejs build/graphgists/notify_admins_about_creation.ejs",
12+
"build": "babel src -d build && shx cp src/schema.graphql build && shx cp src/graphgists/notify_admins_about_creation.ejs build/graphgists/notify_admins_about_creation.ejs",
1313
"start": "npm run build && node build/index.js",
1414
"prettier": "prettier --write",
1515
"clean-temp-dbs": "babel-node src/clean_temp_dbs.js"
@@ -40,7 +40,7 @@
4040
"neo4j-driver": "^4.2.3",
4141
"neo4j-graphql-js": "^2.19.4",
4242
"neo4j-temp-db": "git+https://github.com/neo4j-contrib/neo4j-temp-db.git#v0.2.1",
43-
"node-fetch": "^2.6.1",
43+
"node-fetch": "^2.6.7",
4444
"sharp": "^0.26.1",
4545
"shortid": "^2.2.15",
4646
"slugify": "^1.4.6",

api/src/auth.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ function getKey(header, cb) {
1616
if (key) {
1717
var signingKey = key.publicKey || key.rsaPublicKey;
1818
cb(null, signingKey);
19+
} else {
20+
cb(err, key);
1921
}
2022
});
2123
}
@@ -27,14 +29,18 @@ const options = {
2729
};
2830

2931
export function auth0Verify(token) {
32+
if (process.env.NODE_ENV === 'development' && !process.env.AUTH0_DOMAIN) {
33+
return null; // authentication can be disabled in development when AUTH0_DOMAIN is empty
34+
}
3035
return new Promise((resolve, reject) => {
3136
if (!token) {
3237
resolve(null);
3338
} else {
3439
jwt.verify(token, getKey, options, (err, decoded) => {
35-
// if (err) {
36-
// return reject(err);
37-
// }
40+
if (err) {
41+
console.error('Cannot verify the token!', err)
42+
return resolve(null);
43+
}
3844
resolve(decoded);
3945
});
4046
}

api/src/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ import neo4j from "neo4j-driver";
55
import { makeAugmentedSchema } from "neo4j-graphql-js";
66
import { GraphQLUpload, graphqlUploadExpress } from "graphql-upload";
77
import Asciidoctor from "asciidoctor";
8-
98
import dotenv from "dotenv";
109

11-
dotenv.config();
12-
1310
import * as Sentry from "@sentry/node";
1411
import * as Tracing from "@sentry/tracing";
1512

@@ -31,6 +28,8 @@ import * as imagesMutations from "./images/mutations";
3128
import * as imagesTypes from "./images/types";
3229
import { getGraphGistBySlug, getGraphGistByUUID } from "./graphgists/utils";
3330

31+
dotenv.config();
32+
3433
/*
3534
* Create a Neo4j driver instance to connect to the database
3635
* using credentials specified as environment variables
@@ -132,7 +131,7 @@ const server = new ApolloServer({
132131
extensions: {
133132
...error.extensions,
134133
exception: {
135-
...error.extensions.exception,
134+
...error.extensions.exception,
136135
stacktrace: process.env.NODE_ENV !== "production" ? error.extensions.exception.stacktrace : undefined
137136
}
138137
}

docker-compose.yml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,46 @@ services:
44

55
neo4j:
66
build: ./neo4j
7+
container_name: "graphgist-portal-neo4j"
78
ports:
8-
- 7474:7474
9-
- 7687:7687
9+
- "7474:7474"
10+
- "7687:7687"
1011
environment:
1112
- NEO4J_dbms_security_procedures_unrestricted=apoc.*
1213
- NEO4J_apoc_import_file_enabled=true
1314
- NEO4J_apoc_export_file_enabled=true
1415
- NEO4J_dbms_shell_enabled=true
16+
- NEO4J_AUTH=neo4j/secret
1517
volumes:
1618
- ./neo4j/import:/var/lib/neo4j/import
1719
- ./neo4j/data:/var/lib/neo4j/data
1820
- ./neo4j/config:/var/lib/neo4j/conf
1921

2022
api:
2123
build: ./api
24+
container_name: "graphgist-portal-api"
2225
ports:
23-
- 4001:4001
26+
- "4001:4001"
2427
environment:
25-
- GRAPHQL_LISTEN_PORT=4001
26-
- GRAPHQL_URI=http://api:4001/graphql
27-
28+
- NEO4J_PASSWORD=secret
29+
- NEO4J_URI=bolt://neo4j:7687
30+
env_file:
31+
- ./api/.env
2832
links:
2933
- neo4j
3034
depends_on:
3135
- neo4j
32-
33-
volumes:
34-
- ./api:/app
3536

3637
ui:
3738
build: ./ui-react
39+
container_name: "graphgist-portal-ui"
3840
ports:
39-
- 3000:3000
41+
- "3000:3000"
4042
environment:
4143
- CI=true
42-
- REACT_APP_GRAPHQL_URI=/graphql
43-
- PROXY=http://api:4001/graphql
44+
- REACT_APP_GRAPHQL_URI=http://localhost:4001/graphql
45+
env_file:
46+
- ./ui-react/.env
4447
links:
4548
- api
4649
depends_on:

0 commit comments

Comments
 (0)