Skip to content

Commit fabe5c7

Browse files
authored
Merge pull request #16 from avisionh/feature/dockerfile
Feature: Dockerfile
2 parents d1b1a18 + 9bdaa2e commit fabe5c7

23 files changed

Lines changed: 34 additions & 20 deletions

Dockerfile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,30 @@ FROM python:${PY_VER} AS sqlqeurygraph-py
44
## Add the wait script to the image
55
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.9.0/wait /wait
66

7+
# download pipenv so can create requirements.txt
8+
# for faster environment recreation
9+
# https://pythonspeed.com/articles/pipenv-docker/
10+
RUN pip install --upgrade pip \
11+
&& pip install poetry
12+
COPY poetry.lock ./tmp
13+
COPY pyproject.toml ./
14+
RUN poetry export -f requirements.txt -o requirements.txt
15+
16+
# move relevant folders and files from local to container
17+
COPY ./example ./example
18+
COPY sqlquerygraph.py ./
19+
COPY exporter.py ./
20+
COPY extractor.py ./
21+
COPY writer.py ./
22+
COPY loader.py ./
23+
724
# install package for loader and give it executable rights
8-
RUN pip install py2neo \
25+
RUN pip install -r requirements.txt \
926
&& mkdir log \
1027
&& mkdir data \
28+
&& mkdir neo4j \
29+
&& python sqlquerygraph.py -sd 'example/sql' -ed 'example/neo4j' -rd 'github_repos' 'analytics' 'reporting' \
1130
&& chmod +x /wait
1231

1332
# move relevant files so they can be executed
14-
COPY ./loader.py ./
1533
COPY ./neo4j/*.cypher ./data

README.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ To run the code in here, ensure your system meets the following requirements:
2323
- Python 3.8 or above; and
2424
- [Poetry](https://python-poetry.org/docs/) installed.
2525
- [`direnv`](https://direnv.net/) installed, including shell hooks;
26-
- [`.envrc`](https://github.com/avisionh/sqlquerygraph/blob/main/.envrc) allowed/trusted by `direnv` to use the environment variables - see [below](#set-up);
2726

2827
<!--Note there may be some Python IDE-specific requirements around loading environment variables, which are not considered here. -->
2928

@@ -41,9 +40,9 @@ poetry install
4140
pre-commit install
4241
```
4342

44-
To then extract the tables and their dependencies from the example SQL scripts in the `sql/` directory, run the following in your shell/terminal:
43+
To then extract the tables and their dependencies from the example SQL scripts in the `sql/` directory, run the below in your shell/terminal. It will generate `.csv` files of the tables and their dependencies. It will also generate `.cypher` files to enable you to import the data into neo4j, after you have added the `.csv` files to the database.
4544
```shell script
46-
python sqlquerygraph.py -sd 'sql' -ed 'neo4j' -rd 'github_repos' 'analytics' 'reporting'
45+
python sqlquerygraph.py -sd 'sql' -ed 'neo4j' -rd '<datasets, individually quoted and separated by commas, of tables in sql/ scripts>'
4746
```
4847

4948
### Run neo4j graph database
@@ -59,19 +58,16 @@ We use [neo4j](https://neo4j.com/) for this project to visualise the dependencie
5958
export NEO4J_USERNAME=neo4j
6059
export NEO4J_PASSWORD=<your_password>
6160
```
62-
63-
1. Update your `.env` file to take in the new `.secrets` file you created by entering the below in your shell/terminal:
61+
Then update your `.env` file to take in the new `.secrets` file you created by entering the below in your shell/terminal:
6462
```shell script
6563
direnv allow
6664
```
6765

6866
1. Build the Docker image and launch the container. Within this directory that has the `docker-compose.yml` file, run the below in your shell/terminal:
6967
```shell script
70-
docker-compose build
7168
docker-compose up
7269
```
73-
74-
1. If it's the first time you have downloaded the neo4j docker image, wait awhile (maybe 15 minutes, depends on your machine specs). If you have downloaded the neo4j docker image before (such as going through these instructions), then wait a few minutes. You will know when it's ready when you get the following message in your terminal:
70+
You will know when it's ready when you get the following message in your terminal:
7571
```
7672
app | [INFO wait] Host [neo4j:7687] is now available!
7773
app | [INFO wait] --------------------------------------------------------
@@ -81,7 +77,7 @@ We use [neo4j](https://neo4j.com/) for this project to visualise the dependencie
8177
Then launch neo4j locally via opening your web browser and entering the following web address:
8278
- http://localhost:7474/
8379

84-
1. The username and password will those specified in your `.secrets` file.
80+
The username and password will those specified in your `.secrets` file.
8581

8682
1. When you have finished playing with your local neo4j instance, remember to stop it running by executing the below in your shell/terminal:
8783
```shell script

docker-compose.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
- 7474:7474 # web client
1515
- 7687:7687 # db default port
1616
volumes:
17-
- ./neo4j:/var/lib/neo4j/import
17+
- ./example/neo4j:/var/lib/neo4j/import
1818
environment:
1919
- NEO4j_dbms.security.auth_enabled='true'
2020
# install graph-data-science plugin
@@ -30,7 +30,7 @@ services:
3030
- neo4j_network
3131

3232
app:
33-
build: .
33+
build: . # build from Dockerfile
3434
container_name: app
3535
env_file: .env
3636
environment:
@@ -42,8 +42,8 @@ services:
4242
- neo4j
4343
command: >
4444
sh -c "/wait \
45-
&& python -m loader --file 'data/query_constraints.cypher' \
46-
&& python -m loader --file 'data/query_nodes.cypher' \
47-
&& python -m loader --file 'data/query_relationships.cypher'"
45+
&& python -m loader --file 'example/neo4j/query_constraints.cypher' \
46+
&& python -m loader --file 'example/neo4j/query_nodes.cypher' \
47+
&& python -m loader --file 'example/neo4j/query_relationships.cypher'"
4848
networks:
4949
- neo4j_network
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)