From 5f17267ff7e324f5011bbe283e4250303b0f3e1c Mon Sep 17 00:00:00 2001 From: Marc Aymerich Date: Wed, 30 Sep 2015 16:26:44 +0000 Subject: [PATCH] Added preliminar support for Docker containers --- TODO.md | 6 ++-- orchestra/bin/orchestra-admin | 14 +------- orchestra/contrib/orchestration/helpers.py | 14 +++++--- orchestra/contrib/saas/forms.py | 9 +++--- orchestra/contrib/settings/parser.py | 7 +++- scripts/containers/Dockerfile | 4 +++ scripts/{container => containers}/create.sh | 0 scripts/{container => containers}/deploy.sh | 36 +++++++++++++-------- 8 files changed, 52 insertions(+), 38 deletions(-) create mode 100644 scripts/containers/Dockerfile rename scripts/{container => containers}/create.sh (100%) rename scripts/{container => containers}/deploy.sh (95%) diff --git a/TODO.md b/TODO.md index 37fddd0a..bb6f69f0 100644 --- a/TODO.md +++ b/TODO.md @@ -77,8 +77,6 @@ * prevent @pangea.org email addresses on contacts, enforce at least one email without @pangea.org -* forms autocomplete="off", doesn't work in chrome - ln -s /proc/self/fd /dev/fd @@ -388,3 +386,7 @@ Case # Modsecurity rules template by cms (wordpress, joomla, dokuwiki (973337 973338 973347 958057), ... + +# saas custom domains support (maybe a new form field with custom url? autoconfigure websites?) + custom_url form field and validate/create/delete related website + SAAS_PHPLIST_ALLOW_CUSTOM_URL = False diff --git a/orchestra/bin/orchestra-admin b/orchestra/bin/orchestra-admin index 79ce5453..462a09ed 100755 --- a/orchestra/bin/orchestra-admin +++ b/orchestra/bin/orchestra-admin @@ -28,19 +28,7 @@ function print_help () { ${bold}OPTIONS${normal} ${bold}install_requirements${normal} Installs Orchestra requirements using apt-get and pip - - ${bold}install_postfix${normal} - Installs postfix packages including dovecot, amavis, spamassassin and clamav - - ${bold}uninstall_postfix${normal} - Uninstall postfix packages including dovecot, amavis, spamassassin and clamav - - ${bold}install_certificate${normal} - Installs a valid all-purpose self signed certificate that is valid for the next ten years - - ${bold}uninstall_certificate${normal} - Uninstall certificate - + ${bold}startproject${normal} Creates a new Django-orchestra instance diff --git a/orchestra/contrib/orchestration/helpers.py b/orchestra/contrib/orchestration/helpers.py index 6da892fc..7c4ebf4d 100644 --- a/orchestra/contrib/orchestration/helpers.py +++ b/orchestra/contrib/orchestration/helpers.py @@ -19,8 +19,10 @@ def get_backends_help_text(backends): 'model': backend.model, 'related_models': str(backend.related_models), 'script_executable': backend.script_executable, - 'script_method': '.'.join((backend.script_method.__module__, backend.script_method.__name__)), - 'function_method': '.'.join((backend.function_method.__module__, backend.function_method.__name__)), + 'script_method': '.'.join( + (backend.script_method.__module__, backend.script_method.__name__)), + 'function_method': '.'.join( + (backend.function_method.__module__, backend.function_method.__name__)), 'actions': str(backend.actions), } help_text += textwrap.dedent(""" @@ -61,7 +63,9 @@ def send_report(method, args, log): backend = method.__self__.__class__.__name__ subject = '[Orchestra] %s execution %s on %s' % (backend, log.state, server) separator = "\n%s\n\n" % ('~ '*40,) - operations = '\n'.join([' '.join((op.action, get_instance_url(op))) for op in log.operations.all()]) + operations = '\n'.join( + [' '.join((op.action, get_instance_url(op))) for op in log.operations.all()] + ) log_url = reverse('admin:orchestration_backendlog_change', args=(log.pk,)) log_url = orchestra_settings.ORCHESTRA_SITE_URL + log_url message = separator.join([ @@ -143,7 +147,9 @@ def message_user(request, logs): _('{total} backend has been executed'), _('{total} backends have been executed'), total) - msg = msg.format(total=total, url=url, async_url=async_url, async=async, successes=successes) + msg = msg.format( + total=total, url=url, async_url=async_url, async=async, successes=successes + ) messages.success(request, mark_safe(msg + '.')) else: msg = async_msg.format(url=url, async_url=async_url, async=async) diff --git a/orchestra/contrib/saas/forms.py b/orchestra/contrib/saas/forms.py index de6fe887..ef6918d5 100644 --- a/orchestra/contrib/saas/forms.py +++ b/orchestra/contrib/saas/forms.py @@ -48,11 +48,12 @@ class SaaSPasswordForm(SaaSBaseForm): help_text=_("Passwords are not stored, so there is no way to see this " "service's password, but you can change the password using " "this form.")) - password1 = forms.CharField(label=_("Password"), validators=[validators.validate_password], - widget=forms.PasswordInput(attrs={'autocomplete': 'off'})) + password1 = forms.CharField(label=_("Password"), + widget=forms.PasswordInput(attrs={'autocomplete': 'off'}), + validators=[validators.validate_password]) password2 = forms.CharField(label=_("Password confirmation"), - widget=forms.PasswordInput, - help_text=_("Enter the same password as above, for verification.")) + widget=forms.PasswordInput, + help_text=_("Enter the same password as above, for verification.")) def __init__(self, *args, **kwargs): super(SaaSPasswordForm, self).__init__(*args, **kwargs) diff --git a/orchestra/contrib/settings/parser.py b/orchestra/contrib/settings/parser.py index 07c3345e..f38a60e2 100644 --- a/orchestra/contrib/settings/parser.py +++ b/orchestra/contrib/settings/parser.py @@ -1,5 +1,6 @@ import ast import copy +import json import os import re @@ -91,7 +92,11 @@ def serialize(obj, init=True): def _format_setting(name, value): if isinstance(value, Remove): return "" - value = serialize(eval(value), get_eval_context()) + value = eval(value, get_eval_context()) + try: + value = json.dumps(value, indent=4) + except TypeError: + value = serialize(value) return "{name} = {value}".format(name=name, value=value) diff --git a/scripts/containers/Dockerfile b/scripts/containers/Dockerfile new file mode 100644 index 00000000..f8173ac9 --- /dev/null +++ b/scripts/containers/Dockerfile @@ -0,0 +1,4 @@ +FROM debian:latest +RUN apt-get -y update && apt-get install -y git screen sudo python3 python3-pip wget curl dnsutils rsyslog nano ssh-client +RUN export TERM=xterm; curl https://raw.githubusercontent.com/glic3rinu/django-orchestra/master/orchestra/bin/orchestra-admin | bash -s install_requirements +RUN apt-get clean diff --git a/scripts/container/create.sh b/scripts/containers/create.sh similarity index 100% rename from scripts/container/create.sh rename to scripts/containers/create.sh diff --git a/scripts/container/deploy.sh b/scripts/containers/deploy.sh similarity index 95% rename from scripts/container/deploy.sh rename to scripts/containers/deploy.sh index d60a7f44..7891e69b 100755 --- a/scripts/container/deploy.sh +++ b/scripts/containers/deploy.sh @@ -6,8 +6,22 @@ set -ue -bold=$(tput bold) -normal=$(tput sgr0) +function main () { + + +bold=$(tput -T ${TERM:-xterm} bold) +normal=$(tput -T ${TERM:-xterm} sgr0) + +surun () { + echo " ${bold}\$ su $USER -c \"${@}\"${normal}" + su $USER -c "${@}" +} + + +run () { + echo " ${bold}\$ ${@}${normal}" + ${@} +} [ $(whoami) != 'root' ] && { @@ -25,17 +39,6 @@ PYTHON_BIN="python3" CELERY=false -surun () { - echo " ${bold}\$ su $USER -c \"${@}\"${normal}" - su $USER -c "${@}" -} - -run () { - echo " ${bold}\$ ${@}${normal}" - ${@} -} - - # Create a system user for running Orchestra useradd $USER -s "/bin/bash" || true echo "$USER:$PASSWORD" | chpasswd @@ -72,7 +75,7 @@ fi run "apt-get -y install postgresql" if [[ ! $(sudo su postgres -c "psql -lqt" | awk {'print $1'} | grep '^orchestra$') ]]; then - # orchestra database does not esists + # orchestra database does not exists # Speeding up tests, don't do this in production! . /usr/share/postgresql-common/init.d-functions POSTGRES_VERSION=$(psql --version | head -n1 | sed -r "s/^.*\s([0-9]+\.[0-9]+).*/\1/") @@ -142,3 +145,8 @@ ${bold} - password: $PASSWORD ${normal} EOF + +} + +# Wrap it all on a function to avoid partial executions when running through wget/curl +main