Archived
1
0
Fork 0

Initial import

This commit is contained in:
Daniel Kempkens 2022-01-30 23:11:34 +01:00
commit ff2775fcb6
5 changed files with 199 additions and 0 deletions

41
.github/workflows/build-image.yml vendored Normal file
View file

@ -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 }}

55
Dockerfile Normal file
View file

@ -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"]

73
entrypoint.sh Executable file
View file

@ -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 "$@"

9
requirements.txt Normal file
View file

@ -0,0 +1,9 @@
Cheetah3
configobj
paho-mqtt
Pillow
pyephem
pyserial
pyusb
setuptools
wheel

21
user/extensions.py Normal file
View file

@ -0,0 +1,21 @@
#
# Copyright (c) 2009-2015 Tom Keffer <tkeffer@gmail.com>
#
# 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'