1
+ ARG PY_VERSION_DEFAULT=3.12
2
+ ARG MGBUILD_IMAGE
3
+
4
+ FROM $MGBUILD_IMAGE as builder
5
+
6
+ USER root
7
+
8
+ ARG TARGETARCH
9
+ ARG PY_VERSION_DEFAULT
10
+ ARG BUILD_TYPE
11
+ ARG CACHE_PRESENT
12
+ ENV BUILD_TYPE=${BUILD_TYPE}
13
+ ENV PY_VERSION ${PY_VERSION_DEFAULT}
14
+ ARG CUSTOM_MIRROR
15
+
16
+
17
+ # This modifies the apt configuration to rety 3 times
18
+ RUN echo 'Acquire::Retries "3";' > /etc/apt/apt.conf.d/80-retries
19
+
20
+ # If CUSTOM_MIRROR is set, replace the default archive.ubuntu.com
21
+ # and security.ubuntu.com URIs in your .sources file
22
+ RUN if [ -n "$CUSTOM_MIRROR" ]; then \
23
+ sed -E -i \
24
+ -e '/^URIs:/ s#https?://[^ ]*archive\.ubuntu\.com#'"$CUSTOM_MIRROR"'#g' \
25
+ -e '/^URIs:/ s#https?://security\.ubuntu\.com#'"$CUSTOM_MIRROR"'#g' \
26
+ /etc/apt/sources.list.d/ubuntu.sources; \
27
+ fi
28
+
29
+ # Essentials for production/dev
30
+ RUN apt-get update && apt-get install -y \
31
+ libcurl4 `memgraph` \
32
+ libpython${PY_VERSION} `memgraph` \
33
+ libssl-dev `memgraph` \
34
+ openssl `memgraph` \
35
+ build-essential `mage-memgraph` \
36
+ cmake `mage-memgraph` \
37
+ curl `mage-memgraph` \
38
+ g++ `mage-memgraph` \
39
+ python3 `mage-memgraph` \
40
+ python3-pip `mage-memgraph` \
41
+ python3-setuptools `mage-memgraph` \
42
+ python3-dev `mage-memgraph` \
43
+ clang `mage-memgraph` \
44
+ git `mage-memgraph` \
45
+ unixodbc-dev `mage-memgraph` \
46
+ libboost-all-dev `mage-memgraph` \
47
+ uuid-dev \
48
+ gdb \
49
+ procps \
50
+ libc6-dbg \
51
+ libxmlsec1-dev xmlsec1 \
52
+ libatomic1 \
53
+ --no-install-recommends \
54
+ && ln -s /usr/bin/$(ls /usr/bin | grep perf) /usr/bin/perf \
55
+ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
56
+
57
+ COPY memgraph-${TARGETARCH}.deb .
58
+
59
+ RUN dpkg -i memgraph-${TARGETARCH}.deb && rm memgraph-${TARGETARCH}.deb
60
+
61
+ # move memgraph HOME so that mounting /var/lib/memgraph as a volume doesn't break Python
62
+ RUN mkdir -pv /home/memgraph && \
63
+ usermod -d /home/memgraph memgraph && \
64
+ chown -R memgraph:memgraph /home/memgraph
65
+
66
+ ENV LD_LIBRARY_PATH /usr/lib/memgraph/query_modules
67
+
68
+
69
+ WORKDIR /mage
70
+ COPY . /mage
71
+
72
+ #hacks so we can do everything under the `memgraph` user
73
+ RUN chown -R memgraph: /mage && \
74
+ mkdir -pv /usr/lib/memgraph/query_modules && \
75
+ chown -R memgraph: /usr/lib/memgraph/query_modules
76
+ USER memgraph
77
+
78
+ # First install requirements
79
+ RUN python3 -m pip install --no-cache-dir -r /mage/python/requirements-gpu.txt --break-system-packages && \
80
+ python3 -m pip install --no-cache-dir -r /mage/python/tests/requirements.txt --break-system-packages && \
81
+ python3 -m pip install --no-cache-dir -r /usr/lib/memgraph/auth_module/requirements.txt --break-system-packages && \
82
+ python3 -m pip install --no-cache-dir torch-sparse torch-cluster torch-spline-conv torch-geometric torch-scatter --break-system-packages -f https://data.pyg.org/whl/torch-2.6.0+cu126.html; \
83
+ python3 -m pip install --no-cache-dir dgl==2.5.0 -f https://data.dgl.ai/wheels/torch-2.6/repo.html --break-system-packages; \
84
+ rm -fr /home/memgraph/.cache/pip
85
+
86
+ # Build query modules
87
+ SHELL ["/bin/bash", "-c"]
88
+ RUN source /opt/toolchain-v6/activate && curl https://sh.rustup.rs -sSf | sh -s -- -y \
89
+ && export PATH="$HOME/.cargo/bin:${PATH}" \
90
+ && rustup toolchain install 1.85 \
91
+ && rustup default 1.85 \
92
+ && python3 /mage/setup build -p /usr/lib/memgraph/query_modules/ --cpp-build-flags CMAKE_BUILD_TYPE=${BUILD_TYPE} \
93
+ && chown -R memgraph: /mage
94
+
95
+
96
+ # Memgraph listens for Bolt Protocol on this port by default.
97
+ EXPOSE 7687
98
+
99
+
100
+
101
+ FROM ubuntu:24.04 as base
102
+
103
+ USER root
104
+
105
+ ARG TARGETARCH
106
+ ARG PY_VERSION_DEFAULT=3.12
107
+ ARG MAGE_COMMIT
108
+ ARG BUILD_TYPE
109
+ ENV BUILD_TYPE=${BUILD_TYPE}
110
+ ENV PY_VERSION ${PY_VERSION_DEFAULT}
111
+ ENV MAGE_COMMIT=${MAGE_COMMIT}
112
+ ARG CUSTOM_MIRROR
113
+
114
+ # This modifies the apt configuration to rety 3 times
115
+ RUN echo 'Acquire::Retries "3";' > /etc/apt/apt.conf.d/80-retries
116
+
117
+ # If CUSTOM_MIRROR is set, replace the default archive.ubuntu.com
118
+ # and security.ubuntu.com URIs in your .sources file
119
+ RUN if [ -n "$CUSTOM_MIRROR" ]; then \
120
+ sed -E -i \
121
+ -e '/^URIs:/ s#https?://[^ ]*archive\.ubuntu\.com#'"$CUSTOM_MIRROR"'#g' \
122
+ -e '/^URIs:/ s#https?://security\.ubuntu\.com#'"$CUSTOM_MIRROR"'#g' \
123
+ /etc/apt/sources.list.d/ubuntu.sources; \
124
+ fi
125
+
126
+ # Essentials for production/dev
127
+ RUN apt-get update && \
128
+ apt-get install -y curl && \
129
+ curl -sSL -O https://packages.microsoft.com/config/ubuntu/24.04/packages-microsoft-prod.deb && \
130
+ dpkg -i packages-microsoft-prod.deb && \
131
+ rm packages-microsoft-prod.deb && \
132
+ apt-get update && \
133
+ ACCEPT_EULA=Y apt-get install -y msodbcsql18 unixodbc-dev && \
134
+ apt-get install -y \
135
+ libcurl4 `memgraph` \
136
+ libpython${PY_VERSION} `memgraph` \
137
+ libssl-dev `memgraph` \
138
+ openssl `memgraph` \
139
+ python3 `mage-memgraph` \
140
+ python3-pip `mage-memgraph` \
141
+ python3-setuptools `mage-memgraph` \
142
+ python3-dev `mage-memgraph` \
143
+ libc6-dbg \
144
+ adduser \
145
+ libgomp1 \
146
+ libaio1t64 \
147
+ libatomic1 \
148
+ --no-install-recommends \
149
+ && ln -s /usr/bin/$(ls /usr/bin | grep perf) /usr/bin/perf \
150
+ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
151
+ if [ "${TARGETARCH}" = "arm64" ]; then \
152
+ ln -s /usr/lib/aarch64-linux-gnu/libaio.so.1t64 /usr/lib/aarch64-linux-gnu/libaio.so.1; \
153
+ else \
154
+ ln -s /usr/lib/x86_64-linux-gnu/libaio.so.1t64 /usr/lib/x86_64-linux-gnu/libaio.so.1; \
155
+ fi
156
+
157
+ # install memgraph
158
+ COPY memgraph-${TARGETARCH}.deb .
159
+
160
+ # fix `memgraph` UID and GID for compatibility with previous Debian releases
161
+ RUN groupadd -g 103 memgraph && \
162
+ useradd -u 101 -g memgraph -m -d /home/memgraph -s /bin/bash memgraph && \
163
+ dpkg -i memgraph-${TARGETARCH}.deb && \
164
+ rm memgraph-${TARGETARCH}.deb
165
+
166
+ ENV LD_LIBRARY_PATH /usr/lib/memgraph/query_modules
167
+
168
+ # Copy modules
169
+ COPY --from=builder /usr/lib/memgraph/query_modules/ /usr/lib/memgraph/query_modules/
170
+ COPY --from=builder /usr/lib/memgraph/auth_module/ /usr/lib/memgraph/auth_module/
171
+
172
+ # Copy Python build
173
+ COPY --from=builder /usr/local/lib/python${PY_VERSION}/ /usr/local/lib/python${PY_VERSION}/
174
+ COPY --from=builder --chown=memgraph:memgraph /home/memgraph/.local/ /home/memgraph/.local/
175
+
176
+ # copy script to convert to dev container
177
+ COPY --from=builder /mage/make-dev-container.sh /make-dev-container.sh
178
+
179
+ FROM base as prod
180
+
181
+ USER root
182
+
183
+ ARG TARGETARCH
184
+ ARG PY_VERSION_DEFAULT=3.12
185
+ ARG MAGE_COMMIT
186
+ ARG BUILD_TYPE
187
+ ENV BUILD_TYPE=${BUILD_TYPE}
188
+ ENV PY_VERSION ${PY_VERSION_DEFAULT}
189
+ ENV MAGE_COMMIT=${MAGE_COMMIT}
190
+ ARG CUSTOM_MIRROR
191
+
192
+ # Copy e2e tests
193
+ COPY --from=builder --chown=memgraph:memgraph /mage/e2e/ /mage/e2e/
194
+ COPY --from=builder --chown=memgraph:memgraph /mage/e2e_correctness/ /mage/e2e_correctness/
195
+ COPY --from=builder --chown=memgraph:memgraph /mage/test_e2e_correctness.py /mage/test_e2e_correctness.py
196
+ COPY --from=builder --chown=memgraph:memgraph /mage/run_e2e_correctness_tests.sh /mage/run_e2e_correctness_tests.sh
197
+
198
+ # Copy requirements
199
+ COPY --from=builder --chown=memgraph:memgraph /mage/python/requirements.txt /mage/python/requirements.txt
200
+ COPY --from=builder --chown=memgraph:memgraph /mage/python/tests/requirements.txt /mage/python/tests/requirements.txt
201
+
202
+ RUN if [ -n "$CUSTOM_MIRROR" ]; then \
203
+ sed -E -i \
204
+ -e "/^URIs:/ s#${CUSTOM_MIRROR}/ubuntu/#https://archive.ubuntu.com/ubuntu/#g" \
205
+ -e "/^URIs:/ s#${CUSTOM_MIRROR}/ubuntu/#https://security.ubuntu.com/ubuntu/#g" \
206
+ /etc/apt/sources.list.d/ubuntu.sources; \
207
+ fi
208
+
209
+ USER memgraph
210
+ EXPOSE 7687
211
+
212
+ ENTRYPOINT ["/usr/lib/memgraph/memgraph"]
213
+ CMD [""]
214
+
215
+
216
+ FROM base as debug
217
+
218
+ USER root
219
+
220
+ ARG TARGETARCH
221
+ ARG PY_VERSION_DEFAULT=3.12
222
+ ARG MAGE_COMMIT
223
+ ARG BUILD_TYPE
224
+ ENV BUILD_TYPE=${BUILD_TYPE}
225
+ ENV PY_VERSION ${PY_VERSION_DEFAULT}
226
+ ENV MAGE_COMMIT=${MAGE_COMMIT}
227
+ ARG CUSTOM_MIRROR
228
+
229
+ # Add gdb
230
+ RUN apt-get update && apt-get install -y \
231
+ gdb \
232
+ --no-install-recommends \
233
+ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
234
+
235
+ # Copy entire mage repo
236
+ COPY --from=builder --chown=memgraph:memgraph /mage/ /mage/
237
+
238
+ RUN if [ -n "$CUSTOM_MIRROR" ]; then \
239
+ sed -E -i \
240
+ -e "/^URIs:/ s#${CUSTOM_MIRROR}/ubuntu/#https://archive.ubuntu.com/ubuntu/#g" \
241
+ -e "/^URIs:/ s#${CUSTOM_MIRROR}/ubuntu/#https://security.ubuntu.com/ubuntu/#g" \
242
+ /etc/apt/sources.list.d/ubuntu.sources; \
243
+ fi
244
+
245
+ USER memgraph
246
+ EXPOSE 7687
247
+
248
+ ENTRYPOINT ["/usr/lib/memgraph/memgraph"]
249
+ CMD [""]
0 commit comments