Skip to content
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

Move to multi-stage Dockerfile #4

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
FROM python:3.9
FROM ubuntu:jammy AS python-builder

RUN apt-get update && \
apt-get install -y python3 python3-venv && \
rm -rf /var/lib/apt/lists/*

RUN python3 -m venv /venv && \
/venv/bin/pip install -U pip setuptools

COPY requirements.txt /app/requirements.txt
RUN /venv/bin/pip install --no-deps --requirement /app/requirements.txt

COPY . /app
RUN /venv/bin/pip install --no-deps /app


FROM ubuntu:jammy

# Don't buffer stdout and stderr as it breaks realtime logging
ENV PYTHONUNBUFFERED 1

# Create the user that will be used to run the app
ENV APP_UID 1001
Expand All @@ -14,24 +33,12 @@ RUN groupadd --gid $APP_GID $APP_GROUP && \
--uid $APP_UID \
$APP_USER

# Install tini, which we will use to marshal the processes
RUN apt-get update && \
apt-get install -y tini && \
apt-get install -y ca-certificates python3 tini && \
rm -rf /var/lib/apt/lists/*

# Don't buffer stdout and stderr as it breaks realtime logging
ENV PYTHONUNBUFFERED 1

# Install dependencies
# Doing this separately by copying only the requirements file enables better use of the build cache
COPY ./requirements.txt /application/
RUN pip install --no-deps --requirement /application/requirements.txt

# Install the application
COPY . /application
RUN pip install --no-deps -e /application
COPY --from=python-builder /venv /venv

# By default, run the operator using kopf
USER $APP_UID
ENTRYPOINT ["tini", "-g", "--"]
CMD ["kopf", "run", "--module", "capi_janitor.openstack.operator", "--all-namespaces"]
CMD ["/venv/bin/kopf", "run", "--module", "capi_janitor.openstack.operator", "--all-namespaces"]
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ attrs==23.1.0
certifi==2023.7.22
charset-normalizer==3.2.0
click==8.1.6
easykube @ git+https://github.com/stackhpc/easykube.git@28208e4d07fab1eb74a21b05de102142fb1fc4ad
easykube==0.1.1
exceptiongroup==1.1.2
frozenlist==1.4.0
h11==0.14.0
Expand Down