From 48514c0aada7eb1228b158ff8c175b592de37267 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Sat, 29 Jun 2024 20:57:38 -0400 Subject: [PATCH] Healthcheck web improvements + PUID & PGID support added to Docker --- Dockerfile | 15 ++-- README.md | 54 +++++---------- apprise_api/api/templates/base.html | 62 +++++++++++++++-- apprise_api/api/templates/config.html | 4 +- apprise_api/api/templates/welcome.html | 1 - apprise_api/api/tests/test_healthecheck.py | 7 +- apprise_api/api/tests/test_notify.py | 62 +++++++++++++++++ apprise_api/api/utils.py | 80 +++++++++++++--------- apprise_api/api/views.py | 5 +- apprise_api/core/context_processors.py | 6 +- apprise_api/etc/nginx.conf | 12 ++-- apprise_api/etc/supervisord.conf | 4 +- apprise_api/static/css/base.css | 30 ++++++++ apprise_api/static/css/theme-dark.min.css | 1 - apprise_api/supervisord-startup | 78 +++++++++++++++++++++ 15 files changed, 325 insertions(+), 96 deletions(-) create mode 100755 apprise_api/supervisord-startup diff --git a/Dockerfile b/Dockerfile index 327cb1c..dd26901 100644 --- a/Dockerfile +++ b/Dockerfile @@ -45,7 +45,7 @@ FROM base as runtime # Install requirements and gunicorn COPY ./requirements.txt /etc/requirements.txt -COPY --from=builder /build/*.whl . +COPY --from=builder /build/*.whl ./ RUN set -eux && \ echo "Installing cryptography" && \ pip3 install *.whl && \ @@ -55,6 +55,9 @@ RUN set -eux && \ apt-get update -qq && \ apt-get install -y -qq \ nginx && \ + echo "Installing tools" && \ + apt-get install -y -qq \ + sed && \ echo "Cleaning up" && \ apt-get --yes autoremove --purge && \ apt-get clean --yes && \ @@ -73,16 +76,12 @@ WORKDIR /opt/apprise # Copy over Apprise API COPY apprise_api/ webapp -# -# # Configuration Permissions (to run nginx as a non-root user) +# Configuration Permissions (to run nginx as a non-root user) RUN umask 0002 && \ - mkdir -p /attach /config /plugin /run/apprise && \ - chown www-data:www-data -R /run/apprise /var/lib/nginx /attach /config /plugin + touch /etc/nginx/override.conf -# Handle running as a non-root user (www-data is id/gid 33) -USER www-data VOLUME /config VOLUME /attach VOLUME /plugin EXPOSE 8000 -CMD ["/usr/local/bin/supervisord", "-c", "/opt/apprise/webapp/etc/supervisord.conf"] +CMD ["/opt/apprise/webapp/supervisord-startup"] diff --git a/README.md b/README.md index 20b6e2c..23e0a2d 100644 --- a/README.md +++ b/README.md @@ -56,11 +56,17 @@ docker pull caronc/apprise:latest # setting APPRISE_STATEFUL_MODE to simple allows you to map your defined {key} # straight to a file found in the `/config` path. In simple home configurations # this is sometimes the ideal expectation. +# +# Set your User ID or Group ID if you wish to over-ride the default of 1000 +# in the below example, we make sure it runs as the user we created the container as + docker run --name apprise \ -p 8000:8000 \ - -v /var/lib/apprise/config:/config \ - -v /var/lib/apprise/plugin:/plugin \ - -v /var/lib/apprise/attach:/attach \ + -e PUID=$(id -u) \ + -e PGID=$(id -g) \ + -v /path/to/local/config:/config \ + -v /path/to/local/plugin:/plugin \ + -v /path/to/local/attach:/attach \ -e APPRISE_STATEFUL_MODE=simple \ -e APPRISE_WORKER_COUNT=1 \ -d caronc/apprise:latest @@ -72,11 +78,17 @@ A common change one might make is to update the Dockerfile to point to the maste # Setup your environment the way you like docker build -t apprise/local:latest -f Dockerfile . +# Set up a directory you wish to store your configuration in: +mkdir -p /etc/apprise + # Launch your instance docker run --name apprise \ -p 8000:8000 \ + -e PUID=$(id -u) \ + -e PGID=$(id -g) \ -e APPRISE_STATEFUL_MODE=simple \ -e APPRISE_WORKER_COUNT=1 \ + -v /etc/apprise:/config \ -d apprise/local:latest ``` A `docker-compose.yml` file is already set up to grant you an instant production ready simulated environment: @@ -86,40 +98,6 @@ A `docker-compose.yml` file is already set up to grant you an instant production docker-compose up ``` -### Config Directory Permissions - -Under the hood, An NginX services is reading/writing your configuration files as the user (and group) `www-data` which generally has the id of `33`. In preparation so that you don't get the error: `An error occured saving configuration.` consider also setting up your local `/var/lib/apprise/config` permissions as: - -```bash -# Create a user/group (if one doesn't already exist) owned -# by the user and group id of 33 -id 33 &>/dev/null || sudo useradd \ - --system --no-create-home --shell /bin/false \ - -u 33 -g 33 www-data - -# Securely set the directory limiting access to only those who -# are part of the www-data group: -sudo chmod 770 -R /var/lib/apprise/config -sudo chown 33:33 -R /var/lib/apprise/config - -# Now optionally add yourself to the group if you wish to be able to view -# contents. -sudo usermod -a -G 33 $(whoami) - -# You may need to log out and back in again for the above usermod -# to reflect on you. Alternatively you can just type the following -# and it will work as a temporary solution: -sudo su - $(whoami) -``` - -Alternatively a dirty solution is to just set the directory with full read/write permissions (which is not ideal in a production environment): - -```bash -# Grant full permission to the local directory you're saving your -# Apprise configuration to: -chmod 777 /var/lib/apprise/config -``` - ## Dockerfile Details The following architectures are supported: `amd64`, `arm/v7`, and `arm64`. The following tags can be used: @@ -398,6 +376,8 @@ The use of environment variables allow you to provide over-rides to default sett | Variable | Description | |--------------------- | ----------- | +| `PUID` | The User ID you wish the Apprise instance under the hood to run as. The default is `1000` if not otherwise specified. +| `PGID` | The Group ID you wish the Apprise instance under the hood to run as. The default is `1000` if not otherwise specified. | `APPRISE_DEFAULT_THEME` | Can be set to `light` or `dark`; it defaults to `light` if not otherwise provided. The theme can be toggled from within the website as well. | `APPRISE_DEFAULT_CONFIG_ID` | Defaults to `apprise`. This is the presumed configuration ID you always default to when accessing the configuration manager via the website. | `APPRISE_CONFIG_DIR` | Defines an (optional) persistent store location of all configuration files saved. By default:
- Configuration is written to the `apprise_api/var/config` directory when just using the _Django_ `manage runserver` script. However for the path for the container is `/config`. diff --git a/apprise_api/api/templates/base.html b/apprise_api/api/templates/base.html index 2ebe111..037c2fe 100644 --- a/apprise_api/api/templates/base.html +++ b/apprise_api/api/templates/base.html @@ -37,9 +37,9 @@

{% trans "Apprise API" %}

+
  • APPRISE v{{APPRISE_VERSION}}
  • +
  • invert_colors
  • + @@ -50,10 +50,10 @@

    {% trans "Apprise API" %}

    {% endif %}