Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Simplify kuksa-client docker build and reducing resulting image size
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schildt <[email protected]>
  • Loading branch information
SebastianSchildt committed Oct 6, 2023
1 parent f716273 commit bb34275
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions kuksa-client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,41 @@

# Note: This dockerfile needs to be executed one level above in the root folder

FROM python:3.10-alpine as build
RUN apk update && apk add git alpine-sdk linux-headers
RUN pip install --upgrade pip build

FROM python:3.10-slim-bookworm as build
# binutils is required by pyinstaller to strip any .so libs that are collected
# git is used to determine & embed version information during build time
RUN apt update && apt -yy install binutils git
RUN pip install --upgrade pip build pyinstaller

# We must copy the whole repository otherwise version lookup by tag would not work
COPY . /kuksa.val/
WORKDIR /kuksa.val/kuksa-client
RUN rm -rf dist

RUN python3 -m build
RUN mkdir /kuksa-client
RUN pip install --target /kuksa-client --no-cache-dir dist/*.whl
# We install globally on build container, so pyinstaller can easily gather all files
RUN pip install --no-cache-dir dist/*.whl

WORKDIR /
RUN rm -rf dist
# Letting pyinstaller collect everything that is required
RUN pyinstaller --collect-data kuksa_certificates --collect-data kuksa_client --clean -s /usr/local/bin/kuksa-client


# Debian 12 is bookworm, so the glibc version matches. Distroless is a lot smaller than
# Debian slim versions
# For development add :debug like this
# FROM gcr.io/distroless/base-debian12:debug to get a busybox shell as well
FROM gcr.io/distroless/base-debian12

FROM python:3.10-alpine
COPY --from=build /dist/kuksa-client /kuksa-client

# pyinstaller doesn't pick up transient libz dependency, so copying it manually
COPY --from=build /usr/lib/*-linux-gnu/libz.so.1 /lib/
# stty is required by cmd2
COPY --from=build /usr/bin/stty /bin/

RUN apk add --no-cache libstdc++
COPY --from=build /kuksa-client /kuksa-client
ENV PYTHONUNBUFFERED=yes
ENV GRPC_ENABLE_FORK_SUPPORT=false
ENV PYTHONPATH=/kuksa-client

WORKDIR /kuksa-client
ENTRYPOINT ["bin/kuksa-client"]
ENTRYPOINT ["/kuksa-client/kuksa-client"]

0 comments on commit bb34275

Please sign in to comment.