-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.cli
More file actions
193 lines (170 loc) · 5.83 KB
/
Dockerfile.cli
File metadata and controls
193 lines (170 loc) · 5.83 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
# syntax=docker/dockerfile:1
# Control plane CLI tools for EJFAT (Optimized)
#
# This is a multi-stage build optimized for smaller final image size:
# - base-runtime: Minimal dependencies for running the application
# - base-build: Adds build tools (example for compiling from source)
# - compile: Builds the application
# - deploy: Final slim image
# - deploy-debug: Optional variant with network debugging tools
#
# Build commands:
# Production: docker build --target deploy -t e2sar-utils:slim -f Dockerfile.opt .
# Debug: docker build --target deploy-debug -t e2sar-utils:debug -f Dockerfile.opt .
# Build stage: docker build --target compile -t e2sar-utils:build -f Dockerfile.opt .
#
# Stage 'base-runtime': Minimal runtime dependencies
#
FROM ubuntu:24.04 AS base-runtime
ENV DISTRO=ubuntu24
ENV HOME=/home/ubuntu
ENV LD_LIBRARY_PATH=/usr/local/lib
ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
ENV PATH=/usr/local/bin:$PATH
ENV E2SARINSTALL=/e2sar-install
ENV E2SAR_VER=0.3.1
ENV E2SAR_DEB=E2SAR-${E2SAR_VER}-main-ubuntu-24.04/e2sar_${E2SAR_VER}_amd64.deb
ENV E2SAR_DEB_URL=https://github.com/JeffersonLab/E2SAR/releases/download/${E2SAR_DEB}
ENV ROOT_INSTALL=/rootlib
ENV ROOT_VER=6.36.06
ENV ROOT_TAR=root_v${ROOT_VER}.Linux-ubuntu24.04-x86_64-gcc13.3.tar.gz
ENV ROOT_URL=https://root.cern/download/${ROOT_TAR}
RUN mkdir ${E2SARINSTALL} && mkdir ${ROOT_INSTALL}
# Runtime dependencies only (libraries needed by ROOT and E2SAR at runtime)
RUN apt-get -yq update && \
apt-get -yq install --no-install-recommends \
ca-certificates \
openssl \
libre2-dev \
libtbb12 \
libvdt0.4 \
libgif7 \
libx11-6 \
libxext6 \
libxft2 \
libxpm4 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Install E2SAR from pre-built .deb package
RUN apt-get -yq update && \
apt-get -yq install --no-install-recommends wget && \
wget -q -O e2sar.deb ${E2SAR_DEB_URL} && \
dpkg -i ./e2sar.deb && \
rm e2sar.deb && \
apt-get -yq purge wget && \
apt-get -yq autoremove && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Install ROOT (pre-built binary distribution)
RUN apt-get -yq update && \
apt-get -yq install --no-install-recommends wget && \
wget -q -O root.tar.gz ${ROOT_URL} && \
tar -zxf root.tar.gz -C ${ROOT_INSTALL} && \
rm root.tar.gz && \
apt-get -yq purge wget && \
apt-get -yq autoremove && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
#
# Stage 'base-build': Adds build tools for compilation
#
# This stage demonstrates all dependencies needed to compile the code from source.
# It extends base-runtime with build-time dependencies.
#
FROM base-runtime AS base-build
# Build system and compilation dependencies
# - build-essential: gcc, g++, make, etc.
# - meson/ninja: Build system used by this project
# - cmake: Required by some dependencies
# - pkg-config: For finding installed libraries
# - protobuf-compiler: For E2SAR gRPC communication
# - gdb: Debugger (optional, useful during development)
RUN apt-get -yq update && \
apt-get -yq install \
python3-pip \
build-essential \
autoconf \
cmake \
libtool \
pkg-config \
libglib2.0-dev \
ninja-build \
libssl-dev \
libsystemd-dev \
protobuf-compiler \
gdb \
wget && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Python build tools
# - meson: Build system
# - pybind11: Python bindings (if needed)
RUN pip3 install --break-system-packages pybind11 meson
#
# Stage 'compile': Build the application from source
#
FROM base-build AS compile
ENV SRC_DIR=/src
WORKDIR $SRC_DIR
# Copy source code
COPY . /src/
# Configure and build
# 1. Source ROOT environment (thisroot.sh sets up ROOT paths)
# 2. Run meson setup to configure the build
# 3. Fix C++ standard flag conflict (ROOT uses newer standard)
# 4. Compile with meson
# 5. Install to E2SARINSTALL prefix
RUN bash -c 'cd ${ROOT_INSTALL}/root/bin && \
. ./thisroot.sh && \
cd ${SRC_DIR} && \
PATH=$HOME/.local/bin:/usr/local/bin:$PATH \
BOOST_ROOT=/usr/local/ \
LD_LIBRARY_PATH=${LD_LIBRARY_PATH} \
meson setup -Dpkg_config_path=${PKG_CONFIG_PATH} --prefix ${E2SARINSTALL} build && \
sed -i 's/-std=c++11//g' build/build.ninja && \
meson compile -C build -j 2 && \
meson install -C build'
#
# Stage 'deploy': Final slim production image
#
# This stage contains only what's needed to run the application:
# - Runtime libraries (from base-runtime)
# - Compiled application binaries
#
FROM base-runtime AS deploy
WORKDIR ${E2SARINSTALL}
ENV PATH=${E2SARINSTALL}/bin:$PATH
ENV LD_LIBRARY_PATH=${E2SARINSTALL}/lib/x86_64-linux-gnu/:$LD_LIBRARY_PATH
# ROOT's cling interpreter needs C++ standard library headers at runtime
# Install them here (not in base-runtime to avoid conflicts with base-build)
RUN apt-get -yq update && \
apt-get -yq install --no-install-recommends \
libstdc++-13-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Copy only the compiled application from the compile stage
COPY --from=compile $E2SARINSTALL $E2SARINSTALL
CMD ["e2sar-root"]
#
# Stage 'deploy-debug': Optional debug variant with network tools
#
# Use this image when you need to debug network issues or inspect traffic.
# Build with: docker build --target deploy-debug -t e2sar-utils:debug -f Dockerfile.opt .
#
FROM deploy AS deploy-debug
ENV LD_LIBRARY_PATH=${E2SARINSTALL}/lib/x86_64-linux-gnu/:$LD_LIBRARY_PATH
RUN apt-get -yq update && \
apt-get -yq install --no-install-recommends \
netcat-traditional \
net-tools \
bc \
ethtool \
iproute2 \
iputils-ping \
nano \
tcpdump \
python3-pip && \
pip3 install --break-system-packages scapy && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
CMD ["e2sar-root"]