From 7ff0aab65d10faec202603de3ab759cf1e8f3b82 Mon Sep 17 00:00:00 2001 From: Nils Beyer <nilsb@fsmpi.rwth-aachen.de> Date: Fri, 24 Sep 2021 10:06:23 +0200 Subject: [PATCH] Feature: Docker setup for development --- Dockerfile | 23 +++++++++++++++++++++++ README.md | 20 ++++++++++++++++++++ docker_start.sh | 8 ++++++++ nginx.conf.example | 9 +++++---- 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100755 Dockerfile create mode 100755 docker_start.sh diff --git a/Dockerfile b/Dockerfile new file mode 100755 index 0000000..34bfc8c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM ubuntu + +RUN mkdir -p /code +COPY requirements.txt /code +WORKDIR /code + +RUN apt update && apt install python3 python3-flask sqlite python3-requests python3-lxml python3-ldap3 python3-icalendar python3-mysql.connector locales -y +RUN locale-gen de_DE.utf8 +RUN apt install git -y + +# Install uwsgi +RUN apt update && apt install python3-pip -y +RUN pip3 install uwsgi + +# Install pylint +RUN pip3 install pylint + +# Install nginx +RUN apt install nginx -y + +COPY . /code + +CMD ["bash", "/code/docker_start.sh"] diff --git a/README.md b/README.md index 690f2ae..9e39f2f 100644 --- a/README.md +++ b/README.md @@ -53,3 +53,23 @@ Kurzform unter Ubuntu: Mit python-eigenem Paketmanager: `pip install -r requirements.txt` + +--- + +### Alternative: Docker Image + +Alternativ zu vorigem Setup kann zum lokalen Testen Docker verwendet werden, um die Testversion zu starten: + +1. Lokal das Image erstellen mittels `docker build -t videoag .` in diesem Ordner. +2. Einen entsprechenden Container starten, z.B.: `docker run --rm --name=videoag -p 5000:5000 videoag` + - `--rm` löscht den Container nach dessen Terminierung + - `-p 5000:5000` mappt den Port, damit der Host auf die Webseite zugreifen kann. Nicht den lokalen Port ändern, da ansonsten ggf. Thumbnails oder Videos nicht mehr geladen werden können. + - Zusätzlich kann mittels `-v /lokaler/pfad/:/code` der Source-Code im Container mit dem Host gemounted werden. +3. Webseite unter `localhost:5000` besuchen. + +In dieser Variante sollte in der `config.py` folgendes gesetzt werden: + +``` +SERVER_IP = 'localhost' +VIDEOPREFIX = '/files' +``` diff --git a/docker_start.sh b/docker_start.sh new file mode 100755 index 0000000..32c6ff2 --- /dev/null +++ b/docker_start.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# This file is executed when the docker container starts! +cd /code; + +nginx -c nginx.conf.example -p . & +# Use -C argument to tell uwsgi to chmod 666 /uswgi.sock +exec uwsgi -C -s uwsgi.sock --manage-script-name --mount /=server:app --plugin python --enable-threads diff --git a/nginx.conf.example b/nginx.conf.example index ed1ec31..f81c2eb 100644 --- a/nginx.conf.example +++ b/nginx.conf.example @@ -26,21 +26,22 @@ http { keepalive_timeout 65; types_hash_max_size 2048; server { - #listen 5000; + listen 5000; #listen [::]:5000; - listen localhost:5000; + #listen localhost:5000; error_page 502 /static/500.html; location /static/ { root .; } location /files/ { - auth_request /auth; + auth_request /internal/auth; auth_request_set $trackingcookie $upstream_http_set_cookie; # For use with sshfs (recommended) #alias /mnt/videoag/srv/videoag/released/; #add_header Set-Cookie $trackingcookie; # For use without sshfs - proxy_pass https://videoag.fsmpi.rwth-aachen.de/; + # NO TRAILING SLASH so that /files/ will not be skipped of the request! + proxy_pass https://videoag.fsmpi.rwth-aachen.de; proxy_set_header Host "videoag.fsmpi.rwth-aachen.de"; proxy_set_header Set-Cookie $trackingcookie; } -- GitLab