diff options
| author | Jan Friedli | 2020-03-31 20:33:06 +0200 |
|---|---|---|
| committer | Jan Friedli | 2020-05-09 21:21:49 +0200 |
| commit | b7cd80d155a8b3e1ebc5607b046544d45cf1921f (patch) | |
| tree | a1b3bebda04bcea9fbf6d801ddeeaceaf9fcd81a | |
| parent | ac21ea756c18453954cdc87e9d33a9676ef48066 (diff) | |
made upload folder configurable
| -rw-r--r-- | Dockerfile.production | 5 | ||||
| -rw-r--r-- | README.md | 20 | ||||
| -rw-r--r-- | main.py | 2 |
3 files changed, 14 insertions, 13 deletions
diff --git a/Dockerfile.production b/Dockerfile.production index 025393f..35eb553 100644 --- a/Dockerfile.production +++ b/Dockerfile.production | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # https://github.com/nginxinc/docker-nginx-unprivileged/blob/master/stable/buster/Dockerfile | 1 | # https://github.com/nginxinc/docker-nginx-unprivileged/blob/master/stable/buster/Dockerfile |
| 2 | 2 | ||
| 3 | From registry.0xacab.org/georg/mat2-ci-images:debian | 3 | From debian:buster-slim |
| 4 | 4 | ||
| 5 | LABEL maintainer="Mat-Web Co-Maintainer <jan.friedli@immerda.ch>" | 5 | LABEL maintainer="Mat-Web Co-Maintainer <jan.friedli@immerda.ch>" |
| 6 | 6 | ||
| @@ -8,6 +8,8 @@ WORKDIR /var/www/mat2-web | |||
| 8 | 8 | ||
| 9 | COPY . /var/www/mat2-web | 9 | COPY . /var/www/mat2-web |
| 10 | 10 | ||
| 11 | ENV MAT2_WEB_DOWNLOAD_FOLDER /app/upload | ||
| 12 | |||
| 11 | RUN set -x \ | 13 | RUN set -x \ |
| 12 | && addgroup --system --gid 101 nginx \ | 14 | && addgroup --system --gid 101 nginx \ |
| 13 | && adduser --system --disabled-login --ingroup nginx --no-create-home --home /nonexistent --gecos "nginx user" --shell /bin/false --uid 101 nginx \ | 15 | && adduser --system --disabled-login --ingroup nginx --no-create-home --home /nonexistent --gecos "nginx user" --shell /bin/false --uid 101 nginx \ |
| @@ -16,6 +18,7 @@ RUN set -x \ | |||
| 16 | ca-certificates \ | 18 | ca-certificates \ |
| 17 | nginx \ | 19 | nginx \ |
| 18 | systemd \ | 20 | systemd \ |
| 21 | mat2 \ | ||
| 19 | uwsgi \ | 22 | uwsgi \ |
| 20 | uwsgi-plugin-python3 \ | 23 | uwsgi-plugin-python3 \ |
| 21 | python3-pip \ | 24 | python3-pip \ |
| @@ -47,20 +47,18 @@ Nginx is the recommended web engine, but you can also use Apache if you prefer, | |||
| 47 | by copying [this file](https://0xacab.org/jvoisin/mat2-web/tree/master/config/apache2.config) | 47 | by copying [this file](https://0xacab.org/jvoisin/mat2-web/tree/master/config/apache2.config) |
| 48 | to your `/etc/apache2/sites-enabled/mat2-web` file. | 48 | to your `/etc/apache2/sites-enabled/mat2-web` file. |
| 49 | 49 | ||
| 50 | Then configure the environment variable: `MAT2_ALLOW_ORIGIN_WHITELIST=https://myhost1.org https://myhost2.org` | ||
| 51 | Note that you can add multiple hosts from which you want to accept API requests. These need to be separated by | ||
| 52 | a space. | ||
| 53 | **IMPORTANT:** The default value if the variable is not set is: `Access-Control-Allow-Origin: *` | ||
| 54 | |||
| 55 | Configure the following environment variables: | 50 | Configure the following environment variables: |
| 56 | 51 | ||
| 52 | - `MAT2_ALLOW_ORIGIN_WHITELIST=https://myhost1.org https://myhost2.org` | ||
| 53 | Note that you can add multiple hosts from which you want to accept API requests. These need to be separated by | ||
| 54 | a space. **IMPORTANT:** The default value if the variable is not set is: `Access-Control-Allow-Origin: *` | ||
| 57 | - `MAT2_MAX_FILES_BULK_DOWNLOAD=10` Max number of files that can be grouped for a bulk download. | 55 | - `MAT2_MAX_FILES_BULK_DOWNLOAD=10` Max number of files that can be grouped for a bulk download. |
| 58 | - `MAT2_MAX_FILE_AGE_FOR_REMOVAL=900` Seconds a file in the upload folder is kept. | 56 | Note: Each file has a max file size of 16mb |
| 59 | After that it will be deleted. Default `15 * 60` | ||
| 60 | |||
| 61 | This specifies the max number of files that can be bulk downloaded using the api. | ||
| 62 | Note: Each file has a max file size of 16mb | ||
| 63 | 57 | ||
| 58 | - `MAT2_MAX_FILE_AGE_FOR_REMOVAL=900` Seconds a file in the upload folder is kept. | ||
| 59 | After that it will be deleted. Default `15 * 60` | ||
| 60 | - `MAT2_WEB_DOWNLOAD_FOLDER` Define the upload folder path. Defaults to: `./uploads/` | ||
| 61 | |||
| 64 | Finally, restart uWSGI and your web server: | 62 | Finally, restart uWSGI and your web server: |
| 65 | 63 | ||
| 66 | ``` | 64 | ``` |
| @@ -197,7 +195,7 @@ repository: https://0xacab.org/jvoisin/mat2-web/container_registry | |||
| 197 | ### Building the production image | 195 | ### Building the production image |
| 198 | Build command: `docker build -f Dockerfile.production -t mat-web .` | 196 | Build command: `docker build -f Dockerfile.production -t mat-web .` |
| 199 | 197 | ||
| 200 | Run it: `docker run -ti -p8181:8080 --read-only --tmpfs /tmp --tmpfs /run/uwsgi --tmpfs=/var/www/mat2-web/uploads mat-web:latest` | 198 | Run it: `docker run -ti -p8181:8080 --read-only --tmpfs /tmp --tmpfs /run/uwsgi --tmpfs=/app/uploads mat-web:latest` |
| 201 | 199 | ||
| 202 | This does mount the upload folder as tmpfs and servers the app on `localhost:8181`. | 200 | This does mount the upload folder as tmpfs and servers the app on `localhost:8181`. |
| 203 | 201 | ||
| @@ -10,7 +10,7 @@ from flask_cors import CORS | |||
| 10 | def create_app(test_config=None): | 10 | def create_app(test_config=None): |
| 11 | app = Flask(__name__) | 11 | app = Flask(__name__) |
| 12 | app.config['SECRET_KEY'] = os.urandom(32) | 12 | app.config['SECRET_KEY'] = os.urandom(32) |
| 13 | app.config['UPLOAD_FOLDER'] = './uploads/' | 13 | app.config['UPLOAD_FOLDER'] = os.environ.get('MAT2_WEB_DOWNLOAD_FOLDER', './uploads/') |
| 14 | app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB | 14 | app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB |
| 15 | app.config['CUSTOM_TEMPLATES_DIR'] = 'custom_templates' | 15 | app.config['CUSTOM_TEMPLATES_DIR'] = 'custom_templates' |
| 16 | # optionally load settings from config.py | 16 | # optionally load settings from config.py |
