Skip to content

Commit

Permalink
feat(framework:ci) add alpine base image
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Steiner <robert@flower.ai>
  • Loading branch information
Robert-Steiner committed May 15, 2024
1 parent a62df57 commit b038769
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
python-version: ["3.8", "3.9", "3.10", "3.11"]
with:
namespace-repository: flwr/base
file-dir: src/docker/base
file-dir: src/docker/base/ubuntu
build-args: |
PYTHON_VERSION=${{ matrix.python-version }}
PIP_VERSION=${{ needs.parameters.outputs.pip-version }}
Expand Down
2 changes: 1 addition & 1 deletion doc/source/contributor-how-to-build-docker-images.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The following example creates a base image with Python 3.11.0, pip 23.0.1 and se

.. code-block:: bash
$ cd src/docker/base/
$ cd src/docker/base/ubuntu
$ docker build \
--build-arg PYTHON_VERSION=3.11.0 \
--build-arg PIP_VERSION=23.0.1 \
Expand Down
71 changes: 71 additions & 0 deletions src/docker/base/alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2024 Flower Labs GmbH. All Rights Reserved.

# Multi-stage base build
#
# Building the base image for ARM64 requires installing some additional system dependencies to
# compile the grpcio package, as they do not provide a pre-built package. However, we don't want
# the dependencies in the final base image as they are only needed to compile the package.
# That's why we're creating a multi-stage build. When installing the flwr, we are using a
# virtual environment to keep all files in a single isolated directory as described here:
# https://pythonspeed.com/articles/multi-stage-docker-python/

ARG PYTHON_VERSION=3.11
ARG ALPINE_VERSION=alpine3.19
FROM python:${PYTHON_VERSION}-${ALPINE_VERSION} as compile

# Install system dependencies
RUN apk add --no-cache \
# require for compiling grpcio on ARM64
g++=13.2.1_git20231014-r0 \
libffi-dev=3.4.4-r3 \
# create virtual env
&& python -m venv /opt/venv

# Make sure we use the virtualenv
ENV PATH="/opt/venv/bin:$PATH"

# Install specific version of pip, setuptools and flwr
ARG PIP_VERSION
ARG SETUPTOOLS_VERSION
ARG FLWR_PACKAGE=flwr
ARG FLWR_VERSION
RUN pip install -U --no-cache-dir \
pip==${PIP_VERSION} \
setuptools==${SETUPTOOLS_VERSION} \
${FLWR_PACKAGE}==${FLWR_VERSION}

FROM python:${PYTHON_VERSION}-${ALPINE_VERSION} as base

# required by the grpc package
RUN apk add --no-cache \
libstdc++=13.2.1_git20231014-r0

COPY --from=compile /opt/venv /opt/venv

# Make sure we use the virtualenv:
ENV PATH="/opt/venv/bin:$PATH"

# Send stdout and stderr stream directly to the terminal. Ensures that no
# output is retained in a buffer if the application crashes.
ENV PYTHONUNBUFFERED=1 \
# Typically, bytecode is created on the first invocation to speed up following invocation.
# However, in Docker we only make a single invocation (when we start the container).
# Therefore, we can disable bytecode writing.
PYTHONDONTWRITEBYTECODE=1 \
# Ensure that python encoding is always UTF-8.
PYTHONIOENCODING=UTF-8 \
LANG=C.UTF-8 \
LC_ALL=C.UTF-8

# add non-root user
RUN adduser \
--no-create-home \
--disabled-password \
--gecos "" \
--uid 49999 app \
&& mkdir -p /app \
&& chown -R app:app /app

WORKDIR /app
USER app
ENV HOME=/app
File renamed without changes.

0 comments on commit b038769

Please sign in to comment.