Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial

  • Loading branch information...
commit 98c1e2b4332a70ad1cfdf9e3e9870166a4a408ab 0 parents
@michiya authored
5 .gitignore
@@ -0,0 +1,5 @@
+*.cspkg
+*.csx
+*.log
+*.pyc
+*.pyo
42 README.md
@@ -0,0 +1,42 @@
+heliconzoo-django-role
+======================
+This is a simple scaffold powered by [Helicon Zoo](http://www.helicontech.com/zoo/)
+for packaging Django applications to run on Windows Azure and SQL Azure.
+
+Prerequisites
+-------------
+
+You will need to install the following software on your local computer.
+You can use [Web Platform Installer](http://www.microsoft.com/web/downloads/platform.aspx)
+to install them easily.
+
+* Windows Azure SDK
+* Python 2.7
+* Helicon Zoo Module
+* SQL Server Express 2008 R2
+
+And the following Python packages are also required on your Python installation,
+the script `WebRole/bin/install-requirements.cmd` in this scaffold may be helpful
+when you install them.
+
+* Django
+* [pyodbc](http://code.google.com/p/pyodbc/)
+* [django-pyodbc](http://code.google.com/p/django-pyodbc/)
+
+Usage
+-----
+
+1. Create your Django applications into `WebRole/project` directory,
+and add any other Python packages you use to `WebRole/requirements.txt`.
+
+2. Turn IIS feature on and run `run.cmd` on your Windows Azure Command Prompt
+to run the application on your local emulator.
+
+3. Run `pack.cmd` on your Windows Azure Command Prompt to output `heliconzoo-django-role.cspkg`.
+That file, along with `ServiceConfiguration.Cloud.cscfg` is what you need to deploy
+via the Windows Azure portal (or with some other tool) to get the applications running in the cloud.
+
+License
+-------
+
+Licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
8 ServiceConfiguration.Cloud.cscfg
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ServiceConfiguration serviceName="heliconzoo-django-role" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="2" osVersion="*">
+ <Role name="WebRole">
+ <Instances count="1" />
+ <ConfigurationSettings>
+ </ConfigurationSettings>
+ </Role>
+</ServiceConfiguration>
8 ServiceConfiguration.Local.cscfg
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ServiceConfiguration serviceName="heliconzoo-django-role" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="2" osVersion="*">
+ <Role name="WebRole">
+ <Instances count="1" />
+ <ConfigurationSettings>
+ </ConfigurationSettings>
+ </Role>
+</ServiceConfiguration>
32 ServiceDefinition.csdef
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ServiceDefinition name="heliconzoo-django-role" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
+ <WebRole name="WebRole" enableNativeCodeExecution="true">
+ <Sites>
+ <Site name="Web" physicalDirectory="./WebRole">
+ <Bindings>
+ <Binding name="Endpoint1" endpointName="HttpEndpoint" />
+ </Bindings>
+ </Site>
+ </Sites>
+ <Startup>
+ <Task commandLine="startup.cmd" executionContext="elevated" taskType="simple" >
+ <Environment>
+ <Variable name="EMULATED">
+ <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
+ </Variable>
+ <Variable name="LOCAL_RESOURCE_TMP_DIR">
+ <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/LocalResources/LocalResource[@name='tmp']/@path" />
+ </Variable>
+ </Environment>
+ </Task>
+ </Startup>
+ <Endpoints>
+ <InputEndpoint name="HttpEndpoint" protocol="http" port="80" />
+ </Endpoints>
+ <ConfigurationSettings>
+ </ConfigurationSettings>
+ <LocalResources>
+ <LocalStorage name="tmp" cleanOnRoleRecycle="true" sizeInMB="1000" />
+ </LocalResources>
+ </WebRole>
+</ServiceDefinition>
70 WebRole/bin/install-requirements.cmd
@@ -0,0 +1,70 @@
+@echo off
+
+echo Starting installation of requirements...
+
+REM Helicon Zoo requires Python to be there
+set PYTHON_INSTALL_DIR=%SystemDrive%\Python27
+
+REM test installation prerequisites
+if not exist %PYTHON_INSTALL_DIR%\python.exe (
+echo ERROR: %PYTHON_INSTALL_DIR%\python.exe is missing.
+exit /b 1
+)
+if not exist %SystemDrive%\Zoo (
+echo ERROR: %SystemDrive%\Zoo is missing.
+exit /b 1
+)
+
+if "%LOCAL_RESOURCE_TMP_DIR%"=="" set LOCAL_RESOURCE_TMP_DIR=%TMP%\
+echo temporary download directory is set to [%LOCAL_RESOURCE_TMP_DIR%]
+
+cd /d "%~dp0"
+
+%PYTHON_INSTALL_DIR%\python -c "import sys; print sys.version" | find "64 bit"
+set PYTHON_X86=%ERRORLEVEL%
+
+echo installing subversion...
+if exist %LOCAL_RESOURCE_TMP_DIR%svn-win32\bin\svn.exe goto INSTALL_SETUPTOOLS
+powershell -c "(new-object System.Net.WebClient).DownloadFile('http://downloads.sourceforge.net/project/win32svn/1.7.2/svn-win32-1.7.2.zip', '%LOCAL_RESOURCE_TMP_DIR%svn-win32-1.7.2.zip')"
+%SystemDrive%\Zoo\Tools\7za x -o%LOCAL_RESOURCE_TMP_DIR% -y %LOCAL_RESOURCE_TMP_DIR%svn-win32-1.7.2.zip
+ren %LOCAL_RESOURCE_TMP_DIR%svn-win32-1.7.2 svn-win32
+
+:INSTALL_SETUPTOOLS
+echo installing setuptools...
+if exist %PYTHON_INSTALL_DIR%\Scripts\easy_install.exe goto INSTALL_PIP
+powershell -c "(new-object System.Net.WebClient).DownloadFile('http://peak.telecommunity.com/dist/ez_setup.py', '%LOCAL_RESOURCE_TMP_DIR%easy_setup.py')"
+%PYTHON_INSTALL_DIR%\python %LOCAL_RESOURCE_TMP_DIR%easy_setup.py
+
+:INSTALL_PIP
+echo installing pip...
+if exist %PYTHON_INSTALL_DIR%\Scripts\pip.exe goto INSTALL_PYODBC
+%PYTHON_INSTALL_DIR%\Scripts\easy_install pip
+
+:INSTALL_PYODBC
+echo installing pyodbc...
+%PYTHON_INSTALL_DIR%\python -c "import pyodbc" 2>nul
+if "%ERRORLEVEL%"=="0" goto INSTALL_DJANGO_PYODBC
+if "%PYTHON_X86%"=="0" goto INSTALL_PYODBC_X64
+%SystemDrive%\Python27\Scripts\easy_install -Z pyodbc==3.0.2
+goto INSTALL_DJANGO_PYODBC
+
+:INSTALL_PYODBC_X64
+powershell -c "(new-object System.Net.WebClient).DownloadFile('http://pyodbc.googlecode.com/files/pyodbc-3.0.2.win-amd64-py2.7.exe', '%LOCAL_RESOURCE_TMP_DIR%pyodbc.exe')"
+%SystemDrive%\Zoo\Tools\7za x -o%LOCAL_RESOURCE_TMP_DIR%pyodbc -y %LOCAL_RESOURCE_TMP_DIR%pyodbc.exe
+xcopy /e /h /y %LOCAL_RESOURCE_TMP_DIR%pyodbc\PLATLIB\* %PYTHON_INSTALL_DIR%\Lib\site-packages
+
+:INSTALL_DJANGO_PYODBC
+echo installing django-pyodbc...
+%PYTHON_INSTALL_DIR%\python -c "import sql_server.pyodbc" 2>nul
+if "%ERRORLEVEL%"=="0" goto INSTALL_REQUIREMENTS
+cd /d %LOCAL_RESOURCE_TMP_DIR%
+%LOCAL_RESOURCE_TMP_DIR%svn-win32\bin\svn checkout http://django-pyodbc.googlecode.com/svn/trunk/ django-pyodbc
+cd .\django-pyodbc
+%PYTHON_INSTALL_DIR%\python setup.py install
+cd /d "%~dp0"
+
+:INSTALL_REQUIREMENTS
+echo installing required packages...
+%SystemDrive%\Python27\Scripts\pip install --timeout=600 --default-timeout=600 -r ..\requirements.txt
+
+echo Completed installation of requirements.
35 WebRole/bin/install.cmd
@@ -0,0 +1,35 @@
+@echo off
+
+echo Starting installation...
+
+if not "%1"=="" set PYTHON_ARCH=.%1
+
+REM Helicon Zoo requires Python to be there
+set PYTHON_INSTALL_DIR=%SystemDrive%\Python27
+
+if "%LOCAL_RESOURCE_TMP_DIR%"=="" set LOCAL_RESOURCE_TMP_DIR=%TMP%\
+
+cd /d "%~dp0"
+
+md "%~dp0appdata"
+reg add "hku\.default\software\microsoft\windows\currentversion\explorer\user shell folders" /v "Local AppData" /t REG_EXPAND_SZ /d "%~dp0appdata" /f
+
+echo installing Python...
+powershell -c "(new-object System.Net.WebClient).DownloadFile('http://www.python.org/ftp/python/2.7.2/python-2.7.2%PYTHON_ARCH%.msi', '%LOCAL_RESOURCE_TMP_DIR%python27.msi')"
+msiexec /i %LOCAL_RESOURCE_TMP_DIR%python27.msi /qn TARGET_DIR=%PYTHON_INSTALL_DIR%
+
+echo installing WebPICmdLine...
+powershell -c "(new-object System.Net.WebClient).DownloadFile('http://www.iis.net/community/files/webpi/webpicmdline_anycpu.zip', '%LOCAL_RESOURCE_TMP_DIR%webpicmdline.zip')"
+%PYTHON_INSTALL_DIR%\python -m zipfile -e %LOCAL_RESOURCE_TMP_DIR%webpicmdline.zip %LOCAL_RESOURCE_TMP_DIR%webpicmdline
+
+echo installing Helicon Zoo...
+%LOCAL_RESOURCE_TMP_DIR%webpicmdline\webpicmdline /Products:HeliconZooModule /Feeds:http://www.helicontech.com/zoo/feed/ /AcceptEula
+
+call "%~dp0"install-requirements
+
+REM allow write access to Python runtime for bytecode optimization by Helicon Zoo
+icacls %PYTHON_INSTALL_DIR% /grant "Everyone":F /T
+
+reg add "hku\.default\software\microsoft\windows\currentversion\explorer\user shell folders" /v "Local AppData" /t REG_EXPAND_SZ /d %%USERPROFILE%%\AppData\Local /f
+
+echo Completed installation.
12 WebRole/bin/startup.cmd
@@ -0,0 +1,12 @@
+@echo off
+
+cd "%~dp0"
+
+icacls %RoleRoot%\approot /grant "Everyone":F /T
+
+REM This script will only execute on production Windows Azure.
+if "%EMULATED%"=="true" goto :EOF
+
+REM run the command like this if you want to you use Python x64 instead
+REM install.cmd amd64 >..\startup-tasks.log 2>..\startup-tasks-error.log
+install.cmd >..\startup-tasks.log 2>..\startup-tasks-error.log
1  WebRole/lib/site-packages/README.txt
@@ -0,0 +1 @@
+this file is just a placeholder so the empty directory is not ignored by version control
0  WebRole/project/__init__.py
No changes.
14 WebRole/project/manage.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+from django.core.management import execute_manager
+import imp
+try:
+ imp.find_module('settings') # Assumed to be in the same directory.
+except ImportError:
+ import sys
+ sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)
+ sys.exit(1)
+
+import settings
+
+if __name__ == "__main__":
+ execute_manager(settings)
158 WebRole/project/settings.py
@@ -0,0 +1,158 @@
+# Django settings for the project.
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+ # ('Your Name', 'your_email@example.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+ 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
+ 'USER': '', # Not used with sqlite3.
+ 'PASSWORD': '', # Not used with sqlite3.
+ 'NAME': '', # Or path to database file if using sqlite3.
+ 'PORT': '', # Set to empty string for default. Not used with sqlite3.
+
+ # database setting sample for SQL Azure
+ #'ENGINE': 'sql_server.pyodbc', # Or other mssql engine ('sqlserver_ado' etc.) if available
+ #'HOST': 'yourserver.database.windows.net', # Or your local mssql instance
+ #'USER': 'username@yourserver.database.windows.net', # Or your local mssql login
+ #'PASSWORD': 'password',
+ #'NAME': 'yourdb',
+ #'PORT': '', # Or your local mssql port
+ #'OPTIONS' : {
+ # 'driver': 'SQL Server Native Client 10.0',
+ # 'MARS_Connection': True,
+ #},
+ }
+}
+
+# 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 = 'America/Chicago'
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = 'en-us'
+
+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 filesystem path to the directory that will hold user-uploaded files.
+# Example: "/home/media/media.lawrence.com/media/"
+MEDIA_ROOT = ''
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash.
+# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
+MEDIA_URL = ''
+
+# 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/"
+import os
+STATIC_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir, 'static')
+
+# URL prefix for static files.
+# Example: "http://media.lawrence.com/static/"
+STATIC_URL = '/static/'
+
+# URL prefix for admin static files -- CSS, JavaScript and images.
+# Make sure to use a trailing slash.
+# Examples: "http://foo.com/static/admin/", "/static/admin/".
+ADMIN_MEDIA_PREFIX = '/static/admin/'
+
+# 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 = '3-#!8!u!$qftp#vq%%4w0r=zi#!@ef_&36v50^y04a8mvdalr3'
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.Loader',
+ 'django.template.loaders.app_directories.Loader',
+# 'django.template.loaders.eggs.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',
+)
+
+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.
+)
+
+INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+ 'django.contrib.messages',
+ 'django.contrib.staticfiles',
+ # Uncomment the next line to enable the admin:
+ # 'django.contrib.admin',
+ # Uncomment the next line to enable admin documentation:
+ # 'django.contrib.admindocs',
+)
+
+# A sample logging configuration. The only tangible logging
+# performed by this configuration is to send an email to
+# the site admins on every HTTP 500 error.
+# See http://docs.djangoproject.com/en/dev/topics/logging for
+# more details on how to customize your logging configuration.
+LOGGING = {
+ 'version': 1,
+ 'disable_existing_loggers': False,
+ 'handlers': {
+ 'mail_admins': {
+ 'level': 'ERROR',
+ 'class': 'django.utils.log.AdminEmailHandler'
+ }
+ },
+ 'loggers': {
+ 'django.request': {
+ 'handlers': ['mail_admins'],
+ 'level': 'ERROR',
+ 'propagate': True,
+ },
+ }
+}
17 WebRole/project/urls.py
@@ -0,0 +1,17 @@
+from django.conf.urls.defaults import patterns, include, url
+
+# Uncomment the next two lines to enable the admin:
+# from django.contrib import admin
+# admin.autodiscover()
+
+urlpatterns = patterns('',
+ # Examples:
+ # url(r'^$', 'project.views.home', name='home'),
+ # url(r'^project/', include('project.foo.urls')),
+
+ # Uncomment the admin/doc line below to enable admin documentation:
+ # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
+
+ # Uncomment the next line to enable the admin:
+ # url(r'^admin/', include(admin.site.urls)),
+)
6 WebRole/requirements.txt
@@ -0,0 +1,6 @@
+# Add Python modules your project requires here.
+# If you don't have them, you will have them installed into python_modules folder upon the first request after IIS-app restart.
+# Learn more at http://www.pip-installer.org/en/latest/requirement-format.html
+
+django
+#south
2  WebRole/static/robots.txt
@@ -0,0 +1,2 @@
+User-agent: *
+Disallow: /
9 WebRole/static/web.config
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+ <system.webServer>
+ <handlers>
+ <remove name="django.project.x86" />
+ <remove name="django.project.x64" />
+ </handlers>
+ </system.webServer>
+</configuration>
42 WebRole/web.config
@@ -0,0 +1,42 @@
+<?xml version="1.0"?>
+<configuration>
+ <system.diagnostics>
+ <trace>
+ <listeners>
+ <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
+ <filter type="" />
+ </add>
+ </listeners>
+ </trace>
+ </system.diagnostics>
+ <system.webServer>
+ <heliconZoo>
+ <application name="django.project.x86" >
+ <environmentVariables>
+ <add name="PYTHONPATH" value="%APPL_PHYSICAL_PATH%\project;%APPL_PHYSICAL_PATH%\lib\site-packages;%PYTHONPATH%" />
+ <add name="DJANGO_SETTINGS_MODULE" value="settings" />
+ <add name="django.root" value="%APPL_VIRTUAL_PATH%" />
+ </environmentVariables>
+ </application>
+ <application name="django.project.x64" >
+ <environmentVariables>
+ <add name="PYTHONPATH" value="%APPL_PHYSICAL_PATH%\project;%APPL_PHYSICAL_PATH%\lib\site-packages;%PYTHONPATH%" />
+ <add name="DJANGO_SETTINGS_MODULE" value="settings" />
+ <add name="django.root" value="%APPL_VIRTUAL_PATH%" />
+ </environmentVariables>
+ </application>
+ </heliconZoo>
+ <handlers>
+ <add name="django.project.x86" scriptProcessor="python.2.7.pipe" path="*" verb="*" modules="HeliconZoo_x86" preCondition="bitness32" resourceType="Unspecified" requireAccess="Script" />
+ <add name="django.project.x64" scriptProcessor="python.2.7.pipe" path="*" verb="*" modules="HeliconZoo_x64" preCondition="bitness64" resourceType="Unspecified" requireAccess="Script" />
+ </handlers>
+ <rewrite>
+ <rules>
+ <rule name="robots" stopProcessing="true">
+ <match url="^(robots\.txt)$" ignoreCase="false" />
+ <action type="Rewrite" url="/static/robots.txt" />
+ </rule>
+ </rules>
+ </rewrite>
+ </system.webServer>
+</configuration>
10 pack.cmd
@@ -0,0 +1,10 @@
+@echo off
+
+if "%ServiceHostingSDKInstallPath%" == "" (
+ echo Can't see the ServiceHostingSDKInstallPath environment variable. Please run from a Windows Azure SDK command-line (run Program Files\Windows Azure SDK\^<version^>\bin\setenv.cmd^).
+ GOTO :eof
+)
+
+del /s /q *.log *.pyc *.pyo >nul 2>nul
+
+cspack ServiceDefinition.csdef /out:heliconzoo-django-role.cspkg
10 run.cmd
@@ -0,0 +1,10 @@
+@echo off
+
+if "%ServiceHostingSDKInstallPath%" == "" (
+ echo Can't see the ServiceHostingSDKInstallPath environment variable. Please run from a Windows Azure SDK command-line (run Program Files\Windows Azure SDK\^<version^>\bin\setenv.cmd^).
+ GOTO :eof
+)
+
+cspack ServiceDefinition.csdef /copyOnly /out:heliconzoo-django-role.csx
+csrun heliconzoo-django-role.csx ServiceConfiguration.Local.cscfg
+if "%ERRORLEVEL%"=="0" ( echo Browse to the port you see above to view the app. To stop the compute emulator, use "csrun /devfabric:shutdown" )
Please sign in to comment.
Something went wrong with that request. Please try again.