Skip to content

Commit 8a80712

Browse files
authored
[recommendation]: switch from distroless to alpine image (open-telemetry#2164)
Signed-off-by: Gerard Vanloo <gerard.vanloo@ibm.com>
1 parent 209a748 commit 8a80712

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ the release.
2121
([#2161](https://github.com/open-telemetry/opentelemetry-demo/pull/2161))
2222
* [chore] bump dependent images
2323
([#2179](https://github.com/open-telemetry/opentelemetry-demo/pull/2179))
24+
* [recommendation] change image from bookworm to alpine to reduce size
25+
([#2164](https://github.com/open-telemetry/opentelemetry-demo/pull/2164))
2426

2527
## 2.0.2
2628

src/recommendation/Dockerfile

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,29 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44

5-
FROM python:3.12-slim-bookworm AS base
5+
FROM python:3.12-alpine3.21 AS build-venv
66

7-
#
8-
# Fetch requirements
9-
#
10-
FROM base AS builder
11-
RUN apt-get -qq update \
12-
&& apt-get install -y --no-install-recommends g++ \
13-
&& rm -rf /var/lib/apt/lists/*
7+
RUN apk update && \
8+
apk add gcc g++ linux-headers
149

15-
WORKDIR /usr/src/app/
16-
COPY ./src/recommendation/requirements.txt ./
10+
COPY ./src/recommendation/requirements.txt requirements.txt
1711

18-
RUN pip install --upgrade pip
19-
RUN pip install --prefix="/reqs" -r requirements.txt
12+
RUN python -m venv venv && \
13+
venv/bin/pip install --no-cache-dir -r requirements.txt
2014

21-
#
22-
# Runtime
23-
#
24-
FROM base AS runtime
25-
WORKDIR /usr/src/app/
26-
COPY --from=builder /reqs /usr/local
27-
COPY ./src/recommendation/ ./
15+
RUN venv/bin/opentelemetry-bootstrap -a install
2816

29-
RUN opentelemetry-bootstrap -a install
17+
FROM python:3.12-alpine3.21
18+
19+
COPY --from=build-venv /venv/ /venv/
20+
21+
WORKDIR /app
22+
23+
COPY ./src/recommendation/demo_pb2_grpc.py demo_pb2_grpc.py
24+
COPY ./src/recommendation/demo_pb2.py demo_pb2.py
25+
COPY ./src/recommendation/logger.py logger.py
26+
COPY ./src/recommendation/metrics.py metrics.py
27+
COPY ./src/recommendation/recommendation_server.py recommendation_server.py
3028

3129
EXPOSE ${RECOMMENDATION_PORT}
32-
ENTRYPOINT [ "opentelemetry-instrument", "python", "recommendation_server.py" ]
30+
ENTRYPOINT [ "/venv/bin/opentelemetry-instrument", "/venv/bin/python", "recommendation_server.py" ]

src/recommendation/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
grpcio-health-checking==1.70.0
2-
grpcio==1.70.0
1+
grpcio-health-checking==1.71.0
2+
grpcio==1.71.0
33
opentelemetry-distro==0.51b0
44
opentelemetry-exporter-otlp-proto-grpc==1.30.0
55
python-dotenv==1.0.1

0 commit comments

Comments
 (0)