commit ff2775fcb66f57db938be424c99b1c33a1b53ed7 Author: Daniel Kempkens Date: Sun Jan 30 23:11:34 2022 +0100 Initial import diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml new file mode 100644 index 0000000..a1d1154 --- /dev/null +++ b/.github/workflows/build-image.yml @@ -0,0 +1,41 @@ +name: Build Image + +on: + push: + branches: ['master'] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Log in to the Container registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..32ceda9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,55 @@ +FROM python:3 as stage-1 + +ENV WEEWX_HOME="/home/weewx" +ENV ARCHIVE="weewx-4.5.1.tar.gz" + +RUN addgroup --system --gid 421 weewx &&\ + adduser --system --uid 421 --ingroup weewx weewx + +WORKDIR /tmp +COPY requirements.txt ./ + +# WeeWX setup +RUN wget -O "${ARCHIVE}" "http://www.weewx.com/downloads/released_versions/${ARCHIVE}" &&\ + wget -O weewx-interceptor.zip https://github.com/matthewwall/weewx-interceptor/archive/master.zip &&\ + wget -O neowx-material-latest.zip https://neoground.com/projects/neowx-material/download/latest &&\ + tar --extract --gunzip --directory ${WEEWX_HOME} --strip-components=1 --file "${ARCHIVE}" &&\ + chown -R weewx:weewx ${WEEWX_HOME} + +# Python setup +RUN python -m venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" +RUN pip install --no-cache-dir --requirement requirements.txt + +WORKDIR ${WEEWX_HOME} + +RUN bin/wee_extension --install /tmp/weewx-interceptor.zip &&\ + bin/wee_extension --install /tmp/neowx-material-latest.zip &&\ + mkdir user +COPY entrypoint.sh ./ +COPY user/ ./bin/user/ + +FROM python:3 as stage-2 + +ENV WEEWX_HOME="/home/weewx" + +RUN addgroup --system --gid 421 weewx &&\ + adduser --system --uid 421 --ingroup weewx weewx + +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 &&\ + rm -rf /var/lib/apt/lists/* + +WORKDIR ${WEEWX_HOME} + +COPY --from=stage-1 /opt/venv /opt/venv +COPY --from=stage-1 ${WEEWX_HOME} ${WEEWX_HOME} + +RUN mkdir /data && \ + cp weewx.conf /data + +VOLUME ["/data"] + +ENV PATH="/opt/venv/bin:$PATH" +ENTRYPOINT ["./entrypoint.sh"] +CMD ["/data/weewx.conf"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..1e8bf49 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +set -o nounset +set -o errexit +set -o pipefail + +CONF_FILE="/data/weewx.conf" + +# echo version before starting syslog so we don't confound our tests +if [ "$1" = "--version" ]; then + gosu weewx:weewx ./bin/weewxd --version + exit 0 +fi + +if [ "$(id -u)" = 0 ]; then + # set timezone using environment + ln -snf /usr/share/zoneinfo/"${TIMEZONE:-UTC}" /etc/localtime + + # start the syslog daemon as root + /sbin/syslogd -n -S -O - & + + # start nginx + 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 [ "${WEEWX_UID:-weewx}" != 0 ]; then + # drop privileges and restart this script + echo "Switching uid:gid to ${WEEWX_UID:-weewx}:${WEEWX_GID:-weewx}" + gosu "${WEEWX_UID:-weewx}:${WEEWX_GID:-weewx}" "$(readlink -f "$0")" "$@" + exit 0 + fi +fi + +copy_default_config() { + # create a default configuration on the data volume + echo "Creating a configration file on the container data volume." + cp weewx.conf "${CONF_FILE}" + echo "The default configuration has been copied." + # Change the default location of the SQLITE database to the volume + echo "Setting SQLITE_ROOT to the container volume." + sed -i "s/SQLITE_ROOT =.*/SQLITE_ROOT = \/data/g" "${CONF_FILE}" +} + +if [ "$1" = "--gen-test-config" ]; then + copy_default_config + echo "Generating a test configuration." + ./bin/wee_config --reconfigure --no-prompt "${CONF_FILE}" + exit 0 +fi + +if [ "$1" = "--shell" ]; then + /bin/sh + exit $? +fi + +if [ "$1" = "--upgrade" ]; then + ./bin/wee_config --upgrade --no-prompt --dist-config weewx.conf "${CONF_FILE}" + exit $? +fi + +if [ ! -f "${CONF_FILE}" ]; then + copy_default_config + echo "Running configuration tool." + ./bin/wee_config --reconfigure "${CONF_FILE}" + exit 1 +fi + +./bin/weewxd "$@" diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5440ced --- /dev/null +++ b/requirements.txt @@ -0,0 +1,9 @@ +Cheetah3 +configobj +paho-mqtt +Pillow +pyephem +pyserial +pyusb +setuptools +wheel diff --git a/user/extensions.py b/user/extensions.py new file mode 100644 index 0000000..a8b0394 --- /dev/null +++ b/user/extensions.py @@ -0,0 +1,21 @@ +# +# Copyright (c) 2009-2015 Tom Keffer +# +# See the file LICENSE.txt for your full rights. +# + +"""User extensions module + +This module is imported from the main executable, so anything put here will be +executed before anything else happens. This makes it a good place to put user +extensions. +""" + +import locale +# This will use the locale specified by the environment variable 'LANG' +# Other options are possible. See: +# http://docs.python.org/2/library/locale.html#locale.setlocale +locale.setlocale(locale.LC_ALL, '') + +import weewx.units +weewx.units.obs_group_dict['soilMoist1'] = 'group_percent'