From 51d81024323f2a90ac4818891c2b24e7f2ff29fb Mon Sep 17 00:00:00 2001 From: Daniel Kempkens Date: Fri, 15 Jul 2022 20:29:23 +0200 Subject: [PATCH] Smaller Docker image --- Dockerfile | 53 +++++++++++++++++++++++++++++---------------------- README.md | 3 +++ entrypoint.sh | 5 ----- 3 files changed, 33 insertions(+), 28 deletions(-) create mode 100644 README.md diff --git a/Dockerfile b/Dockerfile index 1b7921c..58f3c69 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,13 @@ -FROM python:3 as stage-1 +FROM python:3.10.5-slim-bullseye as install +ARG WEEWX_UID=421 ENV WEEWX_HOME="/home/weewx" -ENV ARCHIVE="weewx-4.8.0.tar.gz" -ENV NEOWX_VERSION="latest" -ENV WDC_VERSION="v1.3.1" +ENV WEEWX_VERSION="4.8.0" +ENV ARCHIVE="weewx-${WEEWX_VERSION}.tar.gz" +ENV WEEWX_WDC_VERSION="v1.3.1" -RUN addgroup --system --gid 421 weewx &&\ - adduser --system --uid 421 --ingroup weewx weewx +RUN addgroup --system --gid ${WEEWX_UID} weewx \ + && adduser --system --uid ${WEEWX_UID} --ingroup weewx weewx WORKDIR /tmp COPY requirements.txt ./ @@ -16,42 +17,48 @@ RUN python -m venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" RUN pip install --no-cache-dir --requirement requirements.txt -# WeeWX setup +# Download weewx and plugins RUN wget -O "${ARCHIVE}" "http://www.weewx.com/downloads/released_versions/${ARCHIVE}" &&\ wget -O weewx-interceptor.zip https://github.com/nifoc/weewx-interceptor/archive/refs/heads/feature/ecowitt-fields.zip &&\ wget -O weewx-forecast.zip https://github.com/chaunceygardiner/weewx-forecast/archive/master.zip &&\ - wget -O neowx-material.zip https://neoground.com/projects/neowx-material/download/${NEOWX_VERSION} &&\ - wget -O weewx-wdc.zip https://github.com/Daveiano/weewx-wdc/releases/download/${WDC_VERSION}/weewx-wdc-${WDC_VERSION}.zip &&\ - tar --extract --gunzip --directory ${WEEWX_HOME} --strip-components=1 --file "${ARCHIVE}" &&\ - mkdir weewx-wdc && unzip weewx-wdc.zip -d weewx-wdc &&\ - chown -R weewx:weewx ${WEEWX_HOME} + wget -O weewx-wdc.zip https://github.com/Daveiano/weewx-wdc/releases/download/${WEEWX_WDC_VERSION}/weewx-wdc-${WEEWX_WDC_VERSION}.zip +# Extract weewx and (some) plugins +RUN tar --extract --gunzip --directory ${WEEWX_HOME} --strip-components=1 --file "${ARCHIVE}" &&\ + mkdir weewx-wdc && unzip weewx-wdc.zip -d weewx-wdc + +# weewx setup +RUN chown -R weewx:weewx ${WEEWX_HOME} WORKDIR ${WEEWX_HOME} - RUN bin/wee_extension --install /tmp/weewx-interceptor.zip &&\ bin/wee_extension --install /tmp/weewx-forecast.zip &&\ - bin/wee_extension --install /tmp/neowx-material.zip &&\ bin/wee_extension --install /tmp/weewx-wdc &&\ mkdir user - COPY entrypoint.sh ./ -COPY user/ ./bin/user/ +COPY --chown=weewx:weewx user/ ./bin/user/ -FROM python:3 as stage-2 +FROM python:3.10.5-slim-bullseye as final +ARG WEEWX_UID=421 ENV WEEWX_HOME="/home/weewx" -RUN addgroup --system --gid 421 weewx &&\ - adduser --system --uid 421 --ingroup weewx weewx +RUN addgroup --system --gid ${WEEWX_UID} weewx \ + && adduser --system --uid ${WEEWX_UID} --ingroup weewx weewx +# Install runtime dependencies RUN apt-get update -qq -y &&\ - DEBIAN_FRONTEND=noninteractive apt-get install -y libusb-1.0-0 gosu busybox-syslogd tzdata nginx-light -qq -y --no-install-recommends &&\ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + libusb-1.0-0 \ + gosu \ + busybox-syslogd \ + tzdata \ + nginx-light -qq -y --no-install-recommends &&\ rm -rf /var/lib/apt/lists/* +# Copy installation from install stage WORKDIR ${WEEWX_HOME} - -COPY --from=stage-1 /opt/venv /opt/venv -COPY --from=stage-1 ${WEEWX_HOME} ${WEEWX_HOME} +COPY --from=install /opt/venv /opt/venv +COPY --from=install ${WEEWX_HOME} ${WEEWX_HOME} RUN mkdir /data && \ cp weewx.conf /data diff --git a/README.md b/README.md new file mode 100644 index 0000000..2d94a20 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# weewx-docker + +Based on: [felddy/weewx-docker](https://github.com/felddy/weewx-docker) diff --git a/entrypoint.sh b/entrypoint.sh index a5f2c6d..3fbcbbe 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -23,11 +23,6 @@ if [ "$(id -u)" = 0 ]; then nginx -c /data/nginx.conf # skin config - if [ -e /data/neowx-material-skin.conf ]; then - rm -f ./skins/neowx-material/skin.conf - ln -s /data/neowx-material-skin.conf ./skins/neowx-material/skin.conf - fi - if [ -e /data/weewx-wdc-skin.conf ]; then rm -f ./skins/weewx-wdc/skin.conf ln -s /data/weewx-wdc-skin.conf ./skins/weewx-wdc/skin.conf