-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathDockerfile.24
More file actions
468 lines (429 loc) · 16 KB
/
Dockerfile.24
File metadata and controls
468 lines (429 loc) · 16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# # Shared Dockerfile for third party dependencies used in projects in the p4lang
# # organization.
# #
# # Best practices for multi-stage builds are available at
# # https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
# #
# # The approach used in this Dockerfile is as follows:
# #
# # A multi-stage build creates a separate image for each third party dependency and
# # then copies only the binaries to a single output image at the end.
# #
# # If you add a new dependency, please:
# # (1) Create a new build image for it. (It should have its own FROM section.)
# # (2) Ensure that it installs everything that should be included in the final
# # image to `/output/usr/local`. Use DESTDIR and PYTHONUSERBASE for this.
# # Be sure to install python packages and code using
# # `pip install --user --ignore-installed`. If you absolutely *must* use
# # `python setup.py install`, take a look at the protobuf build image and
# # then reconsider.
# # (3) Use COPY to place the contents of the build image's `/output/usr/local`
# # in the final image.
# # (4) If the new dependency requires that certain apt packages be installed at
# # runtime (as opposed to at build time), create a new _DEPS variable and
# # install the new packages with all of the others; look at how the final
# # image is constructed and you'll understand the pattern.
# #
# # In general you don't have to worry about the size of intermediate build images,
# # but please minimize the amount of data and the number of layers that end up in the
# # final image.
# # Create an image with tools used as a base for the next layers
# FROM ubuntu:24.04 as base-builder
# ARG MAKEFLAGS=-j2
# ENV DEBIAN_FRONTEND=noninteractive \
# CFLAGS="-Os" \
# CXXFLAGS="-Os" \
# LDFLAGS="-Wl,-s" \
# PYTHONUSERBASE=/output/usr/local \
# LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/output/usr/local/lib/
# RUN apt-get update -qq && apt-get install -qq --no-install-recommends \
# autoconf \
# automake \
# bison \
# build-essential \
# ca-certificates \
# cmake \
# cython3 \
# flex \
# g++ \
# libavl-dev \
# libboost-dev \
# libboost-test-dev \
# libev-dev \
# libevent-dev \
# libffi-dev \
# libmemcached-dev \
# libpcap-dev \
# libpcre3-dev \
# libprotobuf-c-dev \
# libssl-dev \
# libtool \
# make \
# pkg-config \
# protobuf-c-compiler \
# python3 \
# python3-dev \
# python3-pip \
# python3-setuptools && \
# ldconfig && \
# mkdir -p /output/usr/local
# RUN pip3 install --break-system-packages "Cython<3"
# # Build ccache.
# FROM base-builder as ccache
# ENV RUN_FROM_BUILD_FARM=yes
# COPY ./ccache /ccache/
# WORKDIR /ccache/
# # Tell the ccache build system not to bother with things like documentation.
# RUN ./autogen.sh && \
# ./configure --enable-memcached && \
# make && \
# # `make install` assumes that we *did* build the docs; make it happy.
# touch ccache.1 && \
# make DESTDIR=/output install
# # Build PTF.
# FROM base-builder as ptf
# COPY ./ptf /ptf/
# WORKDIR /ptf/
# RUN pip3 install --user --ignore-installed wheel pypcap && \
# pip3 install --user --ignore-installed -rrequirements.txt && \
# pip3 install --user --ignore-installed .
# # Build nanomsg.
# FROM base-builder as nanomsg
# COPY ./nanomsg /nanomsg/
# RUN mkdir -p /nanomsg/build/
# WORKDIR /nanomsg/build/
# RUN cmake .. && \
# make DESTDIR=/output install
# # Build nnpy.
# FROM base-builder as nnpy
# COPY --from=nanomsg /output/usr/local /usr/local/
# COPY ./nnpy /nnpy/
# WORKDIR /nnpy/
# RUN ldconfig && \
# pip3 install --user --ignore-installed wheel cffi && \
# pip3 install --user --ignore-installed .
# # Build Thrift.
# FROM base-builder as thrift
# COPY ./thrift /thrift/
# WORKDIR /thrift/
# RUN ./bootstrap.sh && \
# ./configure \
# --with-cpp=yes \
# --with-python=yes \
# --with-c_glib=no \
# --with-java=no \
# --with-ruby=no \
# --with-erlang=no \
# --with-go=no \
# --with-nodejs=no \
# --enable-tests=no && \
# make && \
# make DESTDIR=/output install-strip
# WORKDIR /thrift/lib/py/
# RUN pip3 install --user --ignore-installed .
# # Build Protocol Buffers.
# FROM base-builder as protobuf
# COPY ./protobuf /protobuf/
# WORKDIR /protobuf/
# RUN ./autogen.sh && \
# ./configure && \
# make && \
# make DESTDIR=/output install-strip
# WORKDIR /protobuf/python/
# # Protobuf is using a deprecated technique to install Python package with
# # easy install. This is causing issues since 2021-04-21. (https://discuss.python.org/t/pypi-org-recently-changed/8433)
# # We have to install pip and install six ourselves so we do not trigger the
# # broken protobuf install process.
# RUN pip3 install --user --ignore-installed wheel six && \
# python3 setup.py install --user --cpp_implementation
# # We'll finish up the process of building protobuf below, but first, a bit of
# # explanation.
# #
# # Since we can't use `pip` with protobuf's `setup.py`, the package gets
# # installed via setuptools in an "egg" - a directory which acts as a python
# # module, but isn't a package and thus isn't automatically part of the package
# # namespace. Eggs need their contents to be added to python's `sys.path` to
# # become visible. Hooks that run early during python startup normally read
# # `setuptools.pth` and other `.pth` files and add all of the directories
# # referenced in those files to the path; egg contents are placed in those files
# # to be made available to the rest of the python installation.
# #
# # In multistage builds this doesn't work so well, because those `.pth` files can
# # easily be overwritten by other versions from a different image, and the eggs
# # we're installing here will no longer appear in `sys.path`. To work around
# # that, we just copy the contents of the existing `.pth` files into a new one
# # with a name we're sure won't be overwritten. Python will read this new `.pth`
# # file at startup and include the eggs in the path.
# #
# # If you're wondering why the `grep -v` is necessary, meditate upon the fact
# # that these files aren't merely metadata but also executable code, and
# # setuptools, by design, uses this feature to inject code into every python
# # program that runs on your system.
# RUN export PYTHON3_VERSION=`python3 -c 'import sys; version=sys.version_info[:3]; print("python{0}.{1}".format(*version))'` && \
# cd /output/usr/local/lib/$PYTHON3_VERSION/site-packages&& \
# cat *.pth | grep -v "import sys" | sort -u > docker_protobuf.pth
# # Build gRPC.
# # The gRPC build system should detect that a version of protobuf is already
# # installed and should not try to install the third-party one included as a
# # submodule in the grpc repository.
# FROM base-builder as grpc
# COPY --from=protobuf /output/usr/local /usr/local/
# RUN ldconfig
# COPY ./grpc /grpc/
# # See https://github.com/grpc/grpc/blob/master/BUILDING.md
# RUN mkdir -p /grpc/cmake/build
# WORKDIR /grpc/cmake/build/
# RUN cmake ../.. \
# -DgRPC_INSTALL=ON \
# -DCMAKE_BUILD_TYPE=Release \
# -DgRPC_PROTOBUF_PROVIDER=package \
# -DgRPC_SSL_PROVIDER=package && \
# make DESTDIR=/output install
# WORKDIR /grpc/
# # `pip install --user` will place things in `site-packages`, but Ubuntu expects
# # `dist-packages` by default, so we need to set configure `site-packages` as an
# # additional "site-specific directory".
# # Without this, our earlier installation of Protobuf will be ignored.
# RUN export PYTHON3_VERSION=`python3 -c 'import sys; version=sys.version_info[:3]; print("python{0}.{1}".format(*version))'` && \
# echo "import site; site.addsitedir('/usr/local/lib/$PYTHON3_VERSION/site-packages')" \
# > /usr/local/lib/$PYTHON3_VERSION/dist-packages/use_site_packages.pth
# # We don't use `--ignore-installed` here because otherwise we won't use the
# # installed version of the protobuf python package that we copied from the
# # protobuf build image.
# # RUN pip3 install --user -rrequirements.txt
# # RUN env GRPC_PYTHON_BUILD_WITH_CYTHON=1 pip3 install --user --ignore-installed .
# RUN pip3 install --user -rrequirements.txt
# RUN pip3 install --user "Cython==0.29.36"
# RUN env GRPC_PYTHON_BUILD_WITH_CYTHON=1 pip3 install --user --ignore-installed .
# # Build libyang
# FROM base-builder as libyang
# COPY ./libyang /libyang/
# RUN mkdir -p /libyang/build/
# WORKDIR /libyang/build/
# RUN cmake .. && \
# make DESTDIR=/output install
# # Build sysrepo
# FROM base-builder as sysrepo
# COPY --from=libyang /output/usr/local /usr/local/
# RUN ldconfig
# COPY ./sysrepo /sysrepo/
# RUN mkdir -p /sysrepo/build/
# WORKDIR /sysrepo/build/
# # CALL_TARGET_BINS_DIRECTLY=Off is needed here because of the use of DESTDIR
# # Without it sysrepoctl is executed at install time and assumes YANG files are
# # under /etc/sysrepo/yang
# RUN cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=Off -DCALL_TARGET_BINS_DIRECTLY=Off .. && \
# make DESTDIR=/output install
# # Construct the final image.
# FROM ubuntu:20.04
# LABEL maintainer="P4 Developers <p4-dev@lists.p4.org>"
# ARG DEBIAN_FRONTEND=noninteractive
# ARG MAKEFLAGS=-j2
# RUN CCACHE_RUNTIME_DEPS="libmemcached-dev" && \
# PTF_RUNTIME_DEPS="libpcap-dev python3-minimal tcpdump" && \
# NNPY_RUNTIME_DEPS="python3-minimal" && \
# THRIFT_RUNTIME_DEPS="libssl1.1 python3-minimal" && \
# GRPC_RUNTIME_DEPS="libssl-dev python3-minimal python3-setuptools" && \
# SYSREPO_RUNTIME_DEPS="libpcre3 libavl1 libev4 libprotobuf-c1" && \
# apt-get update && \
# apt-get install -y --no-install-recommends $CCACHE_RUNTIME_DEPS \
# $PTF_RUNTIME_DEPS \
# $NNPY_RUNTIME_DEPS \
# $THRIFT_RUNTIME_DEPS \
# $GRPC_RUNTIME_DEPS \
# $SYSREPO_RUNTIME_DEPS \
# python-is-python3 && \
# rm -rf /var/cache/apt/* /var/lib/apt/lists/*
# # Configure ccache so that descendant containers won't need to.
# COPY ./docker/ccache.conf /usr/local/etc/ccache.conf
# # Copy files from the build containers.
# COPY --from=ccache /output/usr/local /usr/local/
# COPY --from=ptf /output/usr/local /usr/local/
# COPY --from=nanomsg /output/usr/local /usr/local/
# COPY --from=nnpy /output/usr/local /usr/local/
# COPY --from=thrift /output/usr/local /usr/local/
# COPY --from=protobuf /output/usr/local /usr/local/
# COPY --from=grpc /output/usr/local /usr/local/
# COPY --from=libyang /output/usr/local /usr/local/
# COPY --from=sysrepo /output/usr/local /usr/local/
# COPY --from=sysrepo /output/etc /etc/
# # `pip install --user` will place things in `site-packages`, but Ubuntu expects
# # `dist-packages` by default, so we need to set configure `site-packages` as an
# # additional "site-specific directory".
# RUN export PYTHON3_VERSION=`python3 -c 'import sys; version=sys.version_info[:3]; print("python{0}.{1}".format(*version))'` && \
# echo "import site; site.addsitedir('/usr/local/lib/$PYTHON3_VERSION/site-packages')" \
# > /usr/local/lib/$PYTHON3_VERSION/dist-packages/use_site_packages.pth
# RUN ldconfig
# ===============================
# Base Builder (Ubuntu 24.04)
# ===============================
FROM ubuntu:24.04 AS base-builder
ARG MAKEFLAGS=-j2
ENV DEBIAN_FRONTEND=noninteractive
# Fixed: Added ENV prefix to these variables
ENV CFLAGS="-Os"
ENV CXXFLAGS="-Os"
ENV LDFLAGS="-Wl,-s"
ENV PYTHONUSERBASE=/output/usr/local
RUN apt-get update -qq && apt-get install -qq --no-install-recommends \
autoconf \
automake \
bison \
build-essential \
gcc-11 \
g++-11 \
ca-certificates \
cmake \
flex \
g++ \
libavl-dev \
libboost-dev \
libboost-test-dev \
libev-dev \
libevent-dev \
libffi-dev \
libmemcached-dev \
libpcap-dev \
libpcre3-dev \
libprotobuf-c-dev \
protobuf-c-compiler \
libprotobuf-dev \
protobuf-compiler \
libssl-dev \
libtool \
make \
pkg-config \
python3 \
python3-dev \
python3-pip \
python3-setuptools && \
ldconfig && \
mkdir -p /output/usr/local
ENV CC=gcc-11
ENV CXX=g++-11
# ===============================
# ccache
# ===============================
FROM base-builder AS ccache
ENV RUN_FROM_BUILD_FARM=yes
COPY ./ccache /ccache/
WORKDIR /ccache/
RUN ./autogen.sh && \
./configure --enable-memcached && \
make && \
touch ccache.1 && \
make DESTDIR=/output install
# ===============================
# PTF
# ===============================
FROM base-builder AS ptf
COPY ./ptf /ptf/
WORKDIR /ptf/
RUN python3 -m pip install pcapy-ng --break-system-packages && \
python3 -m pip install -r requirements.txt --break-system-packages && \
python3 -m pip install . --break-system-packages
# ===============================
# nanomsg
# ===============================
FROM base-builder AS nanomsg
COPY ./nanomsg /nanomsg/
RUN mkdir -p /nanomsg/build
WORKDIR /nanomsg/build
RUN cmake .. && make DESTDIR=/output install
# ===============================
# nnpy
# ===============================
FROM base-builder AS nnpy
COPY --from=nanomsg /output/usr/local /usr/local/
COPY ./nnpy /nnpy/
WORKDIR /nnpy/
RUN ldconfig && \
python3 -m pip install wheel cffi --break-system-packages && \
python3 -m pip install --no-build-isolation . --break-system-packages
# ===============================
# Thrift
# ===============================
FROM base-builder AS thrift
COPY ./thrift /thrift/
WORKDIR /thrift/
RUN ./bootstrap.sh && \
./configure \
--with-cpp=yes \
--with-python=yes \
--with-c_glib=no \
--with-java=no \
--with-ruby=no \
--with-erlang=no \
--with-go=no \
--with-nodejs=no \
--enable-tests=no && \
make && \
make DESTDIR=/output install-strip
WORKDIR /thrift/lib/py/
RUN python3 -m pip install . --break-system-packages
# ===============================
# gRPC
# ===============================
FROM base-builder AS grpc
COPY ./grpc /grpc/
RUN mkdir -p /grpc/cmake/build
WORKDIR /grpc/cmake/build
RUN cmake ../.. \
-DgRPC_INSTALL=ON \
-DCMAKE_BUILD_TYPE=Release \
-DgRPC_PROTOBUF_PROVIDER=module \
-DgRPC_SSL_PROVIDER=package \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_CXX_STANDARD_REQUIRED=ON && \
make -j$(nproc) DESTDIR=/output install
WORKDIR /grpc/
RUN python3 -m pip install grpcio --break-system-packages
# ===============================
# libyang
# ===============================
FROM base-builder AS libyang
COPY ./libyang /libyang/
RUN mkdir -p /libyang/build
WORKDIR /libyang/build
RUN cmake .. && make DESTDIR=/output install
# ===============================
# sysrepo
# ===============================
FROM base-builder AS sysrepo
COPY --from=libyang /output/usr/local /usr/local/
RUN ldconfig
COPY ./sysrepo /sysrepo/
RUN mkdir -p /sysrepo/build
WORKDIR /sysrepo/build
RUN cmake -DCMAKE_BUILD_TYPE=Release \
-DBUILD_EXAMPLES=Off \
-DCALL_TARGET_BINS_DIRECTLY=Off .. && \
make DESTDIR=/output install
# ===============================
# Final Runtime Image (Ubuntu 24.04)
# ===============================
FROM ubuntu:24.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
libmemcached-dev \
libpcap-dev \
python3-minimal \
tcpdump \
libssl-dev \
libpcre3 \
libavl1 \
libev4 \
libprotobuf-c1 \
python-is-python3 && \
rm -rf /var/lib/apt/lists/*
COPY ./docker/ccache.conf /usr/local/etc/ccache.conf
COPY --from=ccache /output/usr/local /usr/local/
COPY --from=ptf /output/usr/local /usr/local/
COPY --from=nanomsg /output/usr/local /usr/local/
COPY --from=nnpy /output/usr/local /usr/local/
COPY --from=thrift /output/usr/local /usr/local/
COPY --from=grpc /output/usr/local /usr/local/
COPY --from=libyang /output/usr/local /usr/local/
COPY --from=sysrepo /output/usr/local /usr/local/
COPY --from=sysrepo /output/etc /etc/
RUN ldconfig