Skip to content

Commit

Permalink
Splitting the dockerfiles into multi-stage builds.
Browse files Browse the repository at this point in the history
Previously if you edited `main.py` and rebuilt the image, you'd
redownload all the python deps again, needlessly.

Now you can change main.py without triggering a needless `pip install`.
It's a much snappier development experience.
  • Loading branch information
krisajenkins committed Apr 24, 2024
1 parent f8aa891 commit db2fb44
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
20 changes: 17 additions & 3 deletions console logger/dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
FROM python:3.11.1-slim-buster
# Dependency-building stage.
FROM python:3.11.1-slim-buster AS build

ENV DEBIAN_FRONTEND="noninteractive"
ENV PYTHONUNBUFFERED=1
ENV PYTHONIOENCODING=UTF-8

WORKDIR /app
RUN python3 -m venv env
ENV PATH="env/bin:$PATH"

COPY requirements.txt .
RUN python3 -m pip install -r requirements.txt

# Runtime stage.
FROM python:3.11.1-slim-buster AS runtime

WORKDIR /app
COPY --from=build /app/env /app/env
ENV PATH="env/bin:$PATH"

COPY . .
RUN find | grep requirements.txt | xargs -I '{}' python3 -m pip install -r '{}' --extra-index-url https://pkgs.dev.azure.com/quix-analytics/53f7fe95-59fe-4307-b479-2473b96de6d1/_packaging/public/pypi/simple/
ENTRYPOINT ["python3", "main.py"]

ENTRYPOINT ["env/bin/python3", "main.py"]
20 changes: 17 additions & 3 deletions csv data source/dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
FROM python:3.11.1-slim-buster
# Dependency-building stage.
FROM python:3.11.1-slim-buster AS build

ENV DEBIAN_FRONTEND="noninteractive"
ENV PYTHONUNBUFFERED=1
ENV PYTHONIOENCODING=UTF-8

WORKDIR /app
RUN python3 -m venv env
ENV PATH="env/bin:$PATH"

COPY requirements.txt .
RUN python3 -m pip install -r requirements.txt

# Runtime stage.
FROM python:3.11.1-slim-buster AS runtime

WORKDIR /app
COPY --from=build /app/env /app/env
ENV PATH="env/bin:$PATH"

COPY . .
RUN find | grep requirements.txt | xargs -I '{}' python3 -m pip install -r '{}' --extra-index-url https://pkgs.dev.azure.com/quix-analytics/53f7fe95-59fe-4307-b479-2473b96de6d1/_packaging/public/pypi/simple/
ENTRYPOINT ["python3", "main.py"]

ENTRYPOINT ["env/bin/python3", "main.py"]
21 changes: 18 additions & 3 deletions name counter/dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
FROM python:3.11.1-slim-buster
# Dependency-building stage.
FROM python:3.11.1-slim-buster AS build

ENV DEBIAN_FRONTEND="noninteractive"
ENV PYTHONUNBUFFERED=1
ENV PYTHONIOENCODING=UTF-8

WORKDIR /app
RUN python3 -m venv env
ENV PATH="env/bin:$PATH"

COPY requirements.txt .
RUN python3 -m pip install -r requirements.txt


# Runtime stage.
FROM python:3.11.1-slim-buster AS runtime

WORKDIR /app
COPY --from=build /app/env /app/env
ENV PATH="env/bin:$PATH"

COPY . .
RUN find | grep requirements.txt | xargs -I '{}' python3 -m pip install -r '{}' --extra-index-url https://pkgs.dev.azure.com/quix-analytics/53f7fe95-59fe-4307-b479-2473b96de6d1/_packaging/public/pypi/simple/
ENTRYPOINT ["python3", "main.py"]

ENTRYPOINT ["env/bin/python3", "main.py"]

0 comments on commit db2fb44

Please sign in to comment.