Fixes on deployment

This commit is contained in:
Marc Aymerich 2015-10-01 18:57:31 +00:00
parent 45cc7b215c
commit 00eb988952
3 changed files with 47 additions and 35 deletions

View File

@ -161,7 +161,6 @@ ORCHESTRA_SITE_NAME = '{{ project_name }}'
MIDDLEWARE_CLASSES = ( MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',

View File

@ -1,4 +1,5 @@
import os import os
import textwrap
from optparse import make_option from optparse import make_option
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -38,32 +39,42 @@ class Command(BaseCommand):
'db_user': options.get('db_user'), 'db_user': options.get('db_user'),
'db_password': options.get('db_password'), 'db_password': options.get('db_password'),
'db_host': options.get('db_host'), 'db_host': options.get('db_host'),
'db_port': options.get('db_port') } 'db_port': options.get('db_port'),
}
run('su postgres -c "psql -c \\"CREATE USER %(db_user)s PASSWORD \'%(db_password)s\';\\""' % context, valid_codes=(0,1)) run(textwrap.dedent("""\
run('su postgres -c "psql -c \\"CREATE DATABASE %(db_name)s OWNER %(db_user)s;\\""' % context, valid_codes=(0,1)) su postgres -c "psql -c \\"CREATE USER %(db_user)s PASSWORD '%(db_password)s';\\""
context.update({'settings': os.path.join(get_project_dir(), 'settings.py')}) su postgres -c "psql -c \\"CREATE DATABASE %(db_name)s OWNER %(db_user)s;\\""\
""") % context, valid_codes=(0,1)
)
context.update({
'settings': os.path.join(get_project_dir(), 'settings.py')
})
if run("grep 'DATABASES' %(settings)s" % context, valid_codes=(0,1)).exit_code == 0: if run("grep '^DATABASES\s*=\s*{' %(settings)s" % context, valid_codes=(0,1)).exit_code == 0:
# Update existing settings_file # Update existing settings_file
run("sed -i \"s/'ENGINE': '\w*',/'ENGINE': 'django.db.backends.postgresql_psycopg2',/\" %(settings)s" % context) run(textwrap.dedent("""\
run("sed -i \"s/'NAME': '.*',/'NAME': '%(db_name)s',/\" %(settings)s" % context) sed -i "s/'ENGINE': '[^']*',/'ENGINE': 'django.db.backends.postgresql_psycopg2',/" %(settings)s
run("sed -i \"s/'USER': '.*',/'USER': '%(db_user)s',/\" %(settings)s" % context) sed -i "s/'NAME': '[^']*',/'NAME': '%(db_name)s',/" %(settings)s
run("sed -i \"s/'PASSWORD': '.*',/'PASSWORD': '%(db_password)s',/\" %(settings)s" % context) sed -i "s/'USER': '[^']*',/'USER': '%(db_user)s',/" %(settings)s
run("sed -i \"s/'HOST': '.*',/'HOST': '%(db_host)s',/\" %(settings)s" % context) sed -i "s/'PASSWORD': '[^']*',/'PASSWORD': '%(db_password)s',/" %(settings)s
run("sed -i \"s/'PORT': '.*',/'PORT': '%(db_port)s',/\" %(settings)s" % context) sed -i "s/'HOST': '[^']*',/'HOST': '%(db_host)s',/" %(settings)s
sed -i "s/'PORT': '[^']*',/'PORT': '%(db_port)s',/" %(settings)s\
""") % context
)
else: else:
db_config = ( db_config = textwrap.dedent("""\
"DATABASES = {\n" DATABASES = {
" 'default': {\n" 'default': {
" 'ENGINE': 'django.db.backends.postgresql_psycopg2',\n" 'ENGINE': 'django.db.backends.postgresql_psycopg2',
" 'NAME': '%(db_name)s',\n" 'NAME': '%(db_name)s',
" 'USER': '%(db_user)s',\n" 'USER': '%(db_user)s',
" 'PASSWORD': '%(db_password)s',\n" 'PASSWORD': '%(db_password)s',
" 'HOST': '%(db_host)s',\n" 'HOST': '%(db_host)s',
" 'PORT': '%(db_port)s',\n" 'PORT': '%(db_port)s',
" 'ATOMIC_REQUESTS': True,\n" 'ATOMIC_REQUESTS': True,
" }\n" }
"}\n" % context) }""") % context
)
context.update({'db_config': db_config}) context.update({'db_config': db_config})
run('echo "%(db_config)s" >> %(settings)s' % context) run('echo "%(db_config)s" >> %(settings)s' % context)

View File

@ -37,7 +37,9 @@ function main () {
done done
# TODO Password: Password (again): # TODO Password: Password (again):
# TODO detect if already installed and don't ask stupid question
# TODO setupceleryd shoudl change orchestra_start/stop/restart_services
# TODO setuppostgres should configure the fucking backend
read -p "Enter a new database password: " db_password read -p "Enter a new database password: " db_password
while true; do while true; do
@ -60,25 +62,25 @@ function main () {
run cd $project_name run cd $project_name
sudo service postgresql start sudo service postgresql start
run sudo python3 manage.py setuppostgres --db_password "$db_password" run sudo python3 -W ignore manage.py setuppostgres --db_password "$db_password"
run python3 manage.py migrate run python3 -W ignore manage.py migrate
if [[ "$task" == "cronbeat" ]]; then if [[ "$task" == "cronbeat" ]]; then
run python3 manage.py setupcronbeat run python3 -W ignore manage.py setupcronbeat
run python3 manage.py syncperiodictasks run python3 -W ignore manage.py syncperiodictasks
else else
run sudo apt-get install rabbitmq run sudo apt-get install rabbitmq
run sudo python3 manage.py setupcelery --username $USER run sudo python3 -W ignore manage.py setupcelery --username $USER
fi fi
run sudo python3 manage.py setuplog --noinput run sudo python3 -W ignore manage.py setuplog --noinput
run python3 manage.py collectstatic --noinput run python3 -W ignore manage.py collectstatic --noinput
run sudo apt-get install nginx-full uwsgi uwsgi-plugin-python3 run sudo apt-get install nginx-full uwsgi uwsgi-plugin-python3
run sudo python3 manage.py setupnginx --user $USER run sudo python3 -W ignore manage.py setupnginx --user $USER
run sudo python3 manage.py startservices run sudo python3 -W ignore manage.py startservices
run python3 manage.py check --deploy run python3 -W ignore manage.py check --deploy
} }
# Wrap it all on a function to avoid partial executions when running through wget/curl # Wrap it all on a function to avoid partial executions when running through wget/curl