From: Code-Otto Date: Tue, 26 Mar 2024 19:48:58 +0000 (+0100) Subject: Docker image size reduction X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=7dfea106269931b135713932db2b0ce6a83f5503;p=flatnotes.git Docker image size reduction - Use the python:3.11-alpine3.19 image as runtime container base - Replace gosu with su-exec - Clean pip and pipenv package cache --- diff --git a/Dockerfile b/Dockerfile index df9c15f..e71b102 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ COPY client ./client RUN npm run build # Runtime Container -FROM python:3.11-slim-bullseye +FROM python:3.11-alpine3.19 ARG BUILD_DIR @@ -30,17 +30,15 @@ ENV FLATNOTES_PATH=/data RUN mkdir -p ${APP_PATH} RUN mkdir -p ${FLATNOTES_PATH} -RUN apt update && apt install -y \ - curl \ - gosu \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache su-exec curl -RUN pip install pipenv +RUN pip install --no-cache-dir pipenv WORKDIR ${APP_PATH} COPY LICENSE Pipfile Pipfile.lock ./ -RUN pipenv install --deploy --ignore-pipfile --system +RUN pipenv install --deploy --ignore-pipfile --system && \ + pipenv --clear COPY server ./server COPY --from=build ${BUILD_DIR}/client/dist ./client/dist diff --git a/entrypoint.sh b/entrypoint.sh index dc810f3..30a5bad 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh set -e @@ -31,7 +31,7 @@ if [ `id -u` -eq 0 ] && [ `id -g` -eq 0 ]; then chown -R ${PUID}:${PGID} ${FLATNOTES_PATH} echo Starting flatnotes as user ${PUID}... - exec gosu ${PUID}:${PGID} ${flatnotes_command} + exec su-exec ${PUID}:${PGID} ${flatnotes_command} else echo "A user was set by docker, skipping file permission changes."