summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbuttle <chris@gatopelao.org>2023-07-31 11:06:32 +0200
committerbuttle <chris@gatopelao.org>2023-07-31 11:06:32 +0200
commit0e69d3136b3954dfe1d8b3427b4581404bd28fee (patch)
tree0a5655db04870446b6f39fd7aaf9f0e20449e047
parentc558f4ee8ecdcedc30cb59c84bfac0d4ad1730fd (diff)
adds Supervisor to docker imagefeat/rotate-logs
-rw-r--r--.gitignore4
-rw-r--r--Dockerfile7
-rw-r--r--docker-compose.yml.example8
-rw-r--r--docs/docker.md4
-rw-r--r--liberaforms/config/docker-build/gunicorn.py9
-rw-r--r--liberaforms/config/docker-build/supervisord.conf24
-rw-r--r--log_listener.py5
7 files changed, 46 insertions, 15 deletions
diff --git a/.gitignore b/.gitignore
index c00d50be..cf5a35bd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,18 +1,16 @@
venv
.env
docker-compose.yml
-gunicorn.py
+./gunicorn.py
logs/*
notes.txt
flask_session
__pycache__
*.backup
.pytest_cache
-WIP
# Styles
liberaforms/static/node_modules/
liberaforms/static/package-lock.json
liberaforms/static/Gruntfile.js
.DS_Store
-liberaforms.conf
diff --git a/Dockerfile b/Dockerfile
index 21af46ae..b545d50c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -9,14 +9,19 @@ ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$PATH:$VIRTUAL_ENV/bin"
-RUN apt-get install libmemcached-dev libpq-dev gcc libz-dev mime-support -y
+RUN apt-get install libmemcached-dev libpq-dev gcc libz-dev mime-support supervisor -y
RUN mkdir /app
WORKDIR /app
ADD ./requirements.txt requirements.txt
+RUN pip install --upgrade pip
RUN pip install -r requirements.txt --no-cache-dir
RUN pip install pylibmc --no-cache-dir
COPY . /app
+COPY ./liberaforms/config/docker-build/gunicorn.py /app/gunicorn.py
+COPY ./liberaforms/config/docker-build/supervisord.conf /etc/supervisor/supervisord.conf
+
EXPOSE 5000
+CMD ["/usr/bin/supervisord", "-n"]
diff --git a/docker-compose.yml.example b/docker-compose.yml.example
index d20ee29a..5a89f9ad 100644
--- a/docker-compose.yml.example
+++ b/docker-compose.yml.example
@@ -61,18 +61,12 @@ services:
LDAP_FILTER: ${LDAP_FILTER}
LDAP_MAIL_ATTRIB: ${LDAP_MAIL_ATTRIB}
LDAP_RECOVER_PASSWD_URL: ${LDAP_RECOVER_PASSWD_URL}
+ GUNICORN_WORKERS: ${GUNICORN_WORKERS}
volumes:
- /opt/liberaforms_uploads:/app/uploads
- /opt/liberaforms_logs:/app/logs
networks:
- db_net
- ## For development
- #volumes:
- # - ./:/app
- #command: flask run --host 0.0.0.0
- ## For production
- command: gunicorn --worker-tmp-dir /dev/shm --bind 0.0.0.0:5000 --workers 3 wsgi:app
-
volumes:
db_data:
diff --git a/docs/docker.md b/docs/docker.md
index 90482d41..c8f04131 100644
--- a/docs/docker.md
+++ b/docs/docker.md
@@ -23,13 +23,15 @@ It will not setup a webserver, you will have to do that.
### Edit `.env`
-The Postgres container requires two extra environment variables.
+You will need to add these extra environment variables.
```
POSTGRES_ROOT_USER=
POSTGRES_ROOT_PASSWORD=
DB_HOST=liberaforms-db
+
+GUNICORN_WORKERS=3
```
Note that the name of the postgresql container will be set to `DB_HOST`
diff --git a/liberaforms/config/docker-build/gunicorn.py b/liberaforms/config/docker-build/gunicorn.py
new file mode 100644
index 00000000..fade6710
--- /dev/null
+++ b/liberaforms/config/docker-build/gunicorn.py
@@ -0,0 +1,9 @@
+import os
+from dotenv import load_dotenv
+
+directory = "/app"
+load_dotenv(dotenv_path=".env")
+
+command = 'gunicorn'
+bind = '0.0.0.0:5000'
+workers = os.environ["GUNICORN_WORKERS"]
diff --git a/liberaforms/config/docker-build/supervisord.conf b/liberaforms/config/docker-build/supervisord.conf
new file mode 100644
index 00000000..83a54490
--- /dev/null
+++ b/liberaforms/config/docker-build/supervisord.conf
@@ -0,0 +1,24 @@
+[supervisord]
+user=root
+nodaemon=true
+logfile=/dev/null
+logfile_maxbytes=0
+
+
+[program:liberaforms-app]
+directory = /app
+command = gunicorn -c /app/gunicorn.py 'wsgi:create_app()'
+stdout_logfile=/dev/fd/1
+stdout_logfile_maxbytes=0
+redirect_stderr=true
+
+
+[program:liberaforms-logs]
+directory = /app
+command = python log_listener.py
+priority = 500
+autostart = true
+autorestart = true
+stdout_logfile=/dev/fd/2
+stdout_logfile_maxbytes=0
+redirect_stderr=true
diff --git a/log_listener.py b/log_listener.py
index 8f61eae9..63575329 100644
--- a/log_listener.py
+++ b/log_listener.py
@@ -25,8 +25,7 @@ LOG_SERVER_PORT = int(os.environ['LOG_SERVER_PORT']) if 'LOG_SERVER_PORT' in os.
LOG_LEVEL = os.environ['LOG_LEVEL'] if 'LOG_LEVEL' in os.environ else 'INFO'
SERVER_NAME = urlparse(os.environ['BASE_URL']).netloc
LOG_DIR = os.environ['LOG_DIR']
-#LOG_MAX_BYTES = 100_000_000
-LOG_MAX_BYTES = 4_000
+LOG_MAX_BYTES = 100_000_000
LOG_COPIES = 5
DEFAULT_LOG_FORMAT = {
@@ -130,7 +129,7 @@ def main():
logging.config.dictConfig(logging_conf)
logging.getLogger('log_listener').info('Log listener started.')
tcpserver = LogRecordSocketReceiver(port=LOG_SERVER_PORT)
- print(f'About to start TCP server on port {LOG_SERVER_PORT} ...')
+ print(f'About to start TCP log server on port {LOG_SERVER_PORT} ...')
tcpserver.serve_until_stopped()