-
Notifications
You must be signed in to change notification settings - Fork 40
Feature/SK-1519 | FEDn container uses distroless image #868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stefanhellander
wants to merge
7
commits into
master
Choose a base branch
from
feature/SK-1519
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e5a8087
FEDn container uses distroless image
stefanhellander 405afbe
Set number of gunicorn workers in config
stefanhellander f78d571
Added back grpc_health_probe, set correct builder image version
stefanhellander e2e67fd
Fixes
stefanhellander a081222
python slim image for clients
stefanhellander 31720a6
Force base img to 3.11
stefanhellander cb3dc4a
...
stefanhellander File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,4 +11,5 @@ examples/* | |
| **/*.npz | ||
| **/data | ||
| **/*.tgz | ||
| dist | ||
| dist | ||
| Dockerfile | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,77 +1,24 @@ | ||
| # Stage 1: Builder | ||
| ARG BASE_IMG=python:3.12-slim | ||
| FROM $BASE_IMG AS builder | ||
| FROM python:3.11-slim AS builder | ||
|
|
||
| ARG GRPC_HEALTH_PROBE_VERSION="" | ||
| ARG REQUIREMENTS="" | ||
|
|
||
| WORKDIR /build | ||
|
|
||
| # Temporarily add the Debian Testing repository to install zlib1g 1:1.3.dfsg+really1.3.1-1+b1 (fixed CVE-2023-45853) | ||
| # Both zlib1g and zlib1g-dev are installed in the builder stage. | ||
| RUN echo "deb http://deb.debian.org/debian testing main" > /etc/apt/sources.list.d/testing.list \ | ||
| && apt-get update \ | ||
| && apt-get install -y --no-install-recommends -t testing zlib1g=1:1.3.dfsg+really1.3.1-1+b1 zlib1g-dev=1:1.3.dfsg+really1.3.1-1+b1 \ | ||
| && rm -rf /etc/apt/sources.list.d/testing.list \ | ||
| && apt-get clean \ | ||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| python3-dev gcc wget zlib1g-dev \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Install build dependencies | ||
| RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends python3-dev gcc wget \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Add FEDn and default configs | ||
| COPY . /build | ||
| COPY $REQUIREMENTS /build/requirements.txt | ||
|
|
||
| # Install dependencies | ||
| RUN python -m venv /venv \ | ||
| && /venv/bin/pip install --upgrade pip \ | ||
| && /venv/bin/pip install --no-cache-dir 'setuptools>=65' \ | ||
| && /venv/bin/pip install --no-cache-dir . \ | ||
| && if [[ ! -z "$REQUIREMENTS" ]]; then \ | ||
| /venv/bin/pip install --no-cache-dir -r /build/requirements.txt; \ | ||
| fi \ | ||
| && rm -rf /build/requirements.txt | ||
|
|
||
|
|
||
| # Install grpc health probe | ||
| RUN if [ ! -z "$GRPC_HEALTH_PROBE_VERSION" ]; then \ | ||
| wget -qO /build/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \ | ||
| chmod +x /build/grpc_health_probe; \ | ||
| fi | ||
| RUN mkdir /python-dist \ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where is fedn installed?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RUN mkdir /python-dist |
||
| && pip install --upgrade pip \ | ||
| && pip install --prefix=/python-dist --no-cache-dir 'setuptools>=65' . | ||
|
|
||
| # Stage 2: Runtime | ||
| FROM $BASE_IMG | ||
| # Stage 2: Distroless Runtime | ||
| FROM gcr.io/distroless/python3 | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy application and venv from the builder stage | ||
| COPY --from=builder /venv /venv | ||
| COPY --from=builder /build /app | ||
|
|
||
| # Use a non-root user | ||
| RUN set -ex \ | ||
| # Create a non-root user | ||
| && addgroup --system --gid 1001 appgroup \ | ||
| && adduser --system --uid 1001 --gid 1001 --no-create-home appuser \ | ||
| # Creare application specific tmp directory, set ENV TMPDIR to /app/tmp | ||
| && mkdir -p /app/tmp \ | ||
| && chown -R appuser:appgroup /venv /app \ | ||
| # Temporarily add the Debian Testing repository to install zlib1g 1:1.3.dfsg+really1.3.1-1+b1 (fixed CVE-2023-45853) | ||
| && echo "deb http://deb.debian.org/debian testing main" > /etc/apt/sources.list.d/testing.list \ | ||
| && apt-get update \ | ||
| && apt-get install -y --no-install-recommends -t testing zlib1g=1:1.3.dfsg+really1.3.1-1+b1 \ | ||
| && rm -rf /etc/apt/sources.list.d/testing.list \ | ||
| # Update package index and upgrade all installed packages | ||
| && apt-get update \ | ||
| && apt-get upgrade -y \ | ||
| # Clean up | ||
| && apt-get autoremove -y \ | ||
| && apt-get clean -y \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
| COPY --from=builder /python-dist /python-dist | ||
|
|
||
| USER appuser | ||
| ENV PYTHONPATH=/python-dist/lib/python3.11/site-packages | ||
|
|
||
| ENTRYPOINT [ "/venv/bin/fedn" ] | ||
| ENTRYPOINT ["python3", "/python-dist/bin/fedn"] | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why downgrade python?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The distroless image seems to be 3.11