From 27c0f4aeec2cd2940653d6067333ab89409ac580 Mon Sep 17 00:00:00 2001 From: madhana Date: Sun, 26 Apr 2015 13:28:11 -0700 Subject: [PATCH] move to new repo --- django-app/azuredeploy.json | 195 +++++++++++++++++++++++++ django-app/azuredeploy.parameters.json | 21 +++ django-app/install_django.sh | 41 ++++++ django-app/metadata.json | 7 + django-app/readme.md | 10 ++ 5 files changed, 274 insertions(+) create mode 100644 django-app/azuredeploy.json create mode 100644 django-app/azuredeploy.parameters.json create mode 100644 django-app/install_django.sh create mode 100644 django-app/metadata.json create mode 100644 django-app/readme.md diff --git a/django-app/azuredeploy.json b/django-app/azuredeploy.json new file mode 100644 index 0000000..1a683b2 --- /dev/null +++ b/django-app/azuredeploy.json @@ -0,0 +1,195 @@ +{ + "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json", + "contentVersion": "1.0.0.0", + "parameters": { + "newStorageAccountName": { + "type": "string", + "metadata": { + "description": "Name of the Storage Account" + } + }, + "location": { + "type": "string", + "defaultValue": "West US", + "metadata": { + "description": "Location of all resources created by this template." + } + }, + "adminUsername": { + "type": "string", + "metadata": { + "description": "Username for the Administrator of the VM" + } + }, + "adminPassword": { + "type": "securestring", + "metadata": { + "description": "Password for the Administrator of the VM, must satisfy the password requirements" + } + }, + "imagePublisher": { + "type": "string", + "defaultValue": "Canonical", + "metadata": { + "Description": "Image Publisher" + } + }, + "imageOffer": { + "type": "string", + "defaultValue": "UbuntuServer", + "metadata": { + "Description": "Image Offer" + } + }, + "imageSKU": { + "type": "string", + "defaultValue": "14.04.2-LTS", + "metadata": { + "Description": "Image SKU" + } + }, + "vmDnsName": { + "type": "string", + "metadata": { + "description": "DNS Name for the Public IP. Must be lowercase." + } + } + }, + "variables": { + "nicName": "myVMNic", + "addressPrefix": "10.0.0.0/16", + "subnetName": "Subnet-1", + "subnetPrefix": "10.0.0.0/24", + "storageAccountType": "Standard_LRS", + "publicIPAddressName": "myPublicIP", + "publicIPAddressType": "Dynamic", + "vmStorageAccountContainerName": "vhds", + "vmName": "[parameters('vmDnsName')]", + "vmSize": "Standard_A0", + "virtualNetworkName": "MyVNET", + "vnetID": "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]", + "subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]" + }, + "resources": [{ + "type": "Microsoft.Storage/storageAccounts", + "name": "[parameters('newStorageAccountName')]", + "apiVersion": "2015-05-01-preview", + "location": "[parameters('location')]", + "properties": { + "accountType": "[variables('storageAccountType')]" + } + }, { + "apiVersion": "2015-05-01-preview", + "type": "Microsoft.Network/publicIPAddresses", + "name": "[variables('publicIPAddressName')]", + "location": "[parameters('location')]", + "properties": { + "publicIPAllocationMethod": "[variables('publicIPAddressType')]", + "dnsSettings": { + "domainNameLabel": "[parameters('vmDnsName')]" + } + } + }, { + "apiVersion": "2015-05-01-preview", + "type": "Microsoft.Network/virtualNetworks", + "name": "[variables('virtualNetworkName')]", + "location": "[parameters('location')]", + "properties": { + "addressSpace": { + "addressPrefixes": [ + "[variables('addressPrefix')]" + ] + }, + "subnets": [{ + "name": "[variables('subnetName')]", + "properties": { + "addressPrefix": "[variables('subnetPrefix')]" + } + }] + } + }, { + "apiVersion": "2015-05-01-preview", + "type": "Microsoft.Network/networkInterfaces", + "name": "[variables('nicName')]", + "location": "[parameters('location')]", + "dependsOn": [ + "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", + "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" + ], + "properties": { + "ipConfigurations": [{ + "name": "ipconfig1", + "properties": { + "privateIPAllocationMethod": "Dynamic", + "publicIPAddress": { + "id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]" + }, + "subnet": { + "id": "[variables('subnetRef')]" + } + } + }] + } + }, { + "apiVersion": "2015-05-01-preview", + "type": "Microsoft.Compute/virtualMachines", + "name": "[variables('vmName')]", + "location": "[parameters('location')]", + "dependsOn": [ + "[concat('Microsoft.Storage/storageAccounts/', parameters('newStorageAccountName'))]", + "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" + ], + "properties": { + "hardwareProfile": { + "vmSize": "[variables('vmSize')]" + }, + "osProfile": { + "computername": "[variables('vmName')]", + "adminUsername": "[parameters('adminUsername')]", + "adminPassword": "[parameters('adminPassword')]" + }, + "storageProfile": { + "imageReference": { + "publisher": "[parameters('imagePublisher')]", + "offer": "[parameters('imageOffer')]", + "sku" : "[parameters('imageSKU')]", + "version":"latest" + }, + "osDisk" : { + "name": "osdisk1", + "vhd": { + "uri": "[[concat('http://',parameters('newStorageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/','osdisk1spec.vhd')]" + }, + "caching": "ReadWrite", + "createOption": "FromImage" + } + + }, + "networkProfile": { + "networkInterfaces": [{ + "id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]" + }] + } + } + }, { + "type": "Microsoft.Compute/virtualMachines/extensions", + "name": "[concat(variables('vmName'),'/newuserscript')]", + "apiVersion": "2015-05-01-preview", + "location": "[parameters('location')]", + "dependsOn": [ + "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]" + ], + "properties": { + "publisher": "Microsoft.OSTCExtensions", + "type": "CustomScriptForLinux", + "typeHandlerVersion": "1.2", + "settings": { + "fileUris": [ + "https://raw.githubusercontent.com/madhana/azurermtemplates/master/django-app/install_django.sh" + ], + "commandToExecute": "[concat('sh install_django.sh ', parameters('vmDnsName'))]" + + } + } + }] +} diff --git a/django-app/azuredeploy.parameters.json b/django-app/azuredeploy.parameters.json new file mode 100644 index 0000000..d28d31f --- /dev/null +++ b/django-app/azuredeploy.parameters.json @@ -0,0 +1,21 @@ +{ + "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "newStorageAccountName": { + "value": "uniquestorageaccountname" + }, + "location": { + "value": "West US" + }, + "adminUsername": { + "value": "username" + }, + "adminPassword": { + "value": "strongpassword" + }, + "vmDnsName": { + "value": "uniquednsname" + } + } +} diff --git a/django-app/install_django.sh b/django-app/install_django.sh new file mode 100644 index 0000000..65b1faa --- /dev/null +++ b/django-app/install_django.sh @@ -0,0 +1,41 @@ +#!/bin/bash +export DEBIAN_FRONTEND=noninteractive +apt-get -y update + +# install Python +apt-get -y install python-setuptools + +# install DJango +easy_install django + +# install Apache +apt-get -y install apache2 libapache2-mod-wsgi + +# create a django app +cd /var/www +django-admin startproject helloworld + +# Create a new file named views.py in the /var/www/helloworld/helloworld directory. This will contain the view +# that renders the "hello world" page +echo 'from django.http import HttpResponse +def home(request): + html = "Hello World!" + return HttpResponse(html)' | tee /var/www/helloworld/helloworld/views.py +# Update urls.py +echo "from django.conf.urls import patterns, url +urlpatterns = patterns('', + url(r'^$', 'helloworld.views.home', name='home'), +)" | tee /var/www/helloworld/helloworld/urls.py + +# Setup Apache +echo " +ServerName $1 + +WSGIScriptAlias / /var/www/helloworld/helloworld/wsgi.py +WSGIPythonPath /var/www/helloworld" | tee /etc/apache2/sites-available/helloworld.conf + +#enable site +a2ensite helloworld + +#restart apache +service apache2 reload diff --git a/django-app/metadata.json b/django-app/metadata.json new file mode 100644 index 0000000..e2b931d --- /dev/null +++ b/django-app/metadata.json @@ -0,0 +1,7 @@ +{ + "itemDisplayName": "Deploy a Django app", + "description": "This template uses the Azure Linux CustomScript extension to deploy an application. This example creates an Ubuntu VM, does a silent install of Python, Django and Apache, then creates a simple Django app", + "summary": "Deploy a Django app", + "githubUsername": "madhana", + "dateUpdated": "2015-04-10" +} diff --git a/django-app/readme.md b/django-app/readme.md new file mode 100644 index 0000000..9cbd356 --- /dev/null +++ b/django-app/readme.md @@ -0,0 +1,10 @@ +# Deploy a Django app on Ubuntu. + + +| Deploy to Azure | Author | Template Name | Description | +|:-----------------|:--------------------------------| :---------------| :---------------| +| | [madhana](https://github.com/madhana) | [Deploy a Python Django app on Ubuntu](https://github.com/azurermtemplates/azurermtemplates/tree/master/deploy-lamp-app) | This template uses the Azure Linux CustomScript extension to deploy a Django application by creating an Ubuntu VM, doing a silent install of Python and Apache, then creating a simple Django application.| + +This template uses the Azure Linux CustomScript extension to deploy an application. This example creates an Ubuntu VM, does a silent install of Python, Apache, then creates a simple Django app.It is essentially the template for the tutorial that can be found here -> http://azure.microsoft.com/en-us/documentation/articles/virtual-machines-python-django-web-app-linux/ + +Once the template is deployed, just grab the public IP address of the VM and open it in a browser and you'll see the hello world app running.