From f79d30ab5490a5437e2d15f42e7246e94af621f5 Mon Sep 17 00:00:00 2001 From: simon Date: Sun, 10 Apr 2022 22:43:00 +0700 Subject: [PATCH] multi stage build Dockerfile for python wheel --- Dockerfile | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7b4f44a..56c6da4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,17 @@ -# build the tube archivist image from default python slim image +# multi stage to build tube archivist +# first stage to build python wheel, copy into final image -FROM python:3.10.4-slim-bullseye + +# First stage to build python wheel +FROM python:3.10.4-slim-bullseye AS builder ARG TARGETPLATFORM -ARG INSTALL_DEBUG -ENV PYTHONUNBUFFERED 1 +RUN apt-get update +RUN apt-get install -y --no-install-recommends build-essential gcc curl -# install distro packages needed -RUN apt-get clean && apt-get -y update && apt-get -y install --no-install-recommends \ - build-essential \ - nginx \ - atomicparsley \ - curl && rm -rf /var/lib/apt/lists/* +# install requirements +COPY ./tubearchivist/requirements.txt /requirements.txt +RUN pip install --user -r requirements.txt # get newest patched ffmpeg and ffprobe builds for amd64 fall back to repo ffmpeg for arm64 RUN if [ "$TARGETPLATFORM" = "linux/amd64" ] ; then \ @@ -27,11 +27,31 @@ RUN if [ "$TARGETPLATFORM" = "linux/amd64" ] ; then \ apt-get -y update && apt-get -y install --no-install-recommends ffmpeg && rm -rf /var/lib/apt/lists/* \ ; fi +# build final image +FROM python:3.10.4-slim-bullseye as tubearchivist + +ARG TARGETPLATFORM +ARG INSTALL_DEBUG + +ENV PYTHONUNBUFFERED 1 + +# copy build requirements +COPY --from=builder /root/.local /root/.local +COPY --from=builder /usr/bin/ffmpeg /usr/bin/ffmpeg +COPY --from=builder /usr/bin/ffprobe /usr/bin/ffprobe +ENV PATH=/root/.local/bin:$PATH + +# install distro packages needed +RUN apt-get clean && apt-get -y update && apt-get -y install --no-install-recommends \ + nginx \ + atomicparsley \ + curl && rm -rf /var/lib/apt/lists/* + # install debug tools for testing environment RUN if [ "$INSTALL_DEBUG" ] ; then \ apt-get -y update && apt-get -y install --no-install-recommends \ vim htop bmon net-tools iputils-ping procps \ - && pip install --no-cache-dir ipython --src /usr/local/src \ + && pip install --user ipython \ ; fi # make folders @@ -39,12 +59,6 @@ RUN mkdir /cache RUN mkdir /youtube RUN mkdir /app -# install python dependencies -COPY ./tubearchivist/requirements.txt /requirements.txt -RUN pip install --upgrade pip && \ - pip install --upgrade setuptools && \ - pip install --no-cache-dir -r requirements.txt --src /usr/local/src - # copy config files COPY docker_assets/nginx.conf /etc/nginx/sites-available/default