Merge lp:~danilo/linaro-license-protection/django-refactor-deployment into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Данило Шеган
Status: Rejected
Rejected by: Milo Casagrande
Proposed branch: lp:~danilo/linaro-license-protection/django-refactor-deployment
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Prerequisite: lp:~danilo/linaro-license-protection/django-refactor
Diff against target: 411 lines (+391/-0)
4 files modified
deploy.py (+147/-0)
deployment_templates/linaro-license-protection.apache2.conf (+41/-0)
deployment_templates/settings.py (+167/-0)
deployment_templates/wsgi.py (+36/-0)
To merge this branch: bzr merge lp:~danilo/linaro-license-protection/django-refactor-deployment
Reviewer Review Type Date Requested Status
Данило Шеган (community) Disapprove
Review via email: mp+114409@code.launchpad.net
To post a comment you must log in.
91. By Данило Шеган

Merge latest django-refactor.

Revision history for this message
Данило Шеган (danilo) wrote :

I'd rather see apache conf integrated into the documentation, and everything deployed in a standard django-manner.

review: Disapprove

Unmerged revisions

91. By Данило Шеган

Merge latest django-refactor.

90. By Данило Шеган

Re-add deployment scripts.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'deploy.py'
--- deploy.py 1970-01-01 00:00:00 +0000
+++ deploy.py 2012-07-11 12:58:19 +0000
@@ -0,0 +1,147 @@
1#!/usr/bin/python
2import os
3import re
4from subprocess import check_call, call
5import sys
6
7# This script takes care of downloading the linaro-license-protection code and
8# installing it onto a server using the configuration dictionary below for
9# commonly changed settings.
10
11config = {
12 # Where to check the django app out to
13 "django_root": "/home/dooferlad/linaro-license-protection",
14
15 # Used in apache configuration...
16 "virtual_host_ip_address_and_port": "_default_",
17 "server_admin_email_address": "admin@linaro.org",
18
19 # Base path that will get searched for files to serve
20 # In theory there can be more than one XSendFilePath in an apache
21 # config and mod_xsendfile will search all of them. This isn't something
22 # that has been tested, but in theory will work and should allow serving
23 # files from an expanding number of mount points as disk space requirements
24 # grow.
25 "x_send_file_path": "/home/dooferlad/linaro-license-protection/android",
26
27 # Apache config file name
28 "apache2_site_config":
29 "/etc/apache2/sites-available/linaro-license-protection",
30
31 # Postgresql database name
32 "database_name": "linaro-license-protection-2",
33}
34
35# Derived variables
36config["deploy_root"] = os.path.dirname(config["django_root"])
37config["django_directory_name"] = os.path.basename(config["django_root"])
38config["a2_site_name"] = os.path.basename(config["apache2_site_config"])
39
40def main():
41 print "Installing Bazaar"
42 run("sudo apt-get -y install bzr")
43
44 print "Fetching linaro-license-protection code from bzr"
45 if os.path.isdir(config["django_root"]):
46 os.chdir(config["django_root"])
47 run("bzr update")
48 else:
49 run("bzr branch lp:~linaro-infrastructure/linaro-license-protection/"
50 "merge-django-into-trunk " + config["django_root"])
51
52 print "Installing python modules"
53 run("sudo apt-get -y install python-django python-django-openid-auth"
54 " python-mock python-psycopg2 testrepository")
55
56 print "Running unit tests (sqlite database)"
57 os.chdir(config["django_root"])
58 run("python manage.py test")
59
60 print "Installing required apache modules"
61 run("sudo apt-get -y install apache2 libapache2-mod-xsendfile"
62 " libapache2-mod-wsgi")
63
64 print "Installing database"
65 run("sudo apt-get -y install postgresql")
66 run_allow_fail("sudo -u postgres createuser -dSR linaro")
67 run_allow_fail("sudo -u postgres createdb " + config["database_name"])
68
69 print "Creating configuration files..."
70 generated_apache_config = os.path.join(
71 config["django_root"], "deployment_templates",
72 "linaro-license-protection.apache2.conf.gen")
73
74 create_config_file(os.path.join(
75 config["django_root"], "deployment_templates",
76 "linaro-license-protection.apache2.conf"),
77 generated_apache_config)
78
79 run("sudo mv " + generated_apache_config + " " +
80 config["apache2_site_config"])
81
82 create_config_file(os.path.join(config["django_root"],
83 "deployment_templates",
84 "wsgi.py"),
85 os.path.join(config["django_root"],
86 "license_protected_downloads",
87 "wsgi.py"))
88
89 create_config_file(os.path.join(config["django_root"],
90 "deployment_templates",
91 "settings.py"),
92 os.path.join(config["django_root"],
93 "settings.py"))
94
95 print "Deploying files to static root for serving"
96 run("python manage.py collectstatic --noinput")
97
98 print "Reloading Apache"
99 run("sudo service apache2 reload")
100
101 print "Set up database"
102 os.chdir(config["django_root"])
103 run("python manage.py syncdb --noinput")
104
105 print "Running unit tests (django database)"
106 os.chdir(config["django_root"])
107 run("python manage.py test")
108
109 print "Enabling new site"
110 run("sudo a2ensite " + config["a2_site_name"])
111 run("sudo service apache2 reload")
112
113 # Note, we don't run these because they have hard links to sites in.
114 # May be useful during a production deployment though...
115 if False:
116 print "Running deployment tests"
117 os.chdir(config["django_root"])
118 run("testr run testplans.test_suite")
119
120def run(cmd):
121 print "-" * 80
122 print cmd
123 check_call(cmd, shell=True)
124
125def run_allow_fail(cmd):
126 print "-" * 80
127 print cmd
128 call(cmd, shell=True)
129
130def template_lookup(match):
131 if match.group(1) in config:
132 return config[match.group(1)]
133 else:
134 print >> sys.stderr, ("Template used undefined variable %s" %
135 match.group(1))
136 exit(1)
137
138def create_config_file(in_file_name, out_file_name):
139 print "Processing %s to create %s" % (in_file_name, out_file_name)
140 with open(in_file_name) as in_file:
141 with open(out_file_name, "w") as out_file:
142 for line in in_file:
143 line = re.sub(r"\{% (\w+) %\}", template_lookup, line)
144 out_file.write(line)
145
146if __name__ == "__main__":
147 main()
0148
=== added directory 'deployment_templates'
=== added file 'deployment_templates/linaro-license-protection.apache2.conf'
--- deployment_templates/linaro-license-protection.apache2.conf 1970-01-01 00:00:00 +0000
+++ deployment_templates/linaro-license-protection.apache2.conf 2012-07-11 12:58:19 +0000
@@ -0,0 +1,41 @@
1NameVirtualHost {% virtual_host_ip_address_and_port %}
2
3<VirtualHost {% virtual_host_ip_address_and_port %}>
4 Alias /static/ {% django_root %}/static/
5
6 <Directory {% django_root %}/static>
7 Order deny,allow
8 Allow from all
9 </Directory>
10
11 ServerAdmin {% server_admin_email_address %}
12
13 XSendFile on
14 XSendFilePath {% x_send_file_path %}
15
16 WSGIScriptAlias / {% django_root %}/license_protected_downloads/wsgi.py
17 WSGIDaemonProcess linaro-license-protection
18
19 <Directory {% django_root %}/license_protected_downloads>
20 <Files wsgi.py>
21 Order deny,allow
22 Allow from all
23 </Files>
24 </Directory>
25
26 <Directory />
27 Options FollowSymLinks
28 AllowOverride None
29 </Directory>
30 <Directory />
31 Options FollowSymLinks
32 AllowOverride None
33 </Directory>
34 <Directory /var/www/>
35 Options Indexes FollowSymLinks MultiViews
36 AllowOverride None
37 Order allow,deny
38 allow from all
39 </Directory>
40
41</VirtualHost>
042
=== added file 'deployment_templates/settings.py'
--- deployment_templates/settings.py 1970-01-01 00:00:00 +0000
+++ deployment_templates/settings.py 2012-07-11 12:58:19 +0000
@@ -0,0 +1,167 @@
1# Django settings for linaro_license_protection_2 project.
2
3import os
4
5DEBUG = False
6
7PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
8ROOT_DIR = os.path.split(PROJECT_ROOT)[-1]
9
10ADMINS = (
11 ('Linaro Infrastructure', 'infrastructure@linaro.org'),
12)
13
14MANAGERS = ADMINS
15
16DATABASES = {
17 'default': {
18 'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
19 'NAME': '{% database_name %}', # Or path to database file if using sqlite3.
20 'USER': 'linaro', # Not used with sqlite3.
21 'PASSWORD': '', # Not used with sqlite3.
22 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
23 'PORT': '', # Set to empty string for default. Not used with sqlite3.
24 }
25}
26
27# Local time zone for this installation. Choices can be found here:
28# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
29# although not all choices may be available on all operating systems.
30# On Unix systems, a value of None will cause Django to use the same
31# timezone as the operating system.
32# If running in a Windows environment this must be set to the same as your
33# system time zone.
34TIME_ZONE = 'America/Chicago'
35
36# Language code for this installation. All choices can be found here:
37# http://www.i18nguy.com/unicode/language-identifiers.html
38LANGUAGE_CODE = 'en-us'
39
40SITE_ID = 1
41
42# If you set this to False, Django will make some optimizations so as not
43# to load the internationalization machinery.
44USE_I18N = True
45
46# If you set this to False, Django will not format dates, numbers and
47# calendars according to the current locale
48USE_L10N = True
49
50# Absolute filesystem path to the directory that will hold user-uploaded files.
51# Example: "/home/media/media.lawrence.com/media/"
52MEDIA_ROOT = ''
53
54# URL that handles the media served from MEDIA_ROOT. Make sure to use a
55# trailing slash.
56# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
57MEDIA_URL = ''
58
59# Absolute path to the directory static files should be collected to.
60# Don't put anything in this directory yourself; store your static files
61# in apps' "static/" subdirectories and in STATICFILES_DIRS.
62# Example: "/home/media/media.lawrence.com/static/"
63STATIC_ROOT = os.path.join(PROJECT_ROOT, "static")
64
65# URL prefix for static files.
66# Example: "http://media.lawrence.com/static/"
67STATIC_URL = '/static/'
68
69# URL prefix for admin static files -- CSS, JavaScript and images.
70# Make sure to use a trailing slash.
71# Examples: "http://foo.com/static/admin/", "/static/admin/".
72ADMIN_MEDIA_PREFIX = '/static/admin/'
73
74# Additional locations of static files
75STATICFILES_DIRS = (
76 # Put strings here, like "/home/html/static" or "C:/www/django/static".
77 # Always use forward slashes, even on Windows.
78 # Don't forget to use absolute paths, not relative paths.
79)
80
81# List of finder classes that know how to find static files in
82# various locations.
83STATICFILES_FINDERS = (
84 'django.contrib.staticfiles.finders.FileSystemFinder',
85 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
86# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
87)
88
89# Make this unique, and don't share it with anybody.
90SECRET_KEY = 'lkye^=q_i(#jies7^cz#anqq(1g0k$luy5^1jr2nk=g#inet(n'
91
92# List of callables that know how to import templates from various sources.
93TEMPLATE_LOADERS = (
94 'django.template.loaders.filesystem.Loader',
95 'django.template.loaders.app_directories.Loader',
96# 'django.template.loaders.eggs.Loader',
97)
98
99MIDDLEWARE_CLASSES = (
100 'django.middleware.common.CommonMiddleware',
101 'django.contrib.sessions.middleware.SessionMiddleware',
102 'django.middleware.csrf.CsrfViewMiddleware',
103 'django.contrib.auth.middleware.AuthenticationMiddleware',
104 'django.contrib.messages.middleware.MessageMiddleware',
105)
106
107ROOT_URLCONF = ROOT_DIR + '.urls'
108
109TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, "templates" ),)
110
111INSTALLED_APPS = (
112 'django.contrib.auth',
113 'django.contrib.contenttypes',
114 'django.contrib.sessions',
115 'django.contrib.sites',
116 'django.contrib.messages',
117 'django.contrib.staticfiles',
118 # Uncomment the next line to enable the admin:
119 'django.contrib.admin',
120 'django_openid_auth',
121 # Uncomment the next line to enable admin documentation:
122 # 'django.contrib.admindocs',
123 ROOT_DIR + '.license_protected_downloads',
124)
125
126AUTHENTICATION_BACKENDS = (
127 'django_openid_auth.auth.OpenIDBackend',
128 'django.contrib.auth.backends.ModelBackend',
129)
130
131LOGIN_URL = '/openid/login/'
132
133OPENID_CREATE_USERS = True
134OPENID_SSO_SERVER_URL = 'https://login.launchpad.net/'
135OPENID_LAUNCHPAD_TEAMS_MAPPING = {
136 'linaro': 'linaro',
137}
138
139# A sample logging configuration. The only tangible logging
140# performed by this configuration is to send an email to
141# the site admins on every HTTP 500 error.
142# See http://docs.djangoproject.com/en/dev/topics/logging for
143# more details on how to customize your logging configuration.
144LOGGING = {
145 'version': 1,
146 'disable_existing_loggers': False,
147 'handlers': {
148 'mail_admins': {
149 'level': 'ERROR',
150 'class': 'django.utils.log.AdminEmailHandler'
151 }
152 },
153 'loggers': {
154 'django.request': {
155 'handlers': ['mail_admins'],
156 'level': 'ERROR',
157 'propagate': True,
158 },
159 }
160}
161
162SERVED_PATHS = ["{% x_send_file_path %}"]
163
164TEMPLATE_CONTEXT_PROCESSORS = (
165 'django.contrib.messages.context_processors.messages',
166 'django.contrib.auth.context_processors.auth',
167)
0168
=== added file 'deployment_templates/wsgi.py'
--- deployment_templates/wsgi.py 1970-01-01 00:00:00 +0000
+++ deployment_templates/wsgi.py 2012-07-11 12:58:19 +0000
@@ -0,0 +1,36 @@
1"""
2WSGI config for license_protected_downloads project.
3
4This module contains the WSGI application used by Django's development server
5and any production WSGI deployments. It should expose a module-level variable
6named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
7this application via the ``WSGI_APPLICATION`` setting.
8
9Usually you will have the standard Django WSGI application here, but it also
10might make sense to replace the whole Django WSGI application with a custom one
11that later delegates to the Django one. For example, you could introduce WSGI
12middleware here, or combine a Django application with an application of another
13framework.
14
15"""
16import os, sys
17sys.path.append("/usr/lib/python2.7/dist-packages")
18sys.path.append("/usr/lib/pymodules/python2.7")
19sys.path.append("/usr/lib/python2.7")
20sys.path.append("{% django_root %}")
21sys.path.append("{% deploy_root %}")
22
23os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{% django_directory_name %}.settings")
24
25# This application object is used by any WSGI server configured to use this
26# file. This includes Django's development server, if the WSGI_APPLICATION
27# setting points here.
28#from django.core.wsgi import get_wsgi_application
29#application = get_wsgi_application()
30
31import django.core.handlers.wsgi
32application = django.core.handlers.wsgi.WSGIHandler()
33
34# Apply WSGI middleware here.
35# from helloworld.wsgi import HelloWorldApplication
36# application = HelloWorldApplication(application)

Subscribers

People subscribed via source and target branches