Skip to content

Commit d680396

Browse files
committed
[load-generator/recommendation]: replace alpine base image with distroless image
Signed-off-by: Gerard Vanloo <gerard.vanloo@ibm.com>
1 parent 7da73bc commit d680396

File tree

3 files changed

+39
-35
lines changed

3 files changed

+39
-35
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ the release.
1111
([#2148](https://github.com/open-telemetry/opentelemetry-demo/pull/2148))
1212
* [product-catalog] Simplify span event name
1313
([#2150](https://github.com/open-telemetry/opentelemetry-demo/pull/2150))
14+
* [load-generator] change image from alpine to distroless to reduce size
15+
([#2164](https://github.com/open-telemetry/opentelemetry-demo/pull/2164))
16+
* [recommendation] change image from alpine to distroless to reduce size
17+
([#2164](https://github.com/open-telemetry/opentelemetry-demo/pull/2164))
1418

1519
## 2.0.2
1620

src/load-generator/Dockerfile

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
33

4+
FROM python:3.12-slim-bookworm AS build-venv
45

5-
FROM python:3.12-slim-bookworm AS base
6+
ENV PLAYWRIGHT_BROWSERS_PATH=/opt/playwright
67

7-
FROM base AS builder
8-
RUN apt-get -qq update \
9-
&& apt-get install -y --no-install-recommends g++ \
10-
&& rm -rf /var/lib/apt/lists/*
8+
COPY ./src/load-generator/requirements.txt requirements.txt
119

12-
COPY ./src/load-generator/requirements.txt .
13-
RUN pip install --prefix="/reqs" -r requirements.txt
10+
RUN python -m venv venv
11+
RUN venv/bin/pip install --no-cache-dir -r requirements.txt
12+
13+
RUN venv/bin/playwright install --with-deps chromium
14+
15+
FROM gcr.io/distroless/python3-debian12:nonroot
1416

15-
FROM base
16-
WORKDIR /usr/src/app/
17-
COPY --from=builder /reqs /usr/local
1817
ENV PLAYWRIGHT_BROWSERS_PATH=/opt/pw-browsers
19-
RUN playwright install --with-deps chromium
20-
COPY ./src/load-generator/locustfile.py .
21-
COPY ./src/load-generator/people.json .
22-
ENTRYPOINT ["locust", "--skip-log-setup"]
18+
19+
COPY --from=build-venv /venv/ /venv/
20+
COPY --from=build-venv /opt/playwright/ /opt/pw-browsers/
21+
22+
WORKDIR /app
23+
24+
COPY ./src/load-generator/locustfile.py locustfile.py
25+
COPY ./src/load-generator/people.json people.json
26+
27+
ENTRYPOINT ["/venv/bin/locust", "--skip-log-setup"]

src/recommendation/Dockerfile

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

44

5-
FROM python:3.12-slim-bookworm AS base
5+
FROM python:3.12-slim-bookworm 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+
COPY ./src/recommendation/requirements.txt requirements.txt
148

15-
WORKDIR /usr/src/app/
16-
COPY ./src/recommendation/requirements.txt ./
9+
RUN python -m venv venv
10+
RUN venv/bin/pip install --no-cache-dir -r requirements.txt
1711

18-
RUN pip install --upgrade pip
19-
RUN pip install --prefix="/reqs" -r requirements.txt
12+
RUN venv/bin/opentelemetry-bootstrap -a install
2013

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/ ./
14+
FROM gcr.io/distroless/python3-debian12:nonroot
2815

29-
RUN opentelemetry-bootstrap -a install
16+
COPY --from=build-venv /venv/ /venv/
17+
18+
WORKDIR /app
19+
20+
COPY ./src/recommendation/demo_pb2_grpc.py demo_pb2_grpc.py
21+
COPY ./src/recommendation/demo_pb2.py demo_pb2.py
22+
COPY ./src/recommendation/logger.py logger.py
23+
COPY ./src/recommendation/metrics.py metrics.py
24+
COPY ./src/recommendation/recommendation_server.py recommendation_server.py
3025

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

0 commit comments

Comments
 (0)