Skip to content

Commit d0e5cbd

Browse files
committed
feat: docker set-up for neo4j
1 parent 99f6a17 commit d0e5cbd

4 files changed

Lines changed: 208 additions & 3 deletions

File tree

.github/workflows/docker-build.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: Build and Push Docker Image for Quickstart
2+
3+
on:
4+
release:
5+
type: [published]
6+
#trigger on each commit of each branch and push with latest tag
7+
push :
8+
# pull_request:
9+
# paths:
10+
# - 'pyproject.toml'
11+
# - './docker/**'
12+
# - '.github/workflows/**'
13+
14+
env:
15+
REGISTRY: ghcr.io
16+
17+
jobs:
18+
build-image:
19+
runs-on: ubuntu-latest
20+
#if: github.ref != 'refs/heads/main'
21+
permissions:
22+
contents: read
23+
packages: write
24+
25+
steps:
26+
# https://github.com/actions/checkout
27+
- name: checkout repository
28+
uses: actions/checkout@v4
29+
30+
- name: lowercase image name
31+
run: |
32+
echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
33+
34+
# https://github.com/docker/setup-qemu-action
35+
- name: Set up QEMU
36+
uses: docker/setup-qemu-action@v3.0.0
37+
38+
# https://github.com/docker/setup-buildx-action
39+
- name: Set up Docker Buildx
40+
id: buildx
41+
uses: docker/setup-buildx-action@v3.0.0
42+
43+
- name: Get current release version
44+
id: release-version
45+
run: |
46+
version=$(grep -E '^version += +' pyproject.toml | sed -E 's/.*= +//' | sed "s/['\"]//g")
47+
echo "version=${version}" >> $GITHUB_OUTPUT
48+
echo "version_build=${version}_"$(git rev-parse --short "$GITHUB_SHA") >> $GITHUB_OUTPUT
49+
50+
# https://github.com/docker/build-push-action
51+
- name: Build Docker image
52+
uses: docker/build-push-action@v5.0.0
53+
with:
54+
context: .
55+
platforms: linux/amd64
56+
file: tools/images/Dockerfile
57+
push: false
58+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.release-version.outputs.version_build }}
59+
build-args: PLATFORM=cu124
60+
outputs: type=image,annotation-index.org.opencontainers.image.description=Run a Graph Neural Network.
61+
62+
push-image:
63+
runs-on: ubuntu-latest
64+
#if: github.ref == 'refs/heads/main'
65+
permissions:
66+
contents: read
67+
packages: write
68+
69+
steps:
70+
# https://github.com/actions/checkout
71+
- name: checkout repository
72+
uses: actions/checkout@v4
73+
74+
- name: lowercase image name
75+
run: |
76+
echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
77+
78+
# https://github.com/docker/setup-qemu-action
79+
- name: Set up QEMU
80+
uses: docker/setup-qemu-action@v3.0.0
81+
82+
# https://github.com/docker/setup-buildx-action
83+
- name: Set up Docker Buildx
84+
id: buildx
85+
uses: docker/setup-buildx-action@v3.0.0
86+
87+
- name: Get current release version
88+
id: release-version
89+
run: |
90+
version=$(grep -E '^version += +' pyproject.toml | sed -E 's/.*= +//' | sed "s/['\"]//g")
91+
echo "version=${version}" >> $GITHUB_OUTPUT
92+
echo "version_build=${version}_"$(git rev-parse --short "$GITHUB_SHA") >> $GITHUB_OUTPUT
93+
94+
# https://github.com/docker/login-action
95+
- name: Log in to the Container registry
96+
uses: docker/login-action@v3.0.0
97+
with:
98+
registry: ${{ env.REGISTRY }}
99+
username: ${{ github.actor }}
100+
password: ${{ secrets.GITHUB_TOKEN }}
101+
102+
# https://github.com/docker/metadata-action
103+
- name: Extract metadata (tags, labels) for Docker
104+
id: meta
105+
uses: docker/metadata-action@v5.0.0
106+
with:
107+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
108+
tags: |
109+
type=raw,value=latest,enable=${{ github.event_name == 'push' }}
110+
type=raw,value=${{ needs.build-image.outputs.version }},enable=${{ github.event_name == 'release' }}
111+
112+
# https://github.com/docker/build-push-action
113+
- name: Push Docker image
114+
uses: docker/build-push-action@v5.0.0
115+
with:
116+
context: .
117+
platforms: linux/amd64
118+
file: tools/images/Dockerfile
119+
push: true
120+
tags: ${{ steps.meta.outputs.tags }}
121+
labels: ${{ steps.meta.outputs.labels }}
122+
build-args: PLATFORM=cu124
123+
outputs: type=image,annotation-index.org.opencontainers.image.description=Run a Graph Neural Network.

src/neo4j-quickstart/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ We are using uv ([installation instructions here](https://docs.astral.sh/uv/gett
88

99
1. Create virtual environment: `uv venv`
1010
2. Activate it: `source .venv/bin/activate`
11-
3. Get all predefined dependencies from the `uv.lock` file by running the command: `uv sync`
11+
3. Get all predefined dependencies from the `uv.lock` file by running the command: `uv sync`
12+
13+
## Build docker
14+
15+
Locally: `docker build -f tools/images/Dockerfile -t test .`
16+
17+
Else there is an integrated github CI in the github workflows of this repository.

src/neo4j-quickstart/quickstart.ipynb

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,42 @@
114114
"df.head()"
115115
]
116116
},
117+
{
118+
"cell_type": "code",
119+
"execution_count": null,
120+
"id": "8dfd7fef",
121+
"metadata": {},
122+
"outputs": [],
123+
"source": [
124+
"from utils.builder_models import df_to_pydantic_models\n",
125+
"graph = df_to_pydantic_models(df.head(200), relationships)"
126+
]
127+
},
117128
{
118129
"cell_type": "markdown",
119130
"id": "4f5f2f38",
120131
"metadata": {},
121132
"source": [
122133
"## Visualizing the Graph\n",
123134
"\n",
124-
"Here is some code snippet for visualizing the graph you have downloaded from Neo4J."
135+
"Here is some code snippet for visualizing the graph you have downloaded from Neo4J.\n",
136+
"\n",
137+
"**Disclaimer: if you run visualization on an entire graph of over 5000 nodes, it may take a long time or may give unreadable graphs. Be smart in your visualizations.**\n",
138+
"\n",
139+
"For CUSTOM visualizations, if you are familiar with networkx, there is a `create_networkx_graph` function in `visualization.py` from which you can kick off other graph manipulations or visualizations."
140+
]
141+
},
142+
{
143+
"cell_type": "markdown",
144+
"id": "ccef6835",
145+
"metadata": {},
146+
"source": [
147+
"### Visualize the entire graph or a subpart of the graph. \n",
148+
"\n",
149+
"We suggest: \n",
150+
"1. select from the dataframe (classic pandas operations)\n",
151+
"2. convert to the pydantic models \n",
152+
"3. run visualizations"
125153
]
126154
},
127155
{
@@ -130,7 +158,35 @@
130158
"id": "7df5ca1c",
131159
"metadata": {},
132160
"outputs": [],
133-
"source": []
161+
"source": [
162+
"from utils.visualization import visualize_graph\n",
163+
"from pathlib import Path\n",
164+
"output_path = Path(\"plots/graphs/graph_visualization.png\")\n",
165+
"visualize_graph(graph, output_path)"
166+
]
167+
},
168+
{
169+
"cell_type": "markdown",
170+
"id": "8ad91bf7",
171+
"metadata": {},
172+
"source": [
173+
"### Visualize Clusters in the graph\n",
174+
"This function will make clusters based on the nodes that are handed over. \n",
175+
"We use the function from networkx `nx.weakly_connected_components(G)`"
176+
]
177+
},
178+
{
179+
"cell_type": "code",
180+
"execution_count": null,
181+
"id": "581739d7",
182+
"metadata": {},
183+
"outputs": [],
184+
"source": [
185+
"from utils.visualization import visualize_clusters\n",
186+
"from pathlib import Path\n",
187+
"output_dir = Path(\"plots/clusters/\")\n",
188+
"visualize_clusters(graph, output_dir)"
189+
]
134190
}
135191
],
136192
"metadata": {

tools/images/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM python:3.10-slim
2+
3+
# TO-DO how to generalize for other tools. i.e. CHAOSS and a graph database access
4+
5+
# Install uv
6+
COPY --from=ghcr.io/astral-sh/uv:0.6.12 /uv /uvx /bin/
7+
8+
# Copy the project into the image
9+
ADD src/neo4j-quickstart /app/neo4j-quickstart
10+
11+
# Sync the project into a new environment, using the frozen lockfile
12+
WORKDIR /app
13+
RUN cd neo4j-quickstart && uv sync
14+
15+
# make uv's python the default python for the image
16+
ENV PATH="/app/neo4j-quickstart/.venv/bin:$PATH"
17+
18+
# Set PYTHONPATH for imports
19+
ENV PYTHONPATH=/app/neo4j-quickstart
20+

0 commit comments

Comments
 (0)