From 0c380d5912b092fa8e901cf2b3185fd01be6d7b5 Mon Sep 17 00:00:00 2001 From: Philipp Grathwohl Date: Thu, 2 Dec 2021 22:21:16 +0100 Subject: [PATCH 1/2] Avoid root when installing cbpi --- Dockerfile | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2e747ba..40a61ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ RUN apk --no-cache add curl && mkdir /downloads # Download installation files RUN curl https://github.com/avollkopf/craftbeerpi4-ui/archive/main.zip -L -o ./downloads/cbpi-ui.zip -FROM python:3.7 +FROM python:3.9 # Install dependencies RUN apt-get update \ @@ -14,28 +14,39 @@ RUN apt-get install --no-install-recommends -y \ python3-pip \ && rm -rf /var/lib/apt/lists/* -RUN python -m pip install --upgrade pip setuptools wheel +ENV VIRTUAL_ENV=/opt/venv -WORKDIR /cbpi # Create non-root user working directory RUN groupadd -g 1000 -r craftbeerpi \ && useradd -u 1000 -r -s /bin/false -g craftbeerpi craftbeerpi \ - && chown craftbeerpi:craftbeerpi /cbpi - -# Install craftbeerpi from source -COPY . /cbpi-src -RUN pip3 install --no-cache-dir /cbpi-src - -# Install craftbeerpi-ui -COPY --from=download /downloads /downloads -RUN pip3 install --no-cache-dir /downloads/cbpi-ui.zip - -# Clean up installation files -RUN rm -rf /downloads /cbpi-src + && mkdir /cbpi \ + && chown craftbeerpi:craftbeerpi /cbpi \ + && mkdir -p $VIRTUAL_ENV \ + && chown -R craftbeerpi:craftbeerpi ${VIRTUAL_ENV} USER craftbeerpi -RUN cbpi setup +# create virtual environment +RUN python3 -m venv $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" + +RUN python3 -m pip install --no-cache-dir --upgrade pip setuptools wheel + +# Install craftbeerpi from source +COPY --chown=craftbeerpi . /cbpi-src +RUN pip3 install --no-cache-dir /cbpi-src + +# Install craftbeerpi-ui +COPY --from=download --chown=craftbeerpi /downloads /downloads +RUN pip3 install --no-cache-dir /downloads/cbpi-ui.zip + +# Clean up installation files +USER root +RUN rm -rf /downloads /cbpi-src +USER craftbeerpi + +WORKDIR /cbpi +RUN ["cbpi", "setup"] EXPOSE 8000 From 623711e772073016c9f831af185e8052402f01c8 Mon Sep 17 00:00:00 2001 From: Philipp Grathwohl Date: Fri, 3 Dec 2021 00:35:45 +0100 Subject: [PATCH 2/2] Increase possible caching on docker file creation --- Dockerfile | 4 ++++ requirements.txt | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 40a61ac..639e820 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,6 +32,10 @@ ENV PATH="$VIRTUAL_ENV/bin:$PATH" RUN python3 -m pip install --no-cache-dir --upgrade pip setuptools wheel +# Install craftbeerpi requirements for better caching +COPY --chown=craftbeerpi ./requirements.txt /cbpi-src/ +RUN pip3 install --no-cache-dir -r /cbpi-src/requirements.txt + # Install craftbeerpi from source COPY --chown=craftbeerpi . /cbpi-src RUN pip3 install --no-cache-dir /cbpi-src diff --git a/requirements.txt b/requirements.txt index 739db3a..28e5433 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,6 +13,10 @@ pyfiglet==0.8.post1 pandas==1.1.5 shortuuid==1.0.1 tabulate==0.8.7 +numpy==1.20.3 cbpi4ui -click -asyncio-mqtt \ No newline at end of file +click==7.1.2 +importlib_metadata==4.8.2 +asyncio-mqtt +psutil==5.8.0 +zipp>=0.5 \ No newline at end of file