Skip to content

Commit 9f0b55a

Browse files
committed
improved Dockerfile and documentation
1 parent 48514c0 commit 9f0b55a

File tree

3 files changed

+64
-11
lines changed

3 files changed

+64
-11
lines changed

Dockerfile

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.11-slim as base
1+
FROM python:3.11-slim AS base
22

33
# set version label
44
ARG BUILD_DATE
@@ -7,13 +7,13 @@ LABEL build_version="Apprise API version:- ${VERSION} Build-date:- ${BUILD_DATE}
77
LABEL maintainer="Chris-Caron"
88

99
# set environment variables
10-
ENV PYTHONDONTWRITEBYTECODE 1
11-
ENV PYTHONUNBUFFERED 1
12-
ENV APPRISE_CONFIG_DIR /config
13-
ENV APPRISE_ATTACH_DIR /attach
14-
ENV APPRISE_PLUGIN_PATHS /plugin
10+
ENV PYTHONDONTWRITEBYTECODE=1
11+
ENV PYTHONUNBUFFERED=1
12+
ENV APPRISE_CONFIG_DIR=/config
13+
ENV APPRISE_ATTACH_DIR=/attach
14+
ENV APPRISE_PLUGIN_PATHS=/plugin
1515

16-
FROM base as builder
16+
FROM base AS builder
1717

1818
WORKDIR /build/
1919

@@ -41,7 +41,7 @@ RUN set -eux && \
4141
--no-binary cryptography \
4242
cryptography
4343

44-
FROM base as runtime
44+
FROM base AS runtime
4545

4646
# Install requirements and gunicorn
4747
COPY ./requirements.txt /etc/requirements.txt
@@ -78,7 +78,8 @@ COPY apprise_api/ webapp
7878

7979
# Configuration Permissions (to run nginx as a non-root user)
8080
RUN umask 0002 && \
81-
touch /etc/nginx/override.conf
81+
touch /etc/nginx/server-override.conf && \
82+
touch /etc/nginx/location-override.conf
8283

8384
VOLUME /config
8485
VOLUME /attach

README.md

+49-1
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,56 @@ The use of environment variables allow you to provide over-rides to default sett
401401
| `DEBUG` | This defaults to `no` and can however be set to `yes` by simply defining the global variable as such.
402402

403403

404-
## Development Environment
404+
## Nginx Overrides
405+
406+
The 2 files you can override are:
407+
1. `/etc/nginx/location-override.conf` which is included within all of the Apprise API NginX `location` references.
408+
1. `/etc/nginx/server-override.conf` which is included within Apprise API `server` reference.
409+
410+
### Authentication
411+
Under the hood, Apprise-API is running a small NginX instance. It allows for you to inject your own configuration into it. One thing you may wish to add is basic authentication.
412+
413+
Below we create ourselves some nginx directives we'd like to apply to our Apprise API:
414+
```nginx
415+
# Our override.conf file:
416+
auth_basic "Apprise API Restricted Area";
417+
auth_basic_user_file /etc/nginx/.htpasswd;
418+
```
419+
420+
Now let's set ourselves up with a simple password file (for more info on htpasswd files, see [here](https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/)
421+
```bash
422+
# Create ourselves a for our user 'foobar'; the below will prompt you for the pass
423+
# you want to provide:
424+
htpasswd -c apprise_api.htpasswd foobar
425+
426+
# Note: the -c above is only needed to create the database for the first time
427+
```
405428

429+
Now we can create our docker container with this new authentication information:
430+
```bash
431+
# Create our container containing Basic Auth:
432+
docker run --name apprise \
433+
-p 8000:8000 \
434+
-e PUID=$(id -u) \
435+
-e PGID=$(id -g) \
436+
-v /path/to/local/config:/config \
437+
-v /path/to/local/attach:/attach \
438+
-v ./override.conf:/etc/nginx/location-override.conf:ro \
439+
-v ./apprise_api.htpasswd:/etc/nginx/.htpasswd:ro \
440+
-e APPRISE_STATEFUL_MODE=simple \
441+
-e APPRISE_WORKER_COUNT=1 \
442+
-d caronc/apprise:latest
443+
```
444+
445+
Visit http://localhost:8000 to see if things are working as expected. If you followed the example above, you should log in as the user `foobar` using the credentials you provided the account.
446+
447+
You can add further accounts to the existing database by omitting the `-c` switch:
448+
```bash
449+
# Add another account
450+
htpasswd apprise_api.htpasswd user2
451+
```
452+
453+
## Development Environment
406454
The following should get you a working development environment to test with:
407455

408456
```bash

apprise_api/etc/nginx.conf

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ http {
1616
types_hash_max_size 2048;
1717
include /etc/nginx/mime.types;
1818
default_type application/octet-stream;
19+
# Do not display Nginx Version
20+
server_tokens off;
1921

2022
##
2123
# Upload Restriction
@@ -45,7 +47,7 @@ http {
4547

4648
# Allow users to map to this file and provide their own custom
4749
# overrides such as
48-
include /etc/nginx/override.conf;
50+
include /etc/nginx/server-override.conf;
4951

5052
# Main Website
5153
location / {
@@ -56,12 +58,14 @@ http {
5658
proxy_pass http://localhost:8080;
5759
# Give ample time for notifications to fire
5860
proxy_read_timeout 120s;
61+
include /etc/nginx/location-override.conf;
5962
}
6063

6164
# Static Content
6265
location /s/ {
6366
root /usr/share/nginx/html;
6467
index index.html;
68+
include /etc/nginx/location-override.conf;
6569
}
6670

6771
# 404 error handling

0 commit comments

Comments
 (0)