From ce452deda56fb4907084bb0849bc1d45e698bc9e Mon Sep 17 00:00:00 2001 From: Gael Le Mignot Date: Mon, 3 Apr 2023 11:35:28 +0200 Subject: [PATCH] First shot of ae dockerization --- .dockerignore | 9 + .gitignore | 12 +- Dockerfile | 27 +- app/__init__.py | 21 + app/init.sh | 16 + app/local_settings.py.sample | 76 +++ app/manage.py | 26 +- app/urls.py | 34 +- app/wait.sh | 3 + app/worker.py | 24 + app/wsgi.ini | 58 ++ app/wsgi.py | 31 +- app/wsgi.sh | 49 ++ bin/build/doc.sh | 3 + bin/build/front.sh | 3 + bin/build/graph.sh | 3 + bin/build/local/messages.sh | 10 + bin/build/local/setup_lib.sh | 14 + bin/build/local/setup_lib_py2.sh | 14 + bin/build/messages.sh | 3 + bin/build/readme.sh | 7 + bin/misc/fix/fs_migrate.sh | 9 + bin/misc/fix_var_perms.sh | 17 + bin/misc/gulp.sh | 3 + bin/misc/poll_twitter.sh | 3 + bin/misc/sql/latin1_to_utf8.py | 31 + bin/misc/sql/latin1_to_utf8_tester.py | 107 ++++ bin/misc/statifier.py | 79 +++ bin/misc/statifier.sh | 20 + bin/misc/wait-for-it/.gitignore | 3 + bin/misc/wait-for-it/.travis.yml | 7 + bin/misc/wait-for-it/LICENSE | 20 + bin/misc/wait-for-it/README.md | 65 ++ bin/misc/wait-for-it/test/wait-for-it.py | 179 ++++++ bin/misc/wait-for-it/wait-for-it.sh | 178 ++++++ debian-packages.txt | 10 + docker-compose-dev.yml | 57 ++ docker-compose.yml | 77 ++- env/debug.env | 10 + etc/apache2-dev.conf | 558 ++++++++++++++++ etc/postgresql.conf | 781 +++++++++++++++++++++++ example/__init__.py | 0 example/manage.py | 9 - example/settings.py | 247 ------- example/urls.py | 29 - example/wsgi.py | 8 - requirements-1.3.txt | 156 ----- requirements-debian.txt | 5 - requirements-dev.txt | 4 +- requirements-new.txt | 9 - requirements.txt | 58 +- run-container-fg | 81 +++ wsgi.py | 0 53 files changed, 2720 insertions(+), 543 deletions(-) create mode 100644 .dockerignore create mode 100755 app/init.sh create mode 100644 app/local_settings.py.sample create mode 100755 app/wait.sh create mode 100644 app/worker.py create mode 100644 app/wsgi.ini create mode 100755 app/wsgi.sh create mode 100755 bin/build/doc.sh create mode 100755 bin/build/front.sh create mode 100755 bin/build/graph.sh create mode 100755 bin/build/local/messages.sh create mode 100755 bin/build/local/setup_lib.sh create mode 100755 bin/build/local/setup_lib_py2.sh create mode 100755 bin/build/messages.sh create mode 100755 bin/build/readme.sh create mode 100755 bin/misc/fix/fs_migrate.sh create mode 100755 bin/misc/fix_var_perms.sh create mode 100755 bin/misc/gulp.sh create mode 100755 bin/misc/poll_twitter.sh create mode 100755 bin/misc/sql/latin1_to_utf8.py create mode 100755 bin/misc/sql/latin1_to_utf8_tester.py create mode 100644 bin/misc/statifier.py create mode 100755 bin/misc/statifier.sh create mode 100644 bin/misc/wait-for-it/.gitignore create mode 100644 bin/misc/wait-for-it/.travis.yml create mode 100644 bin/misc/wait-for-it/LICENSE create mode 100644 bin/misc/wait-for-it/README.md create mode 100644 bin/misc/wait-for-it/test/wait-for-it.py create mode 100755 bin/misc/wait-for-it/wait-for-it.sh create mode 100644 debian-packages.txt create mode 100644 docker-compose-dev.yml create mode 100644 env/debug.env create mode 100644 etc/apache2-dev.conf create mode 100644 etc/postgresql.conf delete mode 100644 example/__init__.py delete mode 100644 example/manage.py delete mode 100644 example/settings.py delete mode 100644 example/urls.py delete mode 100644 example/wsgi.py delete mode 100644 requirements-1.3.txt delete mode 100644 requirements-debian.txt delete mode 100644 requirements-new.txt create mode 100755 run-container-fg delete mode 100644 wsgi.py diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..fec19819 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.git +*.pyc +*.egg-info +data/ +env/ +tmp/ +var/ +**/.sass-cache +*.sock \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3d195fcc..98893fff 100644 --- a/.gitignore +++ b/.gitignore @@ -4,18 +4,18 @@ # Packages *.egg *.egg-info -dist -build eggs parts -bin var sdist develop-eggs +node_modules .installed.cfg .directory *.e4p select2-4.0.5 +.env +local_settings.py # Installer logs pip-log.txt @@ -26,3 +26,9 @@ pip-log.txt #Mr Developer .mr.developer.cfg + +#python venv +py_env +prod.env + +README_pilot.rst \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 9c271d52..f3ff1f0a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,37 +14,50 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM python:2 +FROM python:3 MAINTAINER Guillaume Pellerin ENV PYTHONUNBUFFERED 1 RUN mkdir -p /srv/app -RUN mkdir -p /srv/lib/ -RUN mkdir -p /srv/lib/telemeta +RUN mkdir -p /srv/lib/teleforma WORKDIR /srv RUN apt-get update && apt-get install -y apt-transport-https # COPY etc/apt/sources.list /etc/apt/ -COPY requirements-debian.txt /srv +COPY debian-packages.txt /srv RUN apt-get update && \ - DEBIAN_PACKAGES=$(egrep -v "^\s*(#|$)" /srv/requirements-debian.txt) && \ + DEBIAN_PACKAGES=$(egrep -v "^\s*(#|$)" /srv/debian-packages.txt) && \ apt-get install -y --force-yes $DEBIAN_PACKAGES && \ echo fr_FR.UTF-8 UTF-8 >> /etc/locale.gen && \ locale-gen && \ apt-get clean +RUN pip3 install -U pip + ENV LANG fr_FR.UTF-8 ENV LANGUAGE fr_FR:fr ENV LC_ALL fr_FR.UTF-8 COPY requirements.txt /srv -RUN pip install -r requirements.txt +RUN pip3 install -r requirements.txt COPY requirements-dev.txt /srv -RUN pip install -r requirements-dev.txt --src /srv/lib +ARG dev=0 +RUN if [ "${dev}" = "1" ]; then pip3 install -r requirements-dev.txt; fi +RUN if [ "${dev}" = "1" ]; then apt-get -y install less nano postgresql-client redis-tools; fi + +COPY lib /srv/lib +COPY bin/build/local/setup_lib.sh /srv +RUN /srv/setup_lib.sh + +WORKDIR /srv/src/teleforma +COPY setup.py /srv/src/teleforma +COPY teleforma /srv/src/teleforma +COPY README.rst /srv/src/teleforma +RUN python setup.py develop WORKDIR /srv/app diff --git a/app/__init__.py b/app/__init__.py index e69de29b..12176181 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# +# Copyright (c) 2016-2017 Ircam +# Copyright (c) 2016-2017 Guillaume Pellerin +# Copyright (c) 2016-2017 Emilie Zawadzki + +# This file is part of mezzanine-organization. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + diff --git a/app/init.sh b/app/init.sh new file mode 100755 index 00000000..1aa59bf6 --- /dev/null +++ b/app/init.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# paths +app='/srv/app' +manage=$app'/manage.py' + +python $manage migrate --noinput +python $manage create-admin-user +python $manage create-default-organization +python $manage build-front + +# @todo searching every fixtures file in each folder +python $manage loaddata $app/organization/job/fixtures/organization-job.json +python $manage loaddata $app/organization/projects/fixtures/organization-projects-repositorysystems.json + +bash /srv/doc/build.sh diff --git a/app/local_settings.py.sample b/app/local_settings.py.sample new file mode 100644 index 00000000..054934a0 --- /dev/null +++ b/app/local_settings.py.sample @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- +# +# Copyright (c) 2016-2017 Ircam +# Copyright (c) 2016-2017 Guillaume Pellerin +# Copyright (c) 2016-2017 Emilie Zawadzki + +# This file is part of mezzanine-organization. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import os +from django.utils.translation import ugettext_lazy as _ +from datetime import datetime, date + +DEBUG = True if os.environ.get('DEBUG') == 'True' else False + +# -*- coding: utf-8 -*- +# +# Copyright (c) 2016-2017 Ircam +# Copyright (c) 2016-2017 Guillaume Pellerin +# Copyright (c) 2016-2017 Emilie Zawadzki + +# This file is part of mezzanine-organization. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import os +from django.utils.translation import ugettext_lazy as _ +from datetime import datetime, date + +DEBUG = True if os.environ.get('DEBUG') == 'True' else False + +ADMINS = ( + ('Your Name', 'contact@you.org'), +) + +# Make these unique, and don't share it with anybody. +SECRET_KEY = "H7665jhuyUTGuhuUYT6è-ertyezçuàçi'09Iikrpokfàçir" +NEVERCACHE_KEY = "87654RFGhju7665rdfGyuàiPOpkM;?NbGFr'(3(ezrTYuiJK" + +EMAIL_HOST = 'localhost' # please specify your smtp server address +EMAIL_PORT = '25' +SERVER_EMAIL = 'no-reply@no-reply.org' # a no reply address +DEFAULT_FROM_EMAIL = 'default@default.org' # another address, default one +DEFAULT_TO_EMAIL = 'recipient@recipient.org' # default recipient, for your tests +EMAIL_SUBJECT_PREFIX = "[PREFIX]" # prefix title in email +SITE_TITLE = 'Your Site' +SITE_TAGLINE = 'This is a Mezzo site' + +AUTHENTICATION_BACKENDS = ( + # "organization.core.backend.OrganizationLDAPBackend", + "mezzanine.core.auth_backends.MezzanineBackend", + "guardian.backends.ObjectPermissionBackend", +) diff --git a/app/manage.py b/app/manage.py index c632a8a3..46e20ddd 100755 --- a/app/manage.py +++ b/app/manage.py @@ -1,9 +1,29 @@ #!/usr/bin/env python -import os, sys +# -*- coding: utf-8 -*- +# +# Copyright (c) 2016-2017 Ircam +# Copyright (c) 2016-2017 Guillaume Pellerin +# Copyright (c) 2016-2017 Emilie Zawadzki + +# This file is part of mezzanine-organization. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import os +import sys if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") - from django.core.management import execute_from_command_line - execute_from_command_line(sys.argv) diff --git a/app/urls.py b/app/urls.py index 8bacff02..7f365327 100644 --- a/app/urls.py +++ b/app/urls.py @@ -1,29 +1,41 @@ # -*- coding: utf-8 -*- -from django.conf.urls.defaults import * +import os +from django.conf.urls import include, url +from django.conf import settings # Uncomment the next two lines to enable the admin: from django.contrib import admin +from django.http import HttpResponse +from django.views.i18n import JavaScriptCatalog + admin.autodiscover() -js_info_dict = { - 'packages': ('telemeta','telecaster'), -} +js_info_dict = ['teleforma'] + +if settings.DEBUG_TOOLBAR: + import debug_toolbar -urlpatterns = patterns('', +urlpatterns = [ # Example: # (r'^sandbox/', include('sandbox.foo.urls')), # Uncomment the admin/doc line below and add 'django.contrib.admindocs' # to INSTALLED_APPS to enable admin documentation: # (r'^admin/doc/', include('django.contrib.admindocs.urls')), - url(r'^admin/django/', include(admin.site.urls)), + url(r'^admin/', admin.site.urls), # TeleForma - (r'^', include('teleforma.urls')), - (r'^telecaster/', include('telecaster.urls')), + url(r'^', include('teleforma.urls')), # Languages - (r'^i18n/', include('django.conf.urls.i18n')), - (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict), + url(r'^i18n/', include('django.conf.urls.i18n')), + url(r'^jsi18n/$', JavaScriptCatalog.as_view(packages=js_info_dict), name="js_catalog"), + url(r'^robots\.txt$', lambda r: HttpResponse( + "User-agent: *\nDisallow: /", mimetype="text/plain")), + + url(r'^tinymce/', include('tinymce.urls')), + #url(r'^pdfviewer/', include('webviewer.urls')), + url(r'^pdfannotator/', include('pdfannotator.urls')), + url(r'^messages/', include('postman.urls', namespace='postman')), +] + ([url(r'^__debug__/', include(debug_toolbar.urls)),] if settings.DEBUG_TOOLBAR else []) -) diff --git a/app/wait.sh b/app/wait.sh new file mode 100755 index 00000000..0d92f08c --- /dev/null +++ b/app/wait.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +/srv/bin/misc/wait-for-it/wait-for-it.sh -h $DB_HOST -p $DB_PORT; diff --git a/app/worker.py b/app/worker.py new file mode 100644 index 00000000..6d06656d --- /dev/null +++ b/app/worker.py @@ -0,0 +1,24 @@ +from __future__ import absolute_import +import os, sys +from celery import Celery +from django.conf import settings + +sys.path.append(os.path.dirname('.')) +sys.path.append(os.path.dirname('..')) + +# set the default Django settings module for the 'celery' program. +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings') + +app = Celery('app') + +# Using a string here means the worker will not have to +# pickle the object when using Windows. +app.config_from_object('django.conf:settings') +app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) +# app.conf.update( +# CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend', +# ) + +@app.task(bind=True) +def debug_task(self): + print('Request: {0!r}'.format(self.request)) diff --git a/app/wsgi.ini b/app/wsgi.ini new file mode 100644 index 00000000..374f1694 --- /dev/null +++ b/app/wsgi.ini @@ -0,0 +1,58 @@ +[uwsgi] + +socket = /var/run/app/wsgi.sock +chdir = /srv/app/ +module = wsgi +touch-reload = /srv/app/wsgi.py +chmod-socket = 664 + +uid = www-data +gid = www-data + +strict = true +master = true +enable-threads = true +vacuum = true ; Delete sockets during shutdown +single-interpreter = true +die-on-term = true ; Shutdown when receiving SIGTERM (default is respawn) +need-app = true + +# Close fds on fork (don't allow subprocess to mess with parent's fds) +close-on-exec = true +close-on-exec2 = true + + +disable-logging = false ; Disable built-in logging +log-4xx = true ; but log 4xx's anyway +log-5xx = true ; and 5xx's +logger = file:/var/log/app/app.log + +harakiri = 300 ; forcefully kill workers after 60 seconds +#py-callos-afterfork = true ; allow workers to trap signals + +max-requests = 20000 ; Restart workers after this many requests +max-worker-lifetime = 18000 ; Restart workers after this many seconds +reload-on-rss = 4096 ; Restart workers after this much resident memory +worker-reload-mercy = 60 ; How long to wait before forcefully killing workers + +# We don't expect abuse so lets have fastest respawn possible +forkbomb-delay = 0 + +# Enable an accept mutex for a more balanced worker load +thunder-lock = true + +cheaper-algo = busyness +processes = 128 ; Maximum number of workers allowed +#threads = 2 +cheaper = 24 ; Minimum number of workers allowed +cheaper-initial = 24 ; Workers created at startup +cheaper-overload = 1 ; Length of a cycle in seconds +cheaper-step = 8 ; How many workers to spawn at a time + +cheaper-busyness-multiplier = 30 ; How many cycles to wait before killing workers +cheaper-busyness-min = 20 ; Below this threshold, kill workers (if stable for multiplier cycles) +cheaper-busyness-max = 70 ; Above this threshold, spawn new workers +cheaper-busyness-backlog-alert = 10 ; Spawn emergency workers if more than this many requests are waiting in the queue +cheaper-busyness-backlog-step = 2 ; How many emergency workers to create if there are too many requests in the queue + + diff --git a/app/wsgi.py b/app/wsgi.py index d71b3b73..e63f8351 100644 --- a/app/wsgi.py +++ b/app/wsgi.py @@ -1,8 +1,31 @@ -import os +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# Copyright (c) 2016-2017 Ircam +# Copyright (c) 2016-2017 Guillaume Pellerin +# Copyright (c) 2016-2017 Emilie Zawadzki + +# This file is part of mezzanine-organization. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . -# This application object is used by the development server -# as well as any WSGI server configured to use this file. +# -*- coding: utf-8 -*- + +import os +import sys from django.core.wsgi import get_wsgi_application + +sys.path.append(os.path.dirname('.')) +os.environ.setdefault("DJANGO_SETTINGS_MODULE", 'settings') application = get_wsgi_application() diff --git a/app/wsgi.sh b/app/wsgi.sh new file mode 100755 index 00000000..f9cd6289 --- /dev/null +++ b/app/wsgi.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +# paths +app='/srv/app' +manage=$app'/manage.py' +static='/srv/static/' +media='/srv/media/' +src='/srv/src/' +uwsgi_log='/var/log/uwsgi/app.log' +debug_log='/var/log/app/debug.log' + +# patterns='*.js;*.css;*.jpg;*.jpeg;*.gif;*.png;*.svg;*.ttf;*.eot;*.woff;*.woff2' + +# Install a package in development mode +# without rebuidling docker image. +# You need at first checkout your sources in 'lib' folder +# in host project side, then run : +# pip install -e /srv/lib/mypackage... +# pip3 install -U uwsgi + +# Install (staging) libs +# /srv/bin/build/local/setup_lib.sh + +# waiting for other services +sh $app/wait.sh + +# django setup +#python $manage wait-for-db + +# initial setup +# if [ ! -f .init ]; then +# bash $app/bin/init.sh +# touch .init +# fi + +# app start +if [ "$1" = "--runserver" ]; then + python $manage runserver 0.0.0.0:8000 +else + # static files auto update + # watchmedo shell-command --patterns="$patterns" --recursive \ + # --command='python '$manage' collectstatic --noinput' $app & + + python $manage collectstatic --noinput + + chown -R www-data: $debug_log + + uwsgi /srv/app/wsgi.ini +fi diff --git a/bin/build/doc.sh b/bin/build/doc.sh new file mode 100755 index 00000000..abc248de --- /dev/null +++ b/bin/build/doc.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose run app bash /srv/doc/build.sh diff --git a/bin/build/front.sh b/bin/build/front.sh new file mode 100755 index 00000000..c4157f53 --- /dev/null +++ b/bin/build/front.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose exec -T app python /srv/app/manage.py build-front $1 diff --git a/bin/build/graph.sh b/bin/build/graph.sh new file mode 100755 index 00000000..b5cda09e --- /dev/null +++ b/bin/build/graph.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose run app python /srv/app/manage.py graph_models organization-core organization-media organization-pages organization.network organization.magazine organization.projects organization.agenda organization.shop organization.job > /srv/doc/graph/mezzanine-organization.dot diff --git a/bin/build/local/messages.sh b/bin/build/local/messages.sh new file mode 100755 index 00000000..5fe3892c --- /dev/null +++ b/bin/build/local/messages.sh @@ -0,0 +1,10 @@ +# docker-compose run app python manage.py compilemessages + +cd /srv + +find $(pwd) -type d -name 'locale' -print | while read f; do + cd "$f" && cd .. + echo $(pwd) + django-admin makemessages -l fr + django-admin compilemessages +done diff --git a/bin/build/local/setup_lib.sh b/bin/build/local/setup_lib.sh new file mode 100755 index 00000000..de62e568 --- /dev/null +++ b/bin/build/local/setup_lib.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Exit when any command fails +# We need to stop build if pip fails +set -e + +for module in `ls /srv/lib/`; do + cd /srv/lib/$module + if [ -f 'requirements.txt' ]; then + pip3 install -r requirements.txt + elif [ -f 'setup.py' ]; then + pip3 install -e . + fi +done diff --git a/bin/build/local/setup_lib_py2.sh b/bin/build/local/setup_lib_py2.sh new file mode 100755 index 00000000..c037a260 --- /dev/null +++ b/bin/build/local/setup_lib_py2.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Exit when any command fails +# We need to stop build if pip fails +set -e + +for module in `ls /srv/lib/`; do + cd /srv/lib/$module + if [ -f 'requirements.txt' ]; then + pip install -r requirements.txt + elif [ -f 'setup.py' ]; then + pip install -e . + fi +done diff --git a/bin/build/messages.sh b/bin/build/messages.sh new file mode 100755 index 00000000..cea64eec --- /dev/null +++ b/bin/build/messages.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose run app bash /srv/bin/build/local/messages.sh diff --git a/bin/build/readme.sh b/bin/build/readme.sh new file mode 100755 index 00000000..a22fb8cc --- /dev/null +++ b/bin/build/readme.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +cd "$(dirname "$0")"/../../ + +cat doc/src/overview.rst doc/src/architecture.rst doc/src/install.rst doc/src/development.rst doc/src/maintenance.rst doc/src/copyright.rst doc/src/license.rst > README.rst + +echo "Build finished. The README.rst file is up to date." diff --git a/bin/misc/fix/fs_migrate.sh b/bin/misc/fix/fs_migrate.sh new file mode 100755 index 00000000..9ec9fcf1 --- /dev/null +++ b/bin/misc/fix/fs_migrate.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +docker-compose stop +mv data var +mkdir var/lib +sudo mv var/postgresql var/lib +sudo mv var/external var/opt +sudo mv var/var/log var +sudo rm -rf var/var diff --git a/bin/misc/fix_var_perms.sh b/bin/misc/fix_var_perms.sh new file mode 100755 index 00000000..f0c5b1b6 --- /dev/null +++ b/bin/misc/fix_var_perms.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +cd "$(dirname "$0")"/../../ + +# We need to chown folders so that they can be used by the $USER (with an exception on Darwin) +if ! uname -a | grep Darwin > /dev/null; then + + declare -a arr=("var/media" "var/backup") + + for folder in "${arr[@]}"; do + INFO=( $(stat -L -c "%a %G %U" $folder) ) + OWNER=${INFO[2]} + if [ "$OWNER" != "$USER" ]; then + sudo chown -R $USER $folder + fi + done +fi diff --git a/bin/misc/gulp.sh b/bin/misc/gulp.sh new file mode 100755 index 00000000..dcff3d0b --- /dev/null +++ b/bin/misc/gulp.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose run app python /srv/app/manage.py gulp diff --git a/bin/misc/poll_twitter.sh b/bin/misc/poll_twitter.sh new file mode 100755 index 00000000..fc4b929f --- /dev/null +++ b/bin/misc/poll_twitter.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose exec -T app python /srv/app/manage.py poll_twitter --force diff --git a/bin/misc/sql/latin1_to_utf8.py b/bin/misc/sql/latin1_to_utf8.py new file mode 100755 index 00000000..97f1bc10 --- /dev/null +++ b/bin/misc/sql/latin1_to_utf8.py @@ -0,0 +1,31 @@ +#!/usr/bin/python3.5 + +import os +from chardet import detect +from pyutil import filereplace +srcfile = "./var/backup/mariadb.dump" +trgfile = "./var/backup/mariadb2.dump" + +# get file encoding type +def get_encoding_type(file): + with open(file, 'rb') as f: + rawdata = f.read() + return detect(rawdata)['encoding'] + +from_codec = get_encoding_type(srcfile) + +# add try: except block for reliability +try: + with open(srcfile, 'r', encoding=from_codec) as f, open(trgfile, 'w', encoding='utf-8') as e: + text = f.read() # for small files, for big use chunks + e.write(text) + + os.remove(srcfile) # remove old encoding file + os.rename(trgfile, srcfile) # rename new encoding +except UnicodeDecodeError: + print('Decode Error') +except UnicodeEncodeError: + print('Encode Error') + +# replace charset latin1 to ut8 +filereplace(srcfile,"CHARSET=latin1","CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci") \ No newline at end of file diff --git a/bin/misc/sql/latin1_to_utf8_tester.py b/bin/misc/sql/latin1_to_utf8_tester.py new file mode 100755 index 00000000..6aa629d3 --- /dev/null +++ b/bin/misc/sql/latin1_to_utf8_tester.py @@ -0,0 +1,107 @@ +#!/usr/bin/python + +import pandas as pd +import requests +from subprocess import check_output, CalledProcessError +domain_prod = "http://brahms.ircam.fr" +domain_dev = "http://localhost:9030" +session_option = "-H 'Cookie: sessionid={0}'" +session_prod = "gd9zgu68wo3lptwfhqqkawo59w0486rz" +session_dev = "qh25niyvxetuouxwmafdpvxlc8eldp5u" + +analyse_urls = [ + # analyse - published + "/analyses/dialogue/", + "/analyses/metallics/", + "/analyses/noanoa/", + "/analyses/traiettoria/", + "/analyses/Mortuos/", + "/analyses/Stria/", + "/analyses/Prologue/", + # analyse - draft + "/analyses/Etymo/", + "/analyses/EnTrance/", + "/analyses/test/", + "/analyses/test2/", + # composer + "/witold-lutoslawski", + "/wlodzimierz-kotonski", + "/omer-hulusier", + "/necil-kazim-akses", + "/wenjing-guo", + "/rene-alix", + "/axel-borup-jrgensen", + "/per-nrgard", + "/pierre-boulez", + # events_event + "/admin/events/event/13/change/", + "/admin/events/event/23/change/", + #events_hall + "/admin/events/hall/5/change/", + #events_manifestation + "/admin/events/manifestation/3/change/", + #repertoire_analysis_definitions + "/admin/repertoire/definition/32/change/", + #robots_rule + "/admin/robots/rule/1/change/", + #robots_url + "/admin/robots/url/3/change/", + #utils_citysidney + "/admin/utils/citysidney/3/change/", + #utils_corporatebody + "/admin/utils/corporatebody/127/change/", + #utils_countrysidney + "/admin/utils/countrysidney/230/change/", + #utils_equipmentbrand + "/admin/utils/equipmentbrand/127/change/", + #utils_equipmentcategory + "admin/utils/equipmentcategory/4/change/", + #utils_equipmentreference + "/admin/utils/equipmentreference/422/change/", + #utils_error + "/admin/utils/error/1703/change/", + #utils_lang + "/admin/utils/lang/1/change/", + #utils_naturalperson + "/admin/utils/naturalperson/6791/change/", + "/admin/utils/naturalperson/6806/change/", + "/admin/utils/naturalperson/6892/change/", + #utils_personfunction + "/admin/utils/personfunction/12/change/", + #validation_fichedevalidation + "/admin/validation/fichedevalidation/74/change/", + "/admin/validation/fichedevalidation/63/change/", + #works_electronic + "/admin/works/electronic/11/change/", + "/admin/works/electronic/5/change/", + #works_filetype + "/admin/works/filetype/20/change/", + #works_version + "/admin/works/version/1345/change/", + "/admin/works/version/990/change/", + #works_versionfile + "/admin/works/versionfile/2665/change/", + "/admin/works/versionfile/9250/change/", + #works_worksidney + "/admin/works/worksidney/6970/change/", + "/admin/works/worksidney/18566/change/", + "/admin/works/worksidney/7549/change/", + "/admin/works/worksidney/25673/change/", + "/admin/works/worksidney/10575/change/", +] + +def get_curl_command(domain, url, session): + return "curl -s '{0}' {1}".format(domain + url, session_option.format(session)) + +for url in analyse_urls: + print("==========================================================================") + print("url ", url) + print("-----------------------------------------") + try: + curl_prod = get_curl_command(domain_prod, url, session_prod) + curl_dev = get_curl_command(domain_dev, url, session_dev) + check_output("diff <("+curl_prod+") <("+ curl_dev + ")", + shell=True, executable='/bin/bash', universal_newlines=True) + except CalledProcessError as e: + print(e.output, e.returncode) + diff --git a/bin/misc/statifier.py b/bin/misc/statifier.py new file mode 100644 index 00000000..641cd057 --- /dev/null +++ b/bin/misc/statifier.py @@ -0,0 +1,79 @@ +#!/usr/bin/python3 + +import os +from optparse import OptionParser +import shutil + +class Statifier: + + def __init__(self, domain, languages): + self.domain = domain + self.languages = languages + self.replace_dict = { + } + + def wget(self, language, dir): + command = 'wget -q --mirror -p --adjust-extension --header="Accept-Language: %s" -e robots=off --base=./ -k -P %s https://%s' % (language, dir, self.domain) + # print(command) + os.system(command) + + def sed(self, dir, rule): + command = "find %s -type f -print0 | xargs -0 sed -r -i -e '%s'" % (dir, rule) + # print(command) + os.system(command) + + def fix_languages(self, language): + for root, dirs, files in os.walk(self.domain): + for filename in files: + name = os.path.splitext(filename)[0] + ext = os.path.splitext(filename)[1][1:] + if ext == 'html': + path = root + os.sep + filename + rel_root = root.split('/')[2:] + rel_root = language + '/' + '/'.join(rel_root) + + f = open(path, 'rt') + content = f.read() + f.close() + + s_in = '
' % self.domain + s_out = '' + content = content.replace(s_in, s_out) + + s_in = '' % (language, language.upper()) + s_out = '' + s_in + '' + s_out = s_out % rel_root + content = content.replace(s_in, s_out) + + s_in = '' % (language, language.upper()) + s_out = '' + s_in + '' + s_out = s_out % rel_root + content = content.replace(s_in, s_out) + + f = open(path, 'wt') + f.write(content) + f.close() + + def main(self): + for language in self.languages: + self.wget(language, self.domain) + shutil.move(self.domain + os.sep + self.domain, self.domain + os.sep + language) + + for language in self.languages: + self.fix_languages(language) + + +def main(): + parser = OptionParser() + parser.add_option("-d", "--domain", dest="domain", help="domain") + parser.add_option("-l", "--languages", + dest="languages", nargs=2, + help="languages") + (options, args) = parser.parse_args() + + s = Statifier(options.domain, options.languages) + s.main() + +if __name__ == "__main__": + main() + diff --git a/bin/misc/statifier.sh b/bin/misc/statifier.sh new file mode 100755 index 00000000..262c24b2 --- /dev/null +++ b/bin/misc/statifier.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +DOMAIN=$1 + +mkdir $DOMAIN +cd $DOMAIN + +LANG=en +wget -q --mirror -p --adjust-extension --header='Accept-Language: en' -e robots=off --base=./ -k -P ./ https://$DOMAIN +mv $DOMAIN $LANG +find $LANG/ -type f -print0 | xargs -0 sed -r -i -e 's,,,g' +find $LANG/ -type f -print0 | xargs -0 sed -r -i -e 's,,,g' +find $LANG/ -type f -print0 | xargs -0 sed -r -i -e 's,
,,g' + +LANG=fr +wget -q --mirror -p --adjust-extension --header='Accept-Language: fr' -e robots=off --base=./ -k -P ./ https://$DOMAIN +mv $DOMAIN $LANG +find $LANG -type f -print0 | xargs -0 sed -r -i -e 's,
,,g' +find $LANG -type f -print0 | xargs -0 sed -r -i -e 's,,,g' +find $LANG -type f -print0 | xargs -0 sed -r -i -e 's,
,,g' diff --git a/bin/misc/wait-for-it/.gitignore b/bin/misc/wait-for-it/.gitignore new file mode 100644 index 00000000..3e7e9693 --- /dev/null +++ b/bin/misc/wait-for-it/.gitignore @@ -0,0 +1,3 @@ +**/*.pyc +.pydevproject + diff --git a/bin/misc/wait-for-it/.travis.yml b/bin/misc/wait-for-it/.travis.yml new file mode 100644 index 00000000..30a81383 --- /dev/null +++ b/bin/misc/wait-for-it/.travis.yml @@ -0,0 +1,7 @@ +language: python +python: + - "2.7" + +script: + - python test/wait-for-it.py + diff --git a/bin/misc/wait-for-it/LICENSE b/bin/misc/wait-for-it/LICENSE new file mode 100644 index 00000000..bd18d0c4 --- /dev/null +++ b/bin/misc/wait-for-it/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) +Copyright (c) 2016 Giles Hall + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/bin/misc/wait-for-it/README.md b/bin/misc/wait-for-it/README.md new file mode 100644 index 00000000..4891736f --- /dev/null +++ b/bin/misc/wait-for-it/README.md @@ -0,0 +1,65 @@ +## wait-for-it + +`wait-for-it.sh` is a pure bash script that will wait on the availability of a host and TCP port. It is useful for synchronizing the spin-up of interdependent services, such as linked docker containers. Since it is a pure bash script, it does not have any external dependencies. + +## Usage + +``` +wait-for-it.sh host:port [-s] [-t timeout] [-- command args] +-h HOST | --host=HOST Host or IP under test +-p PORT | --port=PORT TCP port under test + Alternatively, you specify the host and port as host:port +-s | --strict Only execute subcommand if the test succeeds +-q | --quiet Don't output any status messages +-t TIMEOUT | --timeout=TIMEOUT + Timeout in seconds, zero for no timeout +-- COMMAND ARGS Execute command with args after the test finishes +``` + +## Examples + +For example, let's test to see if we can access port 80 on www.google.com, and if it is available, echo the message `google is up`. + +``` +$ ./wait-for-it.sh www.google.com:80 -- echo "google is up" +wait-for-it.sh: waiting 15 seconds for www.google.com:80 +wait-for-it.sh: www.google.com:80 is available after 0 seconds +google is up +``` + +You can set your own timeout with the `-t` or `--timeout=` option. Setting the timeout value to 0 will disable the timeout: + +``` +$ ./wait-for-it.sh -t 0 www.google.com:80 -- echo "google is up" +wait-for-it.sh: waiting for www.google.com:80 without a timeout +wait-for-it.sh: www.google.com:80 is available after 0 seconds +google is up +``` + +The subcommand will be executed regardless if the service is up or not. If you wish to execute the subcommand only if the service is up, add the `--strict` argument. In this example, we will test port 81 on www.google.com which will fail: + +``` +$ ./wait-for-it.sh www.google.com:81 --timeout=1 --strict -- echo "google is up" +wait-for-it.sh: waiting 1 seconds for www.google.com:81 +wait-for-it.sh: timeout occurred after waiting 1 seconds for www.google.com:81 +wait-for-it.sh: strict mode, refusing to execute subprocess +``` + +If you don't want to execute a subcommand, leave off the `--` argument. This way, you can test the exit condition of `wait-for-it.sh` in your own scripts, and determine how to proceed: + +``` +$ ./wait-for-it.sh www.google.com:80 +wait-for-it.sh: waiting 15 seconds for www.google.com:80 +wait-for-it.sh: www.google.com:80 is available after 0 seconds +$ echo $? +0 +$ ./wait-for-it.sh www.google.com:81 +wait-for-it.sh: waiting 15 seconds for www.google.com:81 +wait-for-it.sh: timeout occurred after waiting 15 seconds for www.google.com:81 +$ echo $? +124 +``` + +## Community + +*Debian*: There is a [Debian package](https://tracker.debian.org/pkg/wait-for-it). diff --git a/bin/misc/wait-for-it/test/wait-for-it.py b/bin/misc/wait-for-it/test/wait-for-it.py new file mode 100644 index 00000000..e06fb8c8 --- /dev/null +++ b/bin/misc/wait-for-it/test/wait-for-it.py @@ -0,0 +1,179 @@ +import unittest +import shlex +from subprocess import Popen, PIPE +import os +import sys +import socket +import re + +MISSING_ARGS_TEXT = "Error: you need to provide a host and port to test." +HELP_TEXT = "Usage:" # Start of help text +DIVIDE_LINE = '-'*71 # Output line of dashes + + +class TestWaitForIt(unittest.TestCase): + """ + TestWaitForIt tests the wait-for-it.sh shell script. + The wait-for-it.sh script is assumed to be in the parent directory to + the test script. + """ + + def execute(self, cmd): + """Executes a command and returns exit code, STDOUT, STDERR""" + args = shlex.split(cmd) + proc = Popen(args, stdout=PIPE, stderr=PIPE) + out, err = proc.communicate() + exitcode = proc.returncode + return exitcode, out, err + + def open_local_port(self, host="localhost", port=8929, timeout=5): + s = socket.socket() + s.bind((host, port)) + s.listen(timeout) + return s + + def check_args(self, args, stdout_regex, stderr_regex, exitcode): + command = self.wait_script + " " + args + actual_exitcode, out, err = self.execute(command) + + # Check stderr + msg = ("Failed check that STDERR:\n" + + DIVIDE_LINE + "\n" + err + "\n" + DIVIDE_LINE + + "\nmatches:\n" + + DIVIDE_LINE + "\n" + stderr_regex + "\n" + DIVIDE_LINE) + self.assertIsNotNone(re.match(stderr_regex, err, re.DOTALL), msg) + + # Check STDOUT + msg = ("Failed check that STDOUT:\n" + + DIVIDE_LINE + "\n" + out + "\n" + DIVIDE_LINE + + "\nmatches:\n" + + DIVIDE_LINE + "\n" + stdout_regex + "\n" + DIVIDE_LINE) + self.assertIsNotNone(re.match(stdout_regex, out, re.DOTALL), msg) + + # Check exit code + self.assertEqual(actual_exitcode, exitcode) + + def setUp(self): + script_path = os.path.dirname(sys.argv[0]) + parent_path = os.path.abspath(os.path.join(script_path, os.pardir)) + self.wait_script = os.path.join(parent_path, "wait-for-it.sh") + + def test_no_args(self): + """ + Check that no aruments returns the missing args text and the + correct return code + """ + self.check_args( + "", + "^$", + MISSING_ARGS_TEXT, + 1 + ) + # Return code should be 1 when called with no args + exitcode, out, err = self.execute(self.wait_script) + self.assertEqual(exitcode, 1) + + def test_help(self): + """ Check that help text is printed with --help argument """ + self.check_args( + "--help", + "", + HELP_TEXT, + 1 + ) + + def test_no_port(self): + """ Check with missing port argument """ + self.check_args( + "--host=localhost", + "", + MISSING_ARGS_TEXT, + 1 + ) + + def test_no_host(self): + """ Check with missing hostname argument """ + self.check_args( + "--port=80", + "", + MISSING_ARGS_TEXT, + 1 + ) + + def test_host_port(self): + """ Check that --host and --port args work correctly """ + soc = self.open_local_port(port=8929) + self.check_args( + "--host=localhost --port=8929 --timeout=1", + "", + "wait-for-it.sh: waiting 1 seconds for localhost:8929", + 0 + ) + soc.close() + + def test_combined_host_port(self): + """ + Tests that wait-for-it.sh returns correctly after establishing a + connectionm using combined host and ports + """ + soc = self.open_local_port(port=8929) + self.check_args( + "localhost:8929 --timeout=1", + "", + "wait-for-it.sh: waiting 1 seconds for localhost:8929", + 0 + ) + soc.close() + + def test_port_failure_with_timeout(self): + """ + Note exit status of 124 is exected, passed from the timeout command + """ + self.check_args( + "localhost:8929 --timeout=1", + "", + ".*timeout occurred after waiting 1 seconds for localhost:8929", + 124 + ) + + def test_command_execution(self): + """ + Checks that a command executes correctly after a port test passes + """ + soc = self.open_local_port(port=8929) + self.check_args( + "localhost:8929 -- echo \"CMD OUTPUT\"", + "CMD OUTPUT", + ".*wait-for-it.sh: localhost:8929 is available after 0 seconds", + 0 + ) + soc.close() + + def test_failed_command_execution(self): + """ + Check command failure. The command in question outputs STDERR and + an exit code of 2 + """ + soc = self.open_local_port(port=8929) + self.check_args( + "localhost:8929 -- ls not_real_file", + "", + ".*No such file or directory\n", + 2 + ) + soc.close() + + def test_command_after_connection_failure(self): + """ + Test that a command still runs even if a connection times out + and that the return code is correct for the comand being run + """ + self.check_args( + "localhost:8929 --timeout=1 -- echo \"CMD OUTPUT\"", + "CMD OUTPUT", + ".*timeout occurred after waiting 1 seconds for localhost:8929", + 0 + ) + +if __name__ == '__main__': + unittest.main() diff --git a/bin/misc/wait-for-it/wait-for-it.sh b/bin/misc/wait-for-it/wait-for-it.sh new file mode 100755 index 00000000..071c2bee --- /dev/null +++ b/bin/misc/wait-for-it/wait-for-it.sh @@ -0,0 +1,178 @@ +#!/usr/bin/env bash +# Use this script to test if a given TCP host/port are available + +WAITFORIT_cmdname=${0##*/} + +echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi } + +usage() +{ + cat << USAGE >&2 +Usage: + $WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args] + -h HOST | --host=HOST Host or IP under test + -p PORT | --port=PORT TCP port under test + Alternatively, you specify the host and port as host:port + -s | --strict Only execute subcommand if the test succeeds + -q | --quiet Don't output any status messages + -t TIMEOUT | --timeout=TIMEOUT + Timeout in seconds, zero for no timeout + -- COMMAND ARGS Execute command with args after the test finishes +USAGE + exit 1 +} + +wait_for() +{ + if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then + echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT" + else + echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout" + fi + WAITFORIT_start_ts=$(date +%s) + while : + do + if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then + nc -z $WAITFORIT_HOST $WAITFORIT_PORT + WAITFORIT_result=$? + else + (echo > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1 + WAITFORIT_result=$? + fi + if [[ $WAITFORIT_result -eq 0 ]]; then + WAITFORIT_end_ts=$(date +%s) + echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds" + break + fi + sleep 1 + done + return $WAITFORIT_result +} + +wait_for_wrapper() +{ + # In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692 + if [[ $WAITFORIT_QUIET -eq 1 ]]; then + timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT & + else + timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT & + fi + WAITFORIT_PID=$! + trap "kill -INT -$WAITFORIT_PID" INT + wait $WAITFORIT_PID + WAITFORIT_RESULT=$? + if [[ $WAITFORIT_RESULT -ne 0 ]]; then + echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT" + fi + return $WAITFORIT_RESULT +} + +# process arguments +while [[ $# -gt 0 ]] +do + case "$1" in + *:* ) + WAITFORIT_hostport=(${1//:/ }) + WAITFORIT_HOST=${WAITFORIT_hostport[0]} + WAITFORIT_PORT=${WAITFORIT_hostport[1]} + shift 1 + ;; + --child) + WAITFORIT_CHILD=1 + shift 1 + ;; + -q | --quiet) + WAITFORIT_QUIET=1 + shift 1 + ;; + -s | --strict) + WAITFORIT_STRICT=1 + shift 1 + ;; + -h) + WAITFORIT_HOST="$2" + if [[ $WAITFORIT_HOST == "" ]]; then break; fi + shift 2 + ;; + --host=*) + WAITFORIT_HOST="${1#*=}" + shift 1 + ;; + -p) + WAITFORIT_PORT="$2" + if [[ $WAITFORIT_PORT == "" ]]; then break; fi + shift 2 + ;; + --port=*) + WAITFORIT_PORT="${1#*=}" + shift 1 + ;; + -t) + WAITFORIT_TIMEOUT="$2" + if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi + shift 2 + ;; + --timeout=*) + WAITFORIT_TIMEOUT="${1#*=}" + shift 1 + ;; + --) + shift + WAITFORIT_CLI=("$@") + break + ;; + --help) + usage + ;; + *) + echoerr "Unknown argument: $1" + usage + ;; + esac +done + +if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then + echoerr "Error: you need to provide a host and port to test." + usage +fi + +WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15} +WAITFORIT_STRICT=${WAITFORIT_STRICT:-0} +WAITFORIT_CHILD=${WAITFORIT_CHILD:-0} +WAITFORIT_QUIET=${WAITFORIT_QUIET:-0} + +# check to see if timeout is from busybox? +WAITFORIT_TIMEOUT_PATH=$(type -p timeout) +WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH) +if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then + WAITFORIT_ISBUSY=1 + WAITFORIT_BUSYTIMEFLAG="-t" + +else + WAITFORIT_ISBUSY=0 + WAITFORIT_BUSYTIMEFLAG="" +fi + +if [[ $WAITFORIT_CHILD -gt 0 ]]; then + wait_for + WAITFORIT_RESULT=$? + exit $WAITFORIT_RESULT +else + if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then + wait_for_wrapper + WAITFORIT_RESULT=$? + else + wait_for + WAITFORIT_RESULT=$? + fi +fi + +if [[ $WAITFORIT_CLI != "" ]]; then + if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then + echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess" + exit $WAITFORIT_RESULT + fi + exec "${WAITFORIT_CLI[@]}" +else + exit $WAITFORIT_RESULT +fi diff --git a/debian-packages.txt b/debian-packages.txt new file mode 100644 index 00000000..f80b5282 --- /dev/null +++ b/debian-packages.txt @@ -0,0 +1,10 @@ +git +netcat +vim +locales +ipython +python3-setuptools +python3-mysqldb +python3-psycopg2 +python3-yaml +uwsgi \ No newline at end of file diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml new file mode 100644 index 00000000..5303abf6 --- /dev/null +++ b/docker-compose-dev.yml @@ -0,0 +1,57 @@ +version: '3' + +services: + app: + build: + context: . + args: + dev: 1 + command: /bin/sh /srv/app/wsgi.sh --runserver + volumes: + - ./app/:/srv/app + - ./bin:/srv/bin + - ./lib:/srv/lib + - ./teleforma/:/srv/src/teleforma/teleforma + - ./var/media:/srv/media + - ./var/backup:/srv/backup + - ./var/static:/srv/static + - ./var/log/app:/var/log/app + - ./var/log/uwsgi:/var/log/uwsgi + links: + - db + ports: + - "8004:8000" + env_file: + - 'env/debug.env' + + db: + image: postgres:13 + env_file: + - env/debug.env + environment: + PGDATA: /var/lib/postgresql/data/pgdata + volumes: + - ./var/lib/postgresql:/var/lib/postgresql/data:rw + - ./bin:/srv/bin + - ./var/backup/:/srv/backup + - /etc/localtime:/etc/localtime:ro + + memcached: + image: memcached:alpine + entrypoint: + - memcached + - -m 1024 + - -I 128m + - -v + + apache: + image: httpd + volumes: + - ./etc/apache2-dev.conf:/usr/local/apache2/conf/httpd.conf + ports: + - "8084:80" + + +volumes: + app: + db: diff --git a/docker-compose.yml b/docker-compose.yml index c17b4275..783b7a36 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,33 +1,52 @@ -data: - image: debian:jessie - volumes: - - ./var/media/:/srv/media - - ./var/static/:/srv/static - - ./var/backup/:/srv/backup - command: "true" +version: '3' -db: - image: mariadb - environment: - - MYSQL_ROOT_PASSWORD=mysecretpassword - - MYSQL_DATABASE=teleforma - - MYSQL_USER=teleforma - - MYSQL_PASSWORD=admin - volumes: - - ./data/var/lib/mysql/:/var/lib/mysql - - ./data/var/log/mysql/:/var/log/mysql +services: + app: + build: + context: . + args: + dev: 1 + command: /bin/sh /srv/app/wsgi.sh --runserver + volumes: + - ./app/:/srv/app + - ./bin:/srv/bin + - ./lib:/srv/lib + - ./teleforma/:/srv/src/teleforma/teleforma + - ./var/media:/srv/media + - ./var/backup:/srv/backup + - ./var/static:/srv/static + - ./var/log/app:/var/log/app + - ./var/log/uwsgi:/var/log/uwsgi + - ./var/run/app:/var/run/app + links: + - db:db + - memcached + depends_on: + - db + - memcached + env_file: + - env/debug.env -app: - build: . - command: /bin/sh deploy/start_app.sh - volumes: - - ./app/:/srv/app - - ./teleforma/:/srv/lib/teleforma/teleforma - volumes_from: - - data - ports: - - "8000:8000" - links: - - db + db: + image: postgres:13 + env_file: + - env/debug.env + environment: + PGDATA: /var/lib/postgresql/data/pgdata + volumes: + - ./var/lib/postgresql:/var/lib/postgresql/data:rw + - ./bin:/srv/bin + - ./var/backup/:/srv/backup + - /etc/localtime:/etc/localtime:ro + memcached: + image: memcached:alpine + entrypoint: + - memcached + - -m 1024 + - -I 128m + - -v +volumes: + app: + db: diff --git a/env/debug.env b/env/debug.env new file mode 100644 index 00000000..93fb2bb5 --- /dev/null +++ b/env/debug.env @@ -0,0 +1,10 @@ +DEBUG=True + +DB_PORT=5432 +DB_HOST=db +POSTGRES_HOST=db +POSTGRES_PASSWORD=mysecretpassword +POSTGRES_DATABASE=teleforma +POSTGRES_DB=teleforma +POSTGRES_USER=teleforma +POSTGRES_HOST_AUTH_METHOD=trust diff --git a/etc/apache2-dev.conf b/etc/apache2-dev.conf new file mode 100644 index 00000000..87917d8d --- /dev/null +++ b/etc/apache2-dev.conf @@ -0,0 +1,558 @@ +# +# This is the main Apache HTTP server configuration file. It contains the +# configuration directives that give the server its instructions. +# See for detailed information. +# In particular, see +# +# for a discussion of each configuration directive. +# +# Do NOT simply read the instructions in here without understanding +# what they do. They're here only as hints or reminders. If you are unsure +# consult the online docs. You have been warned. +# +# Configuration and logfile names: If the filenames you specify for many +# of the server's control files begin with "/" (or "drive:/" for Win32), the +# server will use that explicit path. If the filenames do *not* begin +# with "/", the value of ServerRoot is prepended -- so "logs/access_log" +# with ServerRoot set to "/usr/local/apache2" will be interpreted by the +# server as "/usr/local/apache2/logs/access_log", whereas "/logs/access_log" +# will be interpreted as '/logs/access_log'. + +# +# ServerRoot: The top of the directory tree under which the server's +# configuration, error, and log files are kept. +# +# Do not add a slash at the end of the directory path. If you point +# ServerRoot at a non-local disk, be sure to specify a local disk on the +# Mutex directive, if file-based mutexes are used. If you wish to share the +# same ServerRoot for multiple httpd daemons, you will need to change at +# least PidFile. +# +ServerRoot "/usr/local/apache2" + +# +# Mutex: Allows you to set the mutex mechanism and mutex file directory +# for individual mutexes, or change the global defaults +# +# Uncomment and change the directory if mutexes are file-based and the default +# mutex file directory is not on a local disk or is not appropriate for some +# other reason. +# +# Mutex default:logs + +# +# Listen: Allows you to bind Apache to specific IP addresses and/or +# ports, instead of the default. See also the +# directive. +# +# Change this to Listen on specific IP addresses as shown below to +# prevent Apache from glomming onto all bound IP addresses. +# +#Listen 12.34.56.78:80 +Listen 80 + +# +# Dynamic Shared Object (DSO) Support +# +# To be able to use the functionality of a module which was built as a DSO you +# have to place corresponding `LoadModule' lines at this location so the +# directives contained in it are actually available _before_ they are used. +# Statically compiled modules (those listed by `httpd -l') do not need +# to be loaded here. +# +# Example: +# LoadModule foo_module modules/mod_foo.so +# +LoadModule mpm_event_module modules/mod_mpm_event.so +#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so +#LoadModule mpm_worker_module modules/mod_mpm_worker.so +LoadModule authn_file_module modules/mod_authn_file.so +#LoadModule authn_dbm_module modules/mod_authn_dbm.so +#LoadModule authn_anon_module modules/mod_authn_anon.so +#LoadModule authn_dbd_module modules/mod_authn_dbd.so +#LoadModule authn_socache_module modules/mod_authn_socache.so +LoadModule authn_core_module modules/mod_authn_core.so +LoadModule authz_host_module modules/mod_authz_host.so +LoadModule authz_groupfile_module modules/mod_authz_groupfile.so +LoadModule authz_user_module modules/mod_authz_user.so +#LoadModule authz_dbm_module modules/mod_authz_dbm.so +#LoadModule authz_owner_module modules/mod_authz_owner.so +#LoadModule authz_dbd_module modules/mod_authz_dbd.so +LoadModule authz_core_module modules/mod_authz_core.so +#LoadModule authnz_ldap_module modules/mod_authnz_ldap.so +#LoadModule authnz_fcgi_module modules/mod_authnz_fcgi.so +LoadModule access_compat_module modules/mod_access_compat.so +LoadModule auth_basic_module modules/mod_auth_basic.so +#LoadModule auth_form_module modules/mod_auth_form.so +#LoadModule auth_digest_module modules/mod_auth_digest.so +#LoadModule allowmethods_module modules/mod_allowmethods.so +#LoadModule isapi_module modules/mod_isapi.so +#LoadModule file_cache_module modules/mod_file_cache.so +#LoadModule cache_module modules/mod_cache.so +#LoadModule cache_disk_module modules/mod_cache_disk.so +#LoadModule cache_socache_module modules/mod_cache_socache.so +#LoadModule socache_shmcb_module modules/mod_socache_shmcb.so +#LoadModule socache_dbm_module modules/mod_socache_dbm.so +#LoadModule socache_memcache_module modules/mod_socache_memcache.so +#LoadModule socache_redis_module modules/mod_socache_redis.so +#LoadModule watchdog_module modules/mod_watchdog.so +#LoadModule macro_module modules/mod_macro.so +#LoadModule dbd_module modules/mod_dbd.so +#LoadModule bucketeer_module modules/mod_bucketeer.so +#LoadModule dumpio_module modules/mod_dumpio.so +#LoadModule echo_module modules/mod_echo.so +#LoadModule example_hooks_module modules/mod_example_hooks.so +#LoadModule case_filter_module modules/mod_case_filter.so +#LoadModule case_filter_in_module modules/mod_case_filter_in.so +#LoadModule example_ipc_module modules/mod_example_ipc.so +#LoadModule buffer_module modules/mod_buffer.so +#LoadModule data_module modules/mod_data.so +#LoadModule ratelimit_module modules/mod_ratelimit.so +LoadModule reqtimeout_module modules/mod_reqtimeout.so +#LoadModule ext_filter_module modules/mod_ext_filter.so +#LoadModule request_module modules/mod_request.so +#LoadModule include_module modules/mod_include.so +LoadModule filter_module modules/mod_filter.so +#LoadModule reflector_module modules/mod_reflector.so +#LoadModule substitute_module modules/mod_substitute.so +#LoadModule sed_module modules/mod_sed.so +#LoadModule charset_lite_module modules/mod_charset_lite.so +#LoadModule deflate_module modules/mod_deflate.so +#LoadModule xml2enc_module modules/mod_xml2enc.so +#LoadModule proxy_html_module modules/mod_proxy_html.so +#LoadModule brotli_module modules/mod_brotli.so +LoadModule mime_module modules/mod_mime.so +#LoadModule ldap_module modules/mod_ldap.so +LoadModule log_config_module modules/mod_log_config.so +#LoadModule log_debug_module modules/mod_log_debug.so +#LoadModule log_forensic_module modules/mod_log_forensic.so +#LoadModule logio_module modules/mod_logio.so +#LoadModule lua_module modules/mod_lua.so +LoadModule env_module modules/mod_env.so +#LoadModule mime_magic_module modules/mod_mime_magic.so +#LoadModule cern_meta_module modules/mod_cern_meta.so +#LoadModule expires_module modules/mod_expires.so +LoadModule headers_module modules/mod_headers.so +#LoadModule ident_module modules/mod_ident.so +#LoadModule usertrack_module modules/mod_usertrack.so +#LoadModule unique_id_module modules/mod_unique_id.so +LoadModule setenvif_module modules/mod_setenvif.so +LoadModule version_module modules/mod_version.so +#LoadModule remoteip_module modules/mod_remoteip.so +LoadModule proxy_module modules/mod_proxy.so +#LoadModule proxy_connect_module modules/mod_proxy_connect.so +#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so +LoadModule proxy_http_module modules/mod_proxy_http.so +#LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so +#LoadModule proxy_scgi_module modules/mod_proxy_scgi.so +#LoadModule proxy_uwsgi_module modules/mod_proxy_uwsgi.so +#LoadModule proxy_fdpass_module modules/mod_proxy_fdpass.so +LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so +#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so +#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so +#LoadModule proxy_express_module modules/mod_proxy_express.so +#LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so +#LoadModule session_module modules/mod_session.so +#LoadModule session_cookie_module modules/mod_session_cookie.so +#LoadModule session_crypto_module modules/mod_session_crypto.so +#LoadModule session_dbd_module modules/mod_session_dbd.so +#LoadModule slotmem_shm_module modules/mod_slotmem_shm.so +#LoadModule slotmem_plain_module modules/mod_slotmem_plain.so +#LoadModule ssl_module modules/mod_ssl.so +#LoadModule optional_hook_export_module modules/mod_optional_hook_export.so +#LoadModule optional_hook_import_module modules/mod_optional_hook_import.so +#LoadModule optional_fn_import_module modules/mod_optional_fn_import.so +#LoadModule optional_fn_export_module modules/mod_optional_fn_export.so +#LoadModule dialup_module modules/mod_dialup.so +#LoadModule http2_module modules/mod_http2.so +#LoadModule proxy_http2_module modules/mod_proxy_http2.so +#LoadModule md_module modules/mod_md.so +#LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so +#LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so +#LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so +#LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so +LoadModule unixd_module modules/mod_unixd.so +#LoadModule heartbeat_module modules/mod_heartbeat.so +#LoadModule heartmonitor_module modules/mod_heartmonitor.so +#LoadModule dav_module modules/mod_dav.so +LoadModule status_module modules/mod_status.so +LoadModule autoindex_module modules/mod_autoindex.so +#LoadModule asis_module modules/mod_asis.so +#LoadModule info_module modules/mod_info.so +#LoadModule suexec_module modules/mod_suexec.so + + #LoadModule cgid_module modules/mod_cgid.so + + + #LoadModule cgi_module modules/mod_cgi.so + +#LoadModule dav_fs_module modules/mod_dav_fs.so +#LoadModule dav_lock_module modules/mod_dav_lock.so +#LoadModule vhost_alias_module modules/mod_vhost_alias.so +#LoadModule negotiation_module modules/mod_negotiation.so +LoadModule dir_module modules/mod_dir.so +#LoadModule imagemap_module modules/mod_imagemap.so +#LoadModule actions_module modules/mod_actions.so +#LoadModule speling_module modules/mod_speling.so +#LoadModule userdir_module modules/mod_userdir.so +LoadModule alias_module modules/mod_alias.so +LoadModule rewrite_module modules/mod_rewrite.so + + +# +# If you wish httpd to run as a different user or group, you must run +# httpd as root initially and it will switch. +# +# User/Group: The name (or #number) of the user/group to run httpd as. +# It is usually good practice to create a dedicated user and group for +# running httpd, as with most system services. +# +User daemon +Group daemon + + + +# 'Main' server configuration +# +# The directives in this section set up the values used by the 'main' +# server, which responds to any requests that aren't handled by a +# definition. These values also provide defaults for +# any containers you may define later in the file. +# +# All of these directives may appear inside containers, +# in which case these default settings will be overridden for the +# virtual host being defined. +# + +# +# ServerAdmin: Your address, where problems with the server should be +# e-mailed. This address appears on some server-generated pages, such +# as error documents. e.g. admin@your-domain.com +# +ServerAdmin you@example.com + +# +# ServerName gives the name and port that the server uses to identify itself. +# This can often be determined automatically, but we recommend you specify +# it explicitly to prevent problems during startup. +# +# If your host doesn't have a registered DNS name, enter its IP address here. +# +#ServerName www.example.com:80 + +# +# Deny access to the entirety of your server's filesystem. You must +# explicitly permit access to web content directories in other +# blocks below. +# + + AllowOverride none + Require all denied + + +# +# Note that from this point forward you must specifically allow +# particular features to be enabled - so if something's not working as +# you might expect, make sure that you have specifically enabled it +# below. +# + +# +# DocumentRoot: The directory out of which you will serve your +# documents. By default, all requests are taken from this directory, but +# symbolic links and aliases may be used to point to other locations. +# +DocumentRoot "/usr/local/apache2/htdocs" + + # + # Possible values for the Options directive are "None", "All", + # or any combination of: + # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews + # + # Note that "MultiViews" must be named *explicitly* --- "Options All" + # doesn't give it to you. + # + # The Options directive is both complicated and important. Please see + # http://httpd.apache.org/docs/2.4/mod/core.html#options + # for more information. + # + Options Indexes FollowSymLinks + + # + # AllowOverride controls what directives may be placed in .htaccess files. + # It can be "All", "None", or any combination of the keywords: + # AllowOverride FileInfo AuthConfig Limit + # + AllowOverride None + + # + # Controls who can get stuff from this server. + # + Require all granted + + +# +# DirectoryIndex: sets the file that Apache will serve if a directory +# is requested. +# + + DirectoryIndex index.html + + +# +# The following lines prevent .htaccess and .htpasswd files from being +# viewed by Web clients. +# + + Require all denied + + +# +# ErrorLog: The location of the error log file. +# If you do not specify an ErrorLog directive within a +# container, error messages relating to that virtual host will be +# logged here. If you *do* define an error logfile for a +# container, that host's errors will be logged there and not here. +# +ErrorLog /proc/self/fd/2 + +# +# LogLevel: Control the number of messages logged to the error_log. +# Possible values include: debug, info, notice, warn, error, crit, +# alert, emerg. +# +LogLevel warn + + + # + # The following directives define some format nicknames for use with + # a CustomLog directive (see below). + # + LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined + LogFormat "%h %l %u %t \"%r\" %>s %b" common + + + # You need to enable mod_logio.c to use %I and %O + LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio + + + # + # The location and format of the access logfile (Common Logfile Format). + # If you do not define any access logfiles within a + # container, they will be logged here. Contrariwise, if you *do* + # define per- access logfiles, transactions will be + # logged therein and *not* in this file. + # + CustomLog /proc/self/fd/1 common + + # + # If you prefer a logfile with access, agent, and referer information + # (Combined Logfile Format) you can use the following directive. + # + #CustomLog "logs/access_log" combined + + + + # + # Redirect: Allows you to tell clients about documents that used to + # exist in your server's namespace, but do not anymore. The client + # will make a new request for the document at its new location. + # Example: + # Redirect permanent /foo http://www.example.com/bar + + # + # Alias: Maps web paths into filesystem paths and is used to + # access content that does not live under the DocumentRoot. + # Example: + # Alias /webpath /full/filesystem/path + # + # If you include a trailing / on /webpath then the server will + # require it to be present in the URL. You will also likely + # need to provide a section to allow access to + # the filesystem path. + + # + # ScriptAlias: This controls which directories contain server scripts. + # ScriptAliases are essentially the same as Aliases, except that + # documents in the target directory are treated as applications and + # run by the server when requested rather than as documents sent to the + # client. The same rules about trailing "/" apply to ScriptAlias + # directives as to Alias. + # + ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/" + + + + + # + # ScriptSock: On threaded servers, designate the path to the UNIX + # socket used to communicate with the CGI daemon of mod_cgid. + # + #Scriptsock cgisock + + +# +# "/usr/local/apache2/cgi-bin" should be changed to whatever your ScriptAliased +# CGI directory exists, if you have that configured. +# + + AllowOverride None + Options None + Require all granted + + + + # + # Avoid passing HTTP_PROXY environment to CGI's on this or any proxied + # backend servers which have lingering "httpoxy" defects. + # 'Proxy' request header is undefined by the IETF, not listed by IANA + # + RequestHeader unset Proxy early + + + + # + # TypesConfig points to the file containing the list of mappings from + # filename extension to MIME-type. + # + TypesConfig conf/mime.types + + # + # AddType allows you to add to or override the MIME configuration + # file specified in TypesConfig for specific file types. + # + #AddType application/x-gzip .tgz + # + # AddEncoding allows you to have certain browsers uncompress + # information on the fly. Note: Not all browsers support this. + # + #AddEncoding x-compress .Z + #AddEncoding x-gzip .gz .tgz + # + # If the AddEncoding directives above are commented-out, then you + # probably should define those extensions to indicate media types: + # + AddType application/x-compress .Z + AddType application/x-gzip .gz .tgz + + # + # AddHandler allows you to map certain file extensions to "handlers": + # actions unrelated to filetype. These can be either built into the server + # or added with the Action directive (see below) + # + # To use CGI scripts outside of ScriptAliased directories: + # (You will also need to add "ExecCGI" to the "Options" directive.) + # + #AddHandler cgi-script .cgi + + # For type maps (negotiated resources): + #AddHandler type-map var + + # + # Filters allow you to process content before it is sent to the client. + # + # To parse .shtml files for server-side includes (SSI): + # (You will also need to add "Includes" to the "Options" directive.) + # + #AddType text/html .shtml + #AddOutputFilter INCLUDES .shtml + + +# +# The mod_mime_magic module allows the server to use various hints from the +# contents of the file itself to determine its type. The MIMEMagicFile +# directive tells the module where the hint definitions are located. +# +#MIMEMagicFile conf/magic + +# +# Customizable error responses come in three flavors: +# 1) plain text 2) local redirects 3) external redirects +# +# Some examples: +#ErrorDocument 500 "The server made a boo boo." +#ErrorDocument 404 /missing.html +#ErrorDocument 404 "/cgi-bin/missing_handler.pl" +#ErrorDocument 402 http://www.example.com/subscription_info.html +# + +# +# MaxRanges: Maximum number of Ranges in a request before +# returning the entire resource, or one of the special +# values 'default', 'none' or 'unlimited'. +# Default setting is to accept 200 Ranges. +#MaxRanges unlimited + +# +# EnableMMAP and EnableSendfile: On systems that support it, +# memory-mapping or the sendfile syscall may be used to deliver +# files. This usually improves server performance, but must +# be turned off when serving from networked-mounted +# filesystems or if support for these functions is otherwise +# broken on your system. +# Defaults: EnableMMAP On, EnableSendfile Off +# +#EnableMMAP off +#EnableSendfile on + +# Supplemental configuration +# +# The configuration files in the conf/extra/ directory can be +# included to add extra features or to modify the default configuration of +# the server, or you may simply copy their contents here and change as +# necessary. + +# Server-pool management (MPM specific) +#Include conf/extra/httpd-mpm.conf + +# Multi-language error messages +#Include conf/extra/httpd-multilang-errordoc.conf + +# Fancy directory listings +#Include conf/extra/httpd-autoindex.conf + +# Language settings +#Include conf/extra/httpd-languages.conf + +# User home directories +#Include conf/extra/httpd-userdir.conf + +# Real-time info on requests and configuration +#Include conf/extra/httpd-info.conf + +# Virtual hosts +#Include conf/extra/httpd-vhosts.conf + +# Local access to the Apache HTTP Server Manual +#Include conf/extra/httpd-manual.conf + +# Distributed authoring and versioning (WebDAV) +#Include conf/extra/httpd-dav.conf + +# Various default settings +#Include conf/extra/httpd-default.conf + +# Configure mod_proxy_html to understand HTML4/XHTML1 + +Include conf/extra/proxy-html.conf + + +# Secure (SSL/TLS) connections +#Include conf/extra/httpd-ssl.conf +# +# Note: The following must must be present to support +# starting without SSL on platforms with no /dev/random equivalent +# but a statically compiled-in mod_ssl. +# + +SSLRandomSeed startup builtin +SSLRandomSeed connect builtin + + + RewriteEngine on + ProxyPreserveHost on + RewriteCond %{HTTP:Connection} Upgrade [NC] + RewriteCond %{HTTP:Upgrade} websocket [NC] + RewriteRule ^/(.*)$ ws://channels:8000/$1 [P,L] + + RewriteRule ^(.*)$ http://app:8000$1 [P,L] diff --git a/etc/postgresql.conf b/etc/postgresql.conf new file mode 100644 index 00000000..7063ed23 --- /dev/null +++ b/etc/postgresql.conf @@ -0,0 +1,781 @@ +# ----------------------------- +# PostgreSQL configuration file +# ----------------------------- +# +# This file consists of lines of the form: +# +# name = value +# +# (The "=" is optional.) Whitespace may be used. Comments are introduced with +# "#" anywhere on a line. The complete list of parameter names and allowed +# values can be found in the PostgreSQL documentation. +# +# The commented-out settings shown in this file represent the default values. +# Re-commenting a setting is NOT sufficient to revert it to the default value; +# you need to reload the server. +# +# This file is read on server startup and when the server receives a SIGHUP +# signal. If you edit the file on a running system, you have to SIGHUP the +# server for the changes to take effect, run "pg_ctl reload", or execute +# "SELECT pg_reload_conf()". Some parameters, which are marked below, +# require a server shutdown and restart to take effect. +# +# Any parameter can also be given as a command-line option to the server, e.g., +# "postgres -c log_connections=on". Some parameters can be changed at run time +# with the "SET" SQL command. +# +# Memory units: kB = kilobytes Time units: ms = milliseconds +# MB = megabytes s = seconds +# GB = gigabytes min = minutes +# TB = terabytes h = hours +# d = days + + +#------------------------------------------------------------------------------ +# FILE LOCATIONS +#------------------------------------------------------------------------------ + +# The default values of these variables are driven from the -D command-line +# option or PGDATA environment variable, represented here as ConfigDir. + +#data_directory = 'ConfigDir' # use data in another directory + # (change requires restart) +#hba_file = 'ConfigDir/pg_hba.conf' # host-based authentication file + # (change requires restart) +#ident_file = 'ConfigDir/pg_ident.conf' # ident configuration file + # (change requires restart) + +# If external_pid_file is not explicitly set, no extra PID file is written. +#external_pid_file = '' # write an extra PID file + # (change requires restart) + + +#------------------------------------------------------------------------------ +# CONNECTIONS AND AUTHENTICATION +#------------------------------------------------------------------------------ + +# - Connection Settings - + +listen_addresses = '*' + # comma-separated list of addresses; + # defaults to 'localhost'; use '*' for all + # (change requires restart) +#port = 5432 # (change requires restart) +max_connections = 2000 # (change requires restart) +#superuser_reserved_connections = 3 # (change requires restart) +#unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories + # (change requires restart) +#unix_socket_group = '' # (change requires restart) +#unix_socket_permissions = 0777 # begin with 0 to use octal notation + # (change requires restart) +#bonjour = off # advertise server via Bonjour + # (change requires restart) +#bonjour_name = '' # defaults to the computer name + # (change requires restart) + +# - TCP settings - +# see "man tcp" for details + +#tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds; + # 0 selects the system default +#tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds; + # 0 selects the system default +#tcp_keepalives_count = 0 # TCP_KEEPCNT; + # 0 selects the system default +#tcp_user_timeout = 0 # TCP_USER_TIMEOUT, in milliseconds; + # 0 selects the system default + +# - Authentication - + +#authentication_timeout = 1min # 1s-600s +#password_encryption = md5 # md5 or scram-sha-256 +#db_user_namespace = off + +# GSSAPI using Kerberos +#krb_server_keyfile = 'FILE:${sysconfdir}/krb5.keytab' +#krb_caseins_users = off + +# - SSL - + +#ssl = off +#ssl_ca_file = '' +#ssl_cert_file = 'server.crt' +#ssl_crl_file = '' +#ssl_key_file = 'server.key' +#ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers +#ssl_prefer_server_ciphers = on +#ssl_ecdh_curve = 'prime256v1' +#ssl_min_protocol_version = 'TLSv1.2' +#ssl_max_protocol_version = '' +#ssl_dh_params_file = '' +#ssl_passphrase_command = '' +#ssl_passphrase_command_supports_reload = off + + +#------------------------------------------------------------------------------ +# RESOURCE USAGE (except WAL) +#------------------------------------------------------------------------------ + +# - Memory - + +shared_buffers = 24GB # min 128kB + # (change requires restart) +#huge_pages = try # on, off, or try + # (change requires restart) +#temp_buffers = 8MB # min 800kB +#max_prepared_transactions = 0 # zero disables the feature + # (change requires restart) +# Caution: it is not advisable to set max_prepared_transactions nonzero unless +# you actively intend to use prepared transactions. +work_mem = 8MB # min 64kB +#hash_mem_multiplier = 1.0 # 1-1000.0 multiplier on hash table work_mem +#maintenance_work_mem = 64MB # min 1MB +#autovacuum_work_mem = -1 # min 1MB, or -1 to use maintenance_work_mem +#logical_decoding_work_mem = 64MB # min 64kB +#max_stack_depth = 2MB # min 100kB +#shared_memory_type = mmap # the default is the first option + # supported by the operating system: + # mmap + # sysv + # windows + # (change requires restart) +dynamic_shared_memory_type = posix # the default is the first option + # supported by the operating system: + # posix + # sysv + # windows + # mmap + # (change requires restart) + +# - Disk - + +#temp_file_limit = -1 # limits per-process temp file space + # in kilobytes, or -1 for no limit + +# - Kernel Resources - + +#max_files_per_process = 1000 # min 64 + # (change requires restart) + +# - Cost-Based Vacuum Delay - + +#vacuum_cost_delay = 0 # 0-100 milliseconds (0 disables) +#vacuum_cost_page_hit = 1 # 0-10000 credits +#vacuum_cost_page_miss = 10 # 0-10000 credits +#vacuum_cost_page_dirty = 20 # 0-10000 credits +#vacuum_cost_limit = 200 # 1-10000 credits + +# - Background Writer - + +#bgwriter_delay = 200ms # 10-10000ms between rounds +#bgwriter_lru_maxpages = 100 # max buffers written/round, 0 disables +#bgwriter_lru_multiplier = 2.0 # 0-10.0 multiplier on buffers scanned/round +#bgwriter_flush_after = 512kB # measured in pages, 0 disables + +# - Asynchronous Behavior - + +effective_io_concurrency = 200 # 1-1000; 0 disables prefetching +#maintenance_io_concurrency = 10 # 1-1000; 0 disables prefetching +#max_worker_processes = 8 # (change requires restart) +#max_parallel_maintenance_workers = 2 # taken from max_parallel_workers +#max_parallel_workers_per_gather = 2 # taken from max_parallel_workers +#parallel_leader_participation = on +#max_parallel_workers = 8 # maximum number of max_worker_processes that + # can be used in parallel operations +#old_snapshot_threshold = -1 # 1min-60d; -1 disables; 0 is immediate + # (change requires restart) +#backend_flush_after = 0 # measured in pages, 0 disables + + +#------------------------------------------------------------------------------ +# WRITE-AHEAD LOG +#------------------------------------------------------------------------------ + +# - Settings - + +#wal_level = replica # minimal, replica, or logical + # (change requires restart) +#fsync = on # flush data to disk for crash safety + # (turning this off can cause + # unrecoverable data corruption) +#synchronous_commit = on # synchronization level; + # off, local, remote_write, remote_apply, or on +#wal_sync_method = fsync # the default is the first option + # supported by the operating system: + # open_datasync + # fdatasync (default on Linux and FreeBSD) + # fsync + # fsync_writethrough + # open_sync +#full_page_writes = on # recover from partial page writes +#wal_compression = off # enable compression of full-page writes +#wal_log_hints = off # also do full page writes of non-critical updates + # (change requires restart) +#wal_init_zero = on # zero-fill new WAL files +#wal_recycle = on # recycle WAL files +#wal_buffers = -1 # min 32kB, -1 sets based on shared_buffers + # (change requires restart) +#wal_writer_delay = 200ms # 1-10000 milliseconds +#wal_writer_flush_after = 1MB # measured in pages, 0 disables +#wal_skip_threshold = 2MB + +#commit_delay = 0 # range 0-100000, in microseconds +#commit_siblings = 5 # range 1-1000 + +# - Checkpoints - + +#checkpoint_timeout = 5min # range 30s-1d +max_wal_size = 4GB +min_wal_size = 1GB +#checkpoint_completion_target = 0.5 # checkpoint target duration, 0.0 - 1.0 +#checkpoint_flush_after = 256kB # measured in pages, 0 disables +#checkpoint_warning = 30s # 0 disables + +# - Archiving - + +#archive_mode = off # enables archiving; off, on, or always + # (change requires restart) +#archive_command = '' # command to use to archive a logfile segment + # placeholders: %p = path of file to archive + # %f = file name only + # e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f' +#archive_timeout = 0 # force a logfile segment switch after this + # number of seconds; 0 disables + +# - Archive Recovery - + +# These are only used in recovery mode. + +#restore_command = '' # command to use to restore an archived logfile segment + # placeholders: %p = path of file to restore + # %f = file name only + # e.g. 'cp /mnt/server/archivedir/%f %p' + # (change requires restart) +#archive_cleanup_command = '' # command to execute at every restartpoint +#recovery_end_command = '' # command to execute at completion of recovery + +# - Recovery Target - + +# Set these only when performing a targeted recovery. + +#recovery_target = '' # 'immediate' to end recovery as soon as a + # consistent state is reached + # (change requires restart) +#recovery_target_name = '' # the named restore point to which recovery will proceed + # (change requires restart) +#recovery_target_time = '' # the time stamp up to which recovery will proceed + # (change requires restart) +#recovery_target_xid = '' # the transaction ID up to which recovery will proceed + # (change requires restart) +#recovery_target_lsn = '' # the WAL LSN up to which recovery will proceed + # (change requires restart) +#recovery_target_inclusive = on # Specifies whether to stop: + # just after the specified recovery target (on) + # just before the recovery target (off) + # (change requires restart) +#recovery_target_timeline = 'latest' # 'current', 'latest', or timeline ID + # (change requires restart) +#recovery_target_action = 'pause' # 'pause', 'promote', 'shutdown' + # (change requires restart) + + +#------------------------------------------------------------------------------ +# REPLICATION +#------------------------------------------------------------------------------ + +# - Sending Servers - + +# Set these on the master and on any standby that will send replication data. + +#max_wal_senders = 10 # max number of walsender processes + # (change requires restart) +#wal_keep_size = 0 # in megabytes; 0 disables +#max_slot_wal_keep_size = -1 # in megabytes; -1 disables +#wal_sender_timeout = 60s # in milliseconds; 0 disables + +#max_replication_slots = 10 # max number of replication slots + # (change requires restart) +#track_commit_timestamp = off # collect timestamp of transaction commit + # (change requires restart) + +# - Master Server - + +# These settings are ignored on a standby server. + +#synchronous_standby_names = '' # standby servers that provide sync rep + # method to choose sync standbys, number of sync standbys, + # and comma-separated list of application_name + # from standby(s); '*' = all +#vacuum_defer_cleanup_age = 0 # number of xacts by which cleanup is delayed + +# - Standby Servers - + +# These settings are ignored on a master server. + +#primary_conninfo = '' # connection string to sending server +#primary_slot_name = '' # replication slot on sending server +#promote_trigger_file = '' # file name whose presence ends recovery +#hot_standby = on # "off" disallows queries during recovery + # (change requires restart) +#max_standby_archive_delay = 30s # max delay before canceling queries + # when reading WAL from archive; + # -1 allows indefinite delay +#max_standby_streaming_delay = 30s # max delay before canceling queries + # when reading streaming WAL; + # -1 allows indefinite delay +#wal_receiver_create_temp_slot = off # create temp slot if primary_slot_name + # is not set +#wal_receiver_status_interval = 10s # send replies at least this often + # 0 disables +#hot_standby_feedback = off # send info from standby to prevent + # query conflicts +#wal_receiver_timeout = 60s # time that receiver waits for + # communication from master + # in milliseconds; 0 disables +#wal_retrieve_retry_interval = 5s # time to wait before retrying to + # retrieve WAL after a failed attempt +#recovery_min_apply_delay = 0 # minimum delay for applying changes during recovery + +# - Subscribers - + +# These settings are ignored on a publisher. + +#max_logical_replication_workers = 4 # taken from max_worker_processes + # (change requires restart) +#max_sync_workers_per_subscription = 2 # taken from max_logical_replication_workers + + +#------------------------------------------------------------------------------ +# QUERY TUNING +#------------------------------------------------------------------------------ + +# - Planner Method Configuration - + +#enable_bitmapscan = on +#enable_hashagg = on +#enable_hashjoin = on +#enable_indexscan = on +#enable_indexonlyscan = on +#enable_material = on +#enable_mergejoin = on +#enable_nestloop = on +#enable_parallel_append = on +#enable_seqscan = on +#enable_sort = on +#enable_incremental_sort = on +#enable_tidscan = on +#enable_partitionwise_join = off +#enable_partitionwise_aggregate = off +#enable_parallel_hash = on +#enable_partition_pruning = on + +# - Planner Cost Constants - + +#seq_page_cost = 1.0 # measured on an arbitrary scale +#random_page_cost = 4.0 # same scale as above +#cpu_tuple_cost = 0.01 # same scale as above +#cpu_index_tuple_cost = 0.005 # same scale as above +#cpu_operator_cost = 0.0025 # same scale as above +#parallel_tuple_cost = 0.1 # same scale as above +#parallel_setup_cost = 1000.0 # same scale as above + +#jit_above_cost = 100000 # perform JIT compilation if available + # and query more expensive than this; + # -1 disables +#jit_inline_above_cost = 500000 # inline small functions if query is + # more expensive than this; -1 disables +#jit_optimize_above_cost = 500000 # use expensive JIT optimizations if + # query is more expensive than this; + # -1 disables + +#min_parallel_table_scan_size = 8MB +#min_parallel_index_scan_size = 512kB +#effective_cache_size = 4GB + +# - Genetic Query Optimizer - + +#geqo = on +#geqo_threshold = 12 +#geqo_effort = 5 # range 1-10 +#geqo_pool_size = 0 # selects default based on effort +#geqo_generations = 0 # selects default based on effort +#geqo_selection_bias = 2.0 # range 1.5-2.0 +#geqo_seed = 0.0 # range 0.0-1.0 + +# - Other Planner Options - + +#default_statistics_target = 100 # range 1-10000 +#constraint_exclusion = partition # on, off, or partition +#cursor_tuple_fraction = 0.1 # range 0.0-1.0 +#from_collapse_limit = 8 +#join_collapse_limit = 8 # 1 disables collapsing of explicit + # JOIN clauses +#force_parallel_mode = off +#jit = on # allow JIT compilation +#plan_cache_mode = auto # auto, force_generic_plan or + # force_custom_plan + + +#------------------------------------------------------------------------------ +# REPORTING AND LOGGING +#------------------------------------------------------------------------------ + +# - Where to Log - + +#log_destination = 'stderr' # Valid values are combinations of + # stderr, csvlog, syslog, and eventlog, + # depending on platform. csvlog + # requires logging_collector to be on. + +# This is used when logging to stderr: +#logging_collector = off # Enable capturing of stderr and csvlog + # into log files. Required to be on for + # csvlogs. + # (change requires restart) + +# These are only used if logging_collector is on: +#log_directory = 'log' # directory where log files are written, + # can be absolute or relative to PGDATA +#log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern, + # can include strftime() escapes +#log_file_mode = 0600 # creation mode for log files, + # begin with 0 to use octal notation +#log_truncate_on_rotation = off # If on, an existing log file with the + # same name as the new log file will be + # truncated rather than appended to. + # But such truncation only occurs on + # time-driven rotation, not on restarts + # or size-driven rotation. Default is + # off, meaning append to existing files + # in all cases. +#log_rotation_age = 1d # Automatic rotation of logfiles will + # happen after that time. 0 disables. +#log_rotation_size = 10MB # Automatic rotation of logfiles will + # happen after that much log output. + # 0 disables. + +# These are relevant when logging to syslog: +#syslog_facility = 'LOCAL0' +#syslog_ident = 'postgres' +#syslog_sequence_numbers = on +#syslog_split_messages = on + +# This is only relevant when logging to eventlog (win32): +# (change requires restart) +#event_source = 'PostgreSQL' + +# - When to Log - + +#log_min_messages = warning # values in order of decreasing detail: + # debug5 + # debug4 + # debug3 + # debug2 + # debug1 + # info + # notice + # warning + # error + # log + # fatal + # panic + +#log_min_error_statement = error # values in order of decreasing detail: + # debug5 + # debug4 + # debug3 + # debug2 + # debug1 + # info + # notice + # warning + # error + # log + # fatal + # panic (effectively off) + +#log_min_duration_statement = -1 # -1 is disabled, 0 logs all statements + # and their durations, > 0 logs only + # statements running at least this number + # of milliseconds + +#log_min_duration_sample = -1 # -1 is disabled, 0 logs a sample of statements + # and their durations, > 0 logs only a sample of + # statements running at least this number + # of milliseconds; + # sample fraction is determined by log_statement_sample_rate + +#log_statement_sample_rate = 1.0 # fraction of logged statements exceeding + # log_min_duration_sample to be logged; + # 1.0 logs all such statements, 0.0 never logs + + +#log_transaction_sample_rate = 0.0 # fraction of transactions whose statements + # are logged regardless of their duration; 1.0 logs all + # statements from all transactions, 0.0 never logs + +# - What to Log - + +#debug_print_parse = off +#debug_print_rewritten = off +#debug_print_plan = off +#debug_pretty_print = on +#log_checkpoints = off +#log_connections = off +#log_disconnections = off +#log_duration = off +#log_error_verbosity = default # terse, default, or verbose messages +#log_hostname = off +#log_line_prefix = '%m [%p] ' # special values: + # %a = application name + # %u = user name + # %d = database name + # %r = remote host and port + # %h = remote host + # %b = backend type + # %p = process ID + # %t = timestamp without milliseconds + # %m = timestamp with milliseconds + # %n = timestamp with milliseconds (as a Unix epoch) + # %i = command tag + # %e = SQL state + # %c = session ID + # %l = session line number + # %s = session start timestamp + # %v = virtual transaction ID + # %x = transaction ID (0 if none) + # %q = stop here in non-session + # processes + # %% = '%' + # e.g. '<%u%%%d> ' +#log_lock_waits = off # log lock waits >= deadlock_timeout +#log_parameter_max_length = -1 # when logging statements, limit logged + # bind-parameter values to N bytes; + # -1 means print in full, 0 disables +#log_parameter_max_length_on_error = 0 # when logging an error, limit logged + # bind-parameter values to N bytes; + # -1 means print in full, 0 disables +#log_statement = 'none' # none, ddl, mod, all +#log_replication_commands = off +#log_temp_files = -1 # log temporary files equal or larger + # than the specified size in kilobytes; + # -1 disables, 0 logs all temp files +log_timezone = 'Etc/UTC' + +#------------------------------------------------------------------------------ +# PROCESS TITLE +#------------------------------------------------------------------------------ + +#cluster_name = '' # added to process titles if nonempty + # (change requires restart) +#update_process_title = on + + +#------------------------------------------------------------------------------ +# STATISTICS +#------------------------------------------------------------------------------ + +# - Query and Index Statistics Collector - + +#track_activities = on +#track_counts = on +#track_io_timing = off +#track_functions = none # none, pl, all +#track_activity_query_size = 1024 # (change requires restart) +#stats_temp_directory = 'pg_stat_tmp' + + +# - Monitoring - + +#log_parser_stats = off +#log_planner_stats = off +#log_executor_stats = off +#log_statement_stats = off + + +#------------------------------------------------------------------------------ +# AUTOVACUUM +#------------------------------------------------------------------------------ + +#autovacuum = on # Enable autovacuum subprocess? 'on' + # requires track_counts to also be on. +#log_autovacuum_min_duration = -1 # -1 disables, 0 logs all actions and + # their durations, > 0 logs only + # actions running at least this number + # of milliseconds. +#autovacuum_max_workers = 3 # max number of autovacuum subprocesses + # (change requires restart) +#autovacuum_naptime = 1min # time between autovacuum runs +#autovacuum_vacuum_threshold = 50 # min number of row updates before + # vacuum +#autovacuum_vacuum_insert_threshold = 1000 # min number of row inserts + # before vacuum; -1 disables insert + # vacuums +#autovacuum_analyze_threshold = 50 # min number of row updates before + # analyze +#autovacuum_vacuum_scale_factor = 0.2 # fraction of table size before vacuum +#autovacuum_vacuum_insert_scale_factor = 0.2 # fraction of inserts over table + # size before insert vacuum +#autovacuum_analyze_scale_factor = 0.1 # fraction of table size before analyze +#autovacuum_freeze_max_age = 200000000 # maximum XID age before forced vacuum + # (change requires restart) +#autovacuum_multixact_freeze_max_age = 400000000 # maximum multixact age + # before forced vacuum + # (change requires restart) +#autovacuum_vacuum_cost_delay = 2ms # default vacuum cost delay for + # autovacuum, in milliseconds; + # -1 means use vacuum_cost_delay +#autovacuum_vacuum_cost_limit = -1 # default vacuum cost limit for + # autovacuum, -1 means use + # vacuum_cost_limit + + +#------------------------------------------------------------------------------ +# CLIENT CONNECTION DEFAULTS +#------------------------------------------------------------------------------ + +# - Statement Behavior - + +#client_min_messages = notice # values in order of decreasing detail: + # debug5 + # debug4 + # debug3 + # debug2 + # debug1 + # log + # notice + # warning + # error +#search_path = '"$user", public' # schema names +#row_security = on +#default_tablespace = '' # a tablespace name, '' uses the default +#temp_tablespaces = '' # a list of tablespace names, '' uses + # only default tablespace +#default_table_access_method = 'heap' +#check_function_bodies = on +#default_transaction_isolation = 'read committed' +#default_transaction_read_only = off +#default_transaction_deferrable = off +#session_replication_role = 'origin' +#statement_timeout = 0 # in milliseconds, 0 is disabled +#lock_timeout = 0 # in milliseconds, 0 is disabled +#idle_in_transaction_session_timeout = 0 # in milliseconds, 0 is disabled +#vacuum_freeze_min_age = 50000000 +#vacuum_freeze_table_age = 150000000 +#vacuum_multixact_freeze_min_age = 5000000 +#vacuum_multixact_freeze_table_age = 150000000 +#vacuum_cleanup_index_scale_factor = 0.1 # fraction of total number of tuples + # before index cleanup, 0 always performs + # index cleanup +#bytea_output = 'hex' # hex, escape +#xmlbinary = 'base64' +#xmloption = 'content' +#gin_fuzzy_search_limit = 0 +#gin_pending_list_limit = 4MB + +# - Locale and Formatting - + +datestyle = 'iso, mdy' +#intervalstyle = 'postgres' +timezone = 'Etc/UTC' +#timezone_abbreviations = 'Default' # Select the set of available time zone + # abbreviations. Currently, there are + # Default + # Australia (historical usage) + # India + # You can create your own file in + # share/timezonesets/. +#extra_float_digits = 1 # min -15, max 3; any value >0 actually + # selects precise output mode +#client_encoding = sql_ascii # actually, defaults to database + # encoding + +# These settings are initialized by initdb, but they can be changed. +lc_messages = 'en_US.utf8' # locale for system error message + # strings +lc_monetary = 'en_US.utf8' # locale for monetary formatting +lc_numeric = 'en_US.utf8' # locale for number formatting +lc_time = 'en_US.utf8' # locale for time formatting + +# default configuration for text search +default_text_search_config = 'pg_catalog.english' + +# - Shared Library Preloading - + +#shared_preload_libraries = '' # (change requires restart) +#local_preload_libraries = '' +#session_preload_libraries = '' +#jit_provider = 'llvmjit' # JIT library to use + +# - Other Defaults - + +#dynamic_library_path = '$libdir' +#extension_destdir = '' # prepend path when loading extensions + # and shared objects (added by Debian) + + +#------------------------------------------------------------------------------ +# LOCK MANAGEMENT +#------------------------------------------------------------------------------ + +#deadlock_timeout = 1s +#max_locks_per_transaction = 64 # min 10 + # (change requires restart) +#max_pred_locks_per_transaction = 64 # min 10 + # (change requires restart) +#max_pred_locks_per_relation = -2 # negative values mean + # (max_pred_locks_per_transaction + # / -max_pred_locks_per_relation) - 1 +#max_pred_locks_per_page = 2 # min 0 + + +#------------------------------------------------------------------------------ +# VERSION AND PLATFORM COMPATIBILITY +#------------------------------------------------------------------------------ + +# - Previous PostgreSQL Versions - + +#array_nulls = on +#backslash_quote = safe_encoding # on, off, or safe_encoding +#escape_string_warning = on +#lo_compat_privileges = off +#operator_precedence_warning = off +#quote_all_identifiers = off +#standard_conforming_strings = on +#synchronize_seqscans = on + +# - Other Platforms and Clients - + +#transform_null_equals = off + + +#------------------------------------------------------------------------------ +# ERROR HANDLING +#------------------------------------------------------------------------------ + +#exit_on_error = off # terminate session on any error? +#restart_after_crash = on # reinitialize after backend crash? +#data_sync_retry = off # retry or panic on failure to fsync + # data? + # (change requires restart) + + +#------------------------------------------------------------------------------ +# CONFIG FILE INCLUDES +#------------------------------------------------------------------------------ + +# These options allow settings to be loaded from files other than the +# default postgresql.conf. Note that these are directives, not variable +# assignments, so they can usefully be given more than once. + +#include_dir = '...' # include files ending in '.conf' from + # a directory, e.g., 'conf.d' +#include_if_exists = '...' # include file only if it exists +#include = '...' # include file + + +#------------------------------------------------------------------------------ +# CUSTOMIZED OPTIONS +#------------------------------------------------------------------------------ + +# Add settings for extensions here diff --git a/example/__init__.py b/example/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/example/manage.py b/example/manage.py deleted file mode 100644 index c632a8a3..00000000 --- a/example/manage.py +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env python -import os, sys - -if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") - - from django.core.management import execute_from_command_line - - execute_from_command_line(sys.argv) diff --git a/example/settings.py b/example/settings.py deleted file mode 100644 index 57793c47..00000000 --- a/example/settings.py +++ /dev/null @@ -1,247 +0,0 @@ -# -*- coding: utf-8 -*- -# Django settings for sandbox project. - -import os -import sys -from django.core.urlresolvers import reverse_lazy - -sys.dont_write_bytecode = True - -DEBUG = True -TEMPLATE_DEBUG = DEBUG - -ADMINS = ( - ('Guillaume Pellerin', 'webmaster@parisson.com'), - ('Lists', 'lists@parisson.com'), -) - -MANAGERS = ADMINS - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. - 'NAME': 'teleforma_exam.sql', # Or path to database file if using sqlite3. - 'USER': '', # Not used with sqlite3. - 'PASSWORD': '', # Not used with sqlite3. - 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. - 'PORT': '', # Set to empty string for default. Not used with sqlite3. - } -} - -# Local time zone for this installation. Choices can be found here: -# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name -# although not all choices may be available on all operating systems. -# On Unix systems, a value of None will cause Django to use the same -# timezone as the operating system. -# If running in a Windows environment this must be set to the same as your -# system time zone. -TIME_ZONE = 'Europe/Paris' - -# Language code for this installation. All choices can be found here: -# http://www.i18nguy.com/unicode/language-identifiers.html -#LANGUAGE_CODE = 'fr_FR' -LANGUAGES = [ ('fr', 'French'), - ('en', 'English'), -] - -SITE_ID = 1 - -# If you set this to False, Django will make some optimizations so as not -# to load the internationalization machinery. -USE_I18N = True - -# If you set this to False, Django will not format dates, numbers and -# calendars according to the current locale -USE_L10N = True - -# Absolute path to the directory that holds media. -# Example: "/home/media/media.lawrence.com/" -MEDIA_ROOT = os.path.join(os.path.dirname(__file__), 'media/') - -if not os.path.exists(MEDIA_ROOT): - os.mkdir(MEDIA_ROOT) - -# URL that handles the media served from MEDIA_ROOT. Make sure to use a -# trailing slash if there is a path component (optional in other cases). -# Examples: "http://media.lawrence.com", "http://example.com/media/" -MEDIA_URL = '/media/' - -# Absolute path to the directory static files should be collected to. -# Don't put anything in this directory yourself; store your static files -# in apps' "static/" subdirectories and in STATICFILES_DIRS. -# Example: "/home/media/media.lawrence.com/static/" -STATIC_ROOT = '/var/www/static/' - -# URL prefix for static files. -# Example: "http://media.lawrence.com/static/" -STATIC_URL = '/static/' - -# Additional locations of static files -STATICFILES_DIRS = ( - # Put strings here, like "/home/html/static" or "C:/www/django/static". - # Always use forward slashes, even on Windows. - # Don't forget to use absolute paths, not relative paths. -) - -# List of finder classes that know how to find static files in -# various locations. -STATICFILES_FINDERS = ( - 'django.contrib.staticfiles.finders.FileSystemFinder', - 'django.contrib.staticfiles.finders.AppDirectoriesFinder', -# 'django.contrib.staticfiles.finders.DefaultStorageFinder', -) - -# Make this unique, and don't share it with anybody. -SECRET_KEY = 'a8l7%06wr2k+3=%#*#@#rvop2mmzko)44%7k(zx%lls^ihm9^5' - -# List of callables that know how to import templates from various sources. -#TEMPLATE_LOADERS = ( -# ('django.template.loaders.cached.Loader', ( -# 'django.template.loaders.filesystem.Loader', -# 'django.template.loaders.app_directories.Loader', -# )), -#) - - -MIDDLEWARE_CLASSES = ( - 'django.middleware.common.CommonMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.locale.LocaleMiddleware', - 'pagination.middleware.PaginationMiddleware', - 'django_user_agents.middleware.UserAgentMiddleware', -) - -ROOT_URLCONF = 'urls' - -TEMPLATE_DIRS = ( - # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". - # Always use forward slashes, even on Windows. - # Don't forget to use absolute paths, not relative paths. - '/home/momo/dev/teleforma/teleforma/teleforma/templates/', -) - -INSTALLED_APPS = ( - 'suit', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.sites', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'django.contrib.admin', - 'telemeta', - 'jsonrpc', - 'south', - 'teleforma', - 'teleforma.exam', - 'sorl.thumbnail', - 'django_extensions', - 'pagination', - 'postman', -# 'private_files', - 'markup_mixin', - 'notes', -# 'jquery', - 'timezones', - 'jqchat', -# 'follow', - 'googletools', - # 'telecaster', - 'extra_views', - 'captcha', - 'django_user_agents', - 'tinymce', - 'multichoice', - 'true_false', - 'essay', - 'quiz', -) - -TEMPLATE_CONTEXT_PROCESSORS = ( - 'django.core.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'postman.context_processors.inbox', - "django.core.context_processors.i18n", - "django.core.context_processors.media", - 'django.core.context_processors.static', - "teleforma.context_processors.periods", -) - -TELEMETA_ORGANIZATION = 'Pre-Barreau - CRFPA' -TELEMETA_SUBJECTS = ('test', 'telemeta', 'sandbox') -TELEMETA_DESCRIPTION = "Telemeta TEST sandbox" -TELEMETA_GMAP_KEY = 'ABQIAAAArg7eSfnfTkBRma8glnGrlxRVbMrhnNNvToCbZQtWdaMbZTA_3RRGObu5PDoiBImgalVnnLU2yN4RMA' -TELEMETA_CACHE_DIR = MEDIA_ROOT + 'cache' -TELEMETA_EXPORT_CACHE_DIR = TELEMETA_CACHE_DIR + "/export" -TELEMETA_DATA_CACHE_DIR = TELEMETA_CACHE_DIR + "/data" - -TELEMETA_DOWNLOAD_ENABLED = True -TELEMETA_STREAMING_FORMATS = ('mp3', 'webm') -TELEMETA_DOWNLOAD_FORMATS = ('wav', 'mp3', 'webm') -TELEMETA_PUBLIC_ACCESS_PERIOD = 51 -TELEMETA_DEFAULT_GRAPHER_SIZES = ['360x130', '640x130'] -TELEMETA_DEFAULT_GRAPHER_ID = 'waveform_contour_wh' - -AUTH_PROFILE_MODULE = 'telemeta.userprofile' -LOGIN_URL = '/accounts/login/' -LOGIN_REDIRECT_URL = reverse_lazy('teleforma-desk') -SESSION_EXPIRE_AT_BROWSER_CLOSE = False - -EMAIL_HOST = 'smtp.numericable.fr' -DEFAULT_FROM_EMAIL = 'webmaster@parisson.com' -SERVER_EMAIL = 'webmaster@parisson.com' -EMAIL_SUBJECT_PREFIX = '[' + TELEMETA_ORGANIZATION.decode('utf8') + '] ' - -POSTMAN_AUTO_MODERATE_AS = True - -TELECASTER_CONF = [{'type':'mp3','server_type':'icecast','conf':'/etc/telecaster/deefuzzer_mp3.xml', 'port':'8000'}, - {'type':'webm','server_type':'stream-m','conf':'/etc/telecaster/deefuzzer_webm.xml', 'port':'8080'}, ] - -TELECASTER_RSYNC_SERVER = 'telecaster@jimi.parisson.com:archives/' -TELECASTER_RSYNC_LOG = '/var/log/telecaster/rsync.log' -TELECASTER_MASTER_SERVER = 'angus.parisson.com' - -# CRFPA or AE or PRO -TELEFORMA_E_LEARNING_TYPE = 'CRFPA' -TELEFORMA_GLOBAL_TWEETER = False -TELEFORMA_PERIOD_TWEETER = True -TELEFORMA_EXAM_TOPIC_DEFAULT_DOC_TYPE_NUMBER = 2 -TELEFORMA_EXAM_SCRIPT_UPLOAD = True -TELEFORMA_REGISTER_DEFAULT_DOC_ID = 1 - -JQCHAT_DISPLAY_COUNT = 50 -JQCHAT_DISPLAY_TIME = 48 - -BOX_API_TOKEN = 'D2pBaN8YqjGIfS0tKrgnMP93' - -SOUTH_MIGRATION_MODULES = { - 'captcha': 'captcha.south_migrations', -} - -SUIT_CONFIG = { - 'ADMIN_NAME': 'TeleForma Admin', -} - -# Cache backend is optional, but recommended to speed up user agent parsing -CACHES = { - 'default': { - 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', - 'LOCATION': '127.0.0.1:11211', - } -} - -# Name of cache backend to cache user agents. If it not specified default -# cache alias will be used. Set to `None` to disable caching. -USER_AGENTS_CACHE = 'default' - -AUTH_USER_MODEL = 'auth.User' - -TINYMCE_DEFAULT_CONFIG = { - 'plugins': "table,spellcheckerPeepOpenaste,searchreplace", - 'theme': "advanced", - 'cleanup_on_startup': True, - 'custom_undo_redo_levels': 10, -} diff --git a/example/urls.py b/example/urls.py deleted file mode 100644 index cf2c02d5..00000000 --- a/example/urls.py +++ /dev/null @@ -1,29 +0,0 @@ -# -*- coding: utf-8 -*- -from django.conf.urls.defaults import * - -# Uncomment the next two lines to enable the admin: -from django.contrib import admin -admin.autodiscover() - -js_info_dict = { - 'packages': ('telemeta','telecaster'), -} - -urlpatterns = patterns('', - # Example: - # (r'^sandbox/', include('sandbox.foo.urls')), - - # Uncomment the admin/doc line below and add 'django.contrib.admindocs' - # to INSTALLED_APPS to enable admin documentation: - # (r'^admin/doc/', include('django.contrib.admindocs.urls')), - url(r'^admin/django/', include(admin.site.urls)), - - # TeleForma - (r'^', include('teleforma.urls')), - # (r'^telecaster/', include('telecaster.urls')), - - # Languages - (r'^i18n/', include('django.conf.urls.i18n')), - (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict), - -) diff --git a/example/wsgi.py b/example/wsgi.py deleted file mode 100644 index d71b3b73..00000000 --- a/example/wsgi.py +++ /dev/null @@ -1,8 +0,0 @@ -import os - -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") - -# This application object is used by the development server -# as well as any WSGI server configured to use this file. -from django.core.wsgi import get_wsgi_application -application = get_wsgi_application() diff --git a/requirements-1.3.txt b/requirements-1.3.txt deleted file mode 100644 index 935065ed..00000000 --- a/requirements-1.3.txt +++ /dev/null @@ -1,156 +0,0 @@ -amqplib==1.0.2 -anyjson==0.3.1 -asv==0.2 -Babel==2.1.1 -backports.shutil-get-terminal-size==1.0.0 -backports.ssl-match-hostname==3.5.0.1 -beautifulsoup4==4.6.0 -bleach==1.2.2 -bs4==0.0.1 -cached-property==1.3.0 -celery==2.5.3 -certifi==14.5.14 -chardet==2.1.1 -cl==0.0.3 -configobj==4.7.2 -crocodoc==0.1.1 -decorator==4.0.10 -Django==1.4.10 -django-bootstrap-pagination==1.5.1 -django-bootstrap3==6.1.0 -django-cacheops==2.1.1 -django-celery==2.5.5 -django-debug-toolbar==1.0.1 -django-email-extras==0.1.13 -django-extensions==1.2.1 -#django-extra-views==0.6.5 -django-extra-views==0.7 -django-forms-builder==0.8.5 -django-google-tools==1.0.0 -django-json-rpc==0.6.1 -django-linguo==1.3.3 -django-longerusernameandemail==0.5.6 -django-markup-mixin==0.1.0 -django-model-utils==2.3.1 -django-mptt==0.5.2 -django-notes==0.2.2 -django-nvd3==0.8.2 -django-pagination==1.0.7 -django-picklefield==0.2.1 -django-redis-cache==0.13.0 -django-registration==1.0 -django-simple-captcha==0.4.4 -django-suit==0.2.12 -django-timezones==0.2 -django-tinymce==1.5.4 -django-user-agents==0.3.0 -docopt==0.6.2 -docutils==0.8.1 -enum34==1.1.6 -feedparser==5.1.3 -filebrowser-safe==0.2.28 -fpconst==0.7.2 -funcsigs==0.4 -functools32==3.2.3.post2 -funcy==1.2 -gdata==2.0.18 -html5lib==0.95 -httplib2==0.8 -ipaddress==1.0.17 -ipython==5.1.0 -ipython-genutils==0.1.0 -iso8601==0.1.11 -Jinja2==2.7.2 -jsonpatch==1.12 -jsonpointer==1.10 -jsonschema==2.5.1 -jxmlease -keyring==3.8 -keystoneauth1==2.1.0 -lockfile==0.8 -longerusername==0.4 -#lxml==3.3.1 -mailer==0.7 -Mako==0.7.0 -Markdown==2.1.1 -MarkupSafe==0.15 -mercurial==3.1.2 -mock==1.0.1 -monotonic==0.5 -msgpack-python==0.4.6 -mutagen==1.20 -#MySQL-python==1.2.3 -mysqlclient -NavAdd==0.1.1 -netaddr==0.7.18 -netifaces==0.10.4 -numpy==1.6.2 -oauth==1.0.1 -oauth2==1.5.211 -oauthlib==0.6.0 -oslo.config==3.2.0 -oslo.i18n==3.1.0 -oslo.serialization==2.2.0 -oslo.utils==3.3.0 -paramiko==1.10.1 -pathlib2==2.1.0 -pbr==1.8.1 -pexpect==4.2.1 -pickleshare==0.7.4 -Pillow==2.3.0 -prettytable==0.7.2 -prompt-toolkit==1.0.7 -pycosat==0.6.1 -pycrypto==2.6 -pydot==1.0.28 -pygit==0.1 -Pygments==2.1.3 -pylint==0.25.1 -pyparsing==1.5.6 -pyPdf==1.13 -python-dateutil==1.5 -#python-ebml==0.2 -#python-irclib==0.4.8 -python-keystoneclient==2.0.0 -python-nvd3==0.13.7 -python-openid==2.2.5 -python-slugify==0.0.9 -pytz==2013.9 -pyxdg==0.19 -PyYAML==3.12 -pyzmq==13.1.0 -redis==2.10.3 -reportlab==2.7 -requests==2.11.1 -requests-oauthlib==0.3.3 -scipy==0.10.1 -simplegeneric==0.8.1 -simplejson==2.5.2 -six==1.10.0 -sorl-thumbnail==11.12 -South==0.8.2 -Sphinx==1.1.3 -sphinx-me==0.2.1 -sqlparse==0.1.10 -texttable==0.8.7 -TimeSide==0.5.3 -traitlets==4.3.1 -ua-parser==0.3.6 -Unidecode==0.4.18 -unittest2==0.5.1 -urllib3==1.7.1 -user-agents==0.3.2 -uwsgitop==0.10 -vatnumber==1.1 -#vobject==0.8.1rc0 -wadllib==1.3.4 -warlock==1.2.0 -wcwidth==0.1.7 -websocket-client==0.40.0 -Werkzeug==0.9.4 -wrapt==1.10.6 -xhtml2pdf -xlrd==0.6.1 -xlwt==0.7.5 -zipstream==1.0.2 -zope.interface==3.6.1 diff --git a/requirements-debian.txt b/requirements-debian.txt deleted file mode 100644 index 64bb17ad..00000000 --- a/requirements-debian.txt +++ /dev/null @@ -1,5 +0,0 @@ -git -netcat -vim -locales -python-yaml diff --git a/requirements-dev.txt b/requirements-dev.txt index ac1d96e4..d1cc50e1 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,2 +1,2 @@ --e git+https://github.com/Parisson/django_quiz.git#egg=django_quiz-0.5.1 --e git+https://github.com/Parisson/TeleForma.git@tc202#egg=teleforma +ipdb==0.13.8 +django-debug-toolbar \ No newline at end of file diff --git a/requirements-new.txt b/requirements-new.txt deleted file mode 100644 index 80dc8fc3..00000000 --- a/requirements-new.txt +++ /dev/null @@ -1,9 +0,0 @@ -setuptools -uwsgi -django==1.6.11 -south -django-pagination -django-postman -django-extensions -django-notes -django-timezones diff --git a/requirements.txt b/requirements.txt index cc96fd4c..300919e9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,21 +1,37 @@ -setuptools -django==1.4.19 -telemeta==1.4.6 -south # a supprimer -django-pagination==1.0.7 # a supprimer -django-postman==3.2.0 -django-extensions==0.9 -django-notes # a supprimer -django-timezones==0.2 -django-jqchat -crocodoc # a supprimer -django-registration==0.8 -django-extra-views==0.6.5 # a supprimer -django-simple-captcha # a maj -django-suit # a maj -django-nvd3 -django-user-agents -xhtml2pdf -html5lib==0.95 -django-tinymce==1.5.4 -django-quiz # a supprimer +bigbluebutton-api-python==0.0.11 +docutils==0.17.1 +Django==3.2.13 +djangorestframework==3.13.1 +# django-extensions==1.2.1 +# django-timezones==0.2 +# django-registration==3.1.2 +dj_pagination==2.5.0 # used by postman +django-jazzmin==2.4.7 +django-json-rpc==0.7.1 +# django-google-tools==1.1.0 +django-nvd3==0.8.2 +django-postman==4.2 +django-tinymce==3.3.0 +-e git+https://git.parisson.com/git/django-unique-session.git@master#egg=django-unique-session +django-user-agents==0.4.0 +django-recaptcha==2.0.6 +jxmlease==1.0.3 +mysqlclient==2.0.3 +numpy==1.20.3 +# django-user-agents==0.3.0 +# html5lib==1.1 +requests +sorl-thumbnail==12.7.0 +unidecode==1.2.0 +weasyprint==52.5 +xlrd==2.0.1 +xlwt==1.3.0 +psycopg2==2.8.6 +redis==3.5.3 +uwsgi==2.0.19 +daphne==3.0.2 +pymemcache==3.4.4 +django-debug-toolbar==3.2.1 +uvicorn[standard]==0.18.1 +httpx==0.23.3 +ipython diff --git a/run-container-fg b/run-container-fg new file mode 100755 index 00000000..ae551769 --- /dev/null +++ b/run-container-fg @@ -0,0 +1,81 @@ +#!/usr/bin/python3 + +import yaml +import os +import sys +import shlex +import subprocess + +if not os.path.exists('./docker-compose.yml'): + print("This script requires a « docker-compose.yml » file in current directory.") + sys.exit(1) + +if len(sys.argv) < 2 or sys.argv[1].startswith('-'): + print("Syntax: %s [service] <...>" % sys.argv[0]) + print(" Will run the container named « service » from docker compose in foreground.") + print(" All extra arguments will be passed to Docker.") + sys.exit(1) + +with open('./docker-compose.yml') as f: + compose = yaml.load(f) + +service_name = sys.argv[1] + +services = compose['services'] +service = services.get(service_name, None) +if not service: + print("Service %s not found." % service_name) + sys.exit(1) + +command = sys.argv[2:] +if not command: + command = shlex.split(service.get('command', [])) + +_, compose_name = os.path.split(os.getcwd()) +network = '%s_default' % compose_name + +image = service.get('image', None) +if image is None: + image = '%s_%s' % (compose_name, service_name) + +i = 1 +while True: + name = image + '_%d' % i + print("Checking %s..." % name) + output = subprocess.check_output([ "docker", "ps", "-a", "--format={{.State}}", "--filter=name=%s" % name ]).strip() + if output == b'running': + print("Container %s already running, trying next..." % name) + i += 1 + continue + elif output in (b'exited', b'created'): + print("Cleaning %s..." % name) + output = subprocess.check_output([ "docker", "rm", name ]) + break + else: + break + +cmd_line = [ 'docker', 'run', '-it', + '--network', network, + '--name', name, + ] + +ports = service.get('ports', []) +for port in ports: + cmd_line.extend([ '-p', port ]) + +volumes = service.get('volumes', []) +for volume in volumes: + items = volume.split(':') + items[0] = os.path.abspath(items[0]) + volume = ':'.join(items) + cmd_line.extend([ '-v', volume ]) + +env_files = service.get('env_file', []) +for env_file in env_files: + cmd_line.extend([ '--env-file', env_file ]) + +cmd_line.append(image) +cmd_line.extend(command) + +print(" ".join(cmd_line)) +os.execvp('docker', cmd_line) diff --git a/wsgi.py b/wsgi.py deleted file mode 100644 index e69de29b..00000000 -- 2.39.5