Skip to content

Commit 95c2181

Browse files
authored
[TimeSeries]: Enabled Multistage build (open-edge-platform#846)
enables multistage Docker builds for the Time Series Analytics microservice and updates string formatting to use parameterized logging throughout the codebase. The changes improve build efficiency, security, and logging consistency while adding Intel GPU support. Key changes include: Converting Docker build to use multistage approach with separate builder and runtime stages Updating all string formatting in logging statements to use parameterized format strings with %s placeholders Adding Intel GPU tools and drivers to the Docker image Signed-off-by: Vellaisamy, Sathyendran <sathyendran.vellaisamy@intel.com>
1 parent b2cefa2 commit 95c2181

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

microservices/time-series-analytics/Dockerfile

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,32 @@
66

77
# Use the Kapacitor image as the base image
88
ARG KAPACITOR_VERSION
9-
FROM kapacitor:$KAPACITOR_VERSION
9+
FROM kapacitor:$KAPACITOR_VERSION as builder
1010

1111
# Install Python and necessary packages in a single layer, minimize image size
1212
RUN apt-get update && \
13-
apt-get install -y --no-install-recommends \
14-
python3 python3-pip git ca-certificates intel-gpu-tools && \
15-
python3 -m pip install --no-cache-dir --upgrade pip && \
16-
apt-get purge -y --auto-remove && \
17-
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /root/.cache/pip
18-
19-
WORKDIR /app
13+
apt-get install -y --no-install-recommends git
2014

2115
# Clone only the required files to reduce image size
2216
RUN git clone --depth 1 --filter=blob:none --sparse --branch v${KAPACITOR_VERSION} \
2317
https://github.com/influxdata/kapacitor.git /tmp/kapacitor && \
2418
cd /tmp/kapacitor && \
25-
git sparse-checkout set udf/agent/py && \
26-
mv /tmp/kapacitor/udf/agent/py /app/kapacitor_python && \
27-
rm -rf /tmp/kapacitor
19+
git sparse-checkout set udf/agent/py
2820

29-
# Install Intel GPU tools and clean up
30-
RUN apt-get update && apt-get install -y --no-install-recommends intel-gpu-tools
21+
FROM kapacitor:$KAPACITOR_VERSION as runtime
22+
23+
WORKDIR /app
3124

25+
RUN apt-get update && \
26+
apt-get install -y --no-install-recommends \
27+
python3 python3-pip intel-gpu-tools && \
28+
apt-get purge -y --auto-remove && \
29+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /root/.cache/pip
30+
31+
# Copy kapacitor Python UDF agent files from builder image
32+
COPY --from=builder /tmp/kapacitor/udf/agent/py /app/kapacitor_python
33+
34+
# Install Intel GPU tools and clean up
3235
RUN export no_proxy= && \
3336
apt-get update && \
3437
. /etc/os-release && \
@@ -46,7 +49,7 @@ RUN export no_proxy= && \
4649
libgbm1=\* libigdgmm12=\* libxatracker2=\* libdrm-amdgpu1=\* \
4750
va-driver-all=\* vainfo=\* hwinfo=\* clinfo=\* && \
4851
apt-get clean && \
49-
rm -rf /var/lib/apt/lists/*
52+
rm -rf /var/lib/apt/lists/*
5053

5154
ARG TIMESERIES_UID
5255
ARG TIMESERIES_USER_NAME
@@ -110,13 +113,13 @@ RUN if [ "$COPYLEFT_SOURCES" = "true" ]; then \
110113

111114
WORKDIR /app
112115
# Remove git and clean up to reduce image size
113-
RUN apt-get purge -y --auto-remove git && \
114-
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /root/.cache/pip
116+
RUN apt-get purge -y --auto-remove && \
117+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /root/.cache/pip /timeseries_user/.cache/pip
115118

116119
# Switch to non-root user for security
117120
USER $TIMESERIES_USER_NAME
118121

119122
# Simple healthcheck to verify container is running
120123
HEALTHCHECK --interval=5m CMD exit 0
121124

122-
ENTRYPOINT ["python3", "main.py"]
125+
ENTRYPOINT ["python3", "main.py"]

0 commit comments

Comments
 (0)