GridU Azure capstone
Last active
September 7, 2018 11:35
-
-
Save k-popov/2a7de541502db8e1df3434fe2729c79d to your computer and use it in GitHub Desktop.
GridU Azure capstone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"assignableScopes": [ | |
"/" | |
], | |
"description": "Lets you manage everything except access to resources.", | |
"id": "/subscriptions/505a7109-f530-47ec-9a7a-e965f5755cf6/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c", | |
"name": "b24988ac-6180-42a0-ab88-20f7382dd24c", | |
"permissions": [ | |
{ | |
"actions": [ | |
"*" | |
], | |
"dataActions": [], | |
"notActions": [ | |
"Microsoft.Authorization/*/Delete", | |
"Microsoft.Authorization/*/Write", | |
"Microsoft.Authorization/elevateAccess/Action", | |
"Microsoft.Blueprint/blueprintAssignments/write", | |
"Microsoft.Blueprint/blueprintAssignments/delete" | |
], | |
"notDataActions": [] | |
} | |
], | |
"roleName": "Contributor", | |
"roleType": "BuiltInRole", | |
"type": "Microsoft.Authorization/roleDefinitions" | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function install_az_cli() { | |
local AZ_REPO=$(lsb_release -cs) | |
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | \ | |
sudo tee /etc/apt/sources.list.d/azure-cli.list | |
curl -L https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - | |
sudo apt-get update && sudo apt-get install -y apt-transport-https azure-cli | |
} | |
function setup_share_mount() { | |
local STORAGE_ACCOUNT_NAME="$1" | |
local FILE_SHARE_NAME="$2" | |
local STORAGE_ACCOUNT_KEY="$3" | |
grep -q -F "${STORAGE_ACCOUNT_NAME}.file.core.windows.net/${FILE_SHARE_NAME}" /etc/fstab && { echo 'already set up'; return 0; } | |
sudo mkdir "$LOCAL_WP_FILES_DIR" | |
chmod 0777 "$LOCAL_WP_FILES_DIR" | |
sudo mkdir -p /etc/smbcredentials | |
if [ ! -f "/etc/smbcredentials/${STORAGE_ACCOUNT_NAME}.cred" ]; then | |
echo -e "username=${STORAGE_ACCOUNT_NAME}\npassword=${STORAGE_ACCOUNT_KEY}" | sudo tee -a /etc/smbcredentials/${STORAGE_ACCOUNT_NAME}.cred | |
sudo chmod 600 /etc/smbcredentials/${STORAGE_ACCOUNT_NAME}.cred | |
fi | |
echo "//${STORAGE_ACCOUNT_NAME}.file.core.windows.net/${FILE_SHARE_NAME} "$LOCAL_WP_FILES_DIR" cifs nofail,vers=3.0,credentials=/etc/smbcredentials/${STORAGE_ACCOUNT_NAME}.cred,dir_mode=0777,file_mode=0677,serverino" | sudo tee -a /etc/fstab | |
} | |
function set_up_mysql() { | |
local FULL_ADMIN_USER_NAME="${DB_ADMIN_USER}@$(echo $DB_HOST | cut -f 1 -d .)" | |
sudo apt-get -y install mysql-client | |
echo "GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO '${DB_WP_USER}'@'%' IDENTIFIED BY '${DB_WP_PASSWORD}'; | |
FLUSH PRIVILEGES;" | \ | |
mysql -h $DB_HOST --user "$FULL_ADMIN_USER_NAME" -p"$DB_ADMIN_PASSWORD" | |
} | |
function set_up_wp() { | |
local FULL_WP_USER_NAME="${DB_WP_USER}@$(echo $DB_HOST | cut -f 1 -d .)" | |
cd | |
wget http://wordpress.org/latest.tar.gz | |
tar xzf latest.tar.gz -C "$LOCAL_WP_FILES_DIR" --strip-components=1 | |
sudo apt-get install -y php-cli sendmail | |
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar | |
cd "$LOCAL_WP_FILES_DIR" | |
php ~/wp-cli.phar config create --dbname=$DB_NAME --dbuser=$FULL_WP_USER_NAME --dbpass=$DB_WP_PASSWORD --dbhost=$DB_HOST | |
php ~/wp-cli.phar core install --url=$WP_URL --title="WP-CLI" --admin_user=$WP_ADMIN --admin_password="$WP_PASSWORD" --admin_email=$WP_EMAIL | |
} | |
STORAGE_ACCOUNT_NAME="" | |
FILE_SHARE_NAME="" | |
STORAGE_ACCOUNT_KEY="" | |
DB_HOST="" | |
DB_NAME="" | |
DB_ADMIN_USER="" | |
DB_ADMIN_PASSWORD="" | |
DB_WP_USER="" | |
DB_WP_PASSWORD="" | |
WP_URL="" | |
WP_ADMIN="" | |
WP_PASSWORD="" | |
WP_EMAIL="" | |
LOCAL_WP_FILES_DIR="/wpfiles" | |
while getopts "a:f:k:h:n:u:p:l:s:r:d:w:e:" opt; do | |
case $opt in | |
a) | |
STORAGE_ACCOUNT_NAME="$OPTARG" | |
;; | |
f) | |
FILE_SHARE_NAME="$OPTARG" | |
;; | |
k) | |
STORAGE_ACCOUNT_KEY="$OPTARG" | |
;; | |
h) | |
DB_HOST="$OPTARG" | |
;; | |
n) | |
DB_NAME="$OPTARG" | |
;; | |
u) | |
DB_ADMIN_USER="$OPTARG" | |
;; | |
p) | |
DB_ADMIN_PASSWORD="$OPTARG" | |
;; | |
l) | |
DB_WP_USER="$OPTARG" | |
;; | |
s) | |
DB_WP_PASSWORD="$OPTARG" | |
;; | |
r) | |
WP_URL="$OPTARG" | |
;; | |
d) | |
WP_ADMIN="$OPTARG" | |
;; | |
w) | |
WP_PASSWORD="$OPTARG" | |
;; | |
e) | |
WP_EMAIL="$OPTARG" | |
;; | |
*) | |
echo "Invalid option: -$opt" >&2 | |
exit 1 | |
;; | |
:) | |
echo "Option -$opt requires an argument." >&2 | |
exit 1 | |
;; | |
esac | |
done | |
for VAR_NAME in \ | |
STORAGE_ACCOUNT_NAME \ | |
FILE_SHARE_NAME \ | |
STORAGE_ACCOUNT_KEY \ | |
DB_HOST \ | |
DB_NAME \ | |
DB_ADMIN_USER \ | |
DB_ADMIN_PASSWORD \ | |
DB_WP_USER \ | |
DB_WP_PASSWORD \ | |
WP_ADMIN \ | |
WP_PASSWORD \ | |
WP_EMAIL \ | |
; do | |
eval "test -z \"\$$VAR_NAME\"" && { echo "$VAR_NAME is missing"; exit 1; } | |
done | |
install_az_cli | |
az login --identity | |
az storage share create --name "$FILE_SHARE_NAME" --quota 1 --account-name "$STORAGE_ACCOUNT_NAME" | |
setup_share_mount "$STORAGE_ACCOUNT_NAME" "$FILE_SHARE_NAME" "$STORAGE_ACCOUNT_KEY" | |
sudo mount -v "$LOCAL_WP_FILES_DIR" | |
set_up_mysql | |
set_up_wp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"envPrefix": { | |
"value": "griduaz" | |
}, | |
"envLocation": { | |
"value": "westus" | |
}, | |
"jumpBoxVMSize": { | |
"value": "Standard_A0" | |
}, | |
"jumpBoxUsername": { | |
"value": "hub" | |
}, | |
"jumpBoxPubkey": { | |
"value": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDJ1dkGeW2cmZDCy71xT+Jcwd29/BiYFlb9L8QRefQGlqrWbpqsd4PnJcUBaVXL911Uc0CLDBIuLuwrvWHlURPzDvHjbtMD9+NiT7/TOPfee/nYvJP5x1YSqMvwTf5xeJt8mWwZmld1WQWU5ZdSazAvHrxJ7bP/a1NCdtSAp8d3FLo1l95Cidv2J3mZ6HkjpfDGMxPG1k7w9XvCfz1dWHS2wf8Oxvlk5ChPoulegjqHUvXxOj6LCpTURoy9uyobQTK+jBG6GktxuxdqwXgDBzB2sx0oI8/nvTE6A+kFfU8jTK6iGPEoUGyox/yIm0DLjuWGDPIHyZYrezR8y15xVlGN hub@hub-laptop" | |
}, | |
"mysqlAdminUsername": { | |
"value": "guadmin" | |
}, | |
"mysqlAdminPassword": { | |
"value": "sqlsecr3t_With999Symbols" | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"hashSalt": { | |
"type": "string" | |
}, | |
"envPrefix": { | |
"type": "string", | |
"defaultValue": "griduAz" | |
}, | |
"envLocation": { | |
"type": "string", | |
"defaultValue": "[resourceGroup().location]", | |
"allowedValues": [ | |
"westus", | |
"westus2" | |
] | |
}, | |
"jumpBoxVMSize": { | |
"type": "string", | |
"defaultValue": "Basic_A0", | |
"allowedValues": [ | |
"Basic_A0", | |
"Standard_A0" | |
] | |
}, | |
"jumpBoxUsername": { | |
"type": "string" | |
}, | |
"jumpBoxPubkey": { | |
"type": "string" | |
}, | |
"mysqlAdminUsername": { | |
"type": "string" | |
}, | |
"mysqlAdminPassword": { | |
"type": "securestring" | |
}, | |
"vmssInstanceCount": { | |
"type": "int", | |
"defaultValue": 1 | |
} | |
}, | |
"variables": { | |
"storageAccountName": "[toLower(concat(parameters('envPrefix'), 'StorAcc'))]", | |
"jumpboxSubnetName": "[concat(parameters('envPrefix'), 'jbsubnet')]", | |
"vmssSubnetName": "[concat(parameters('envPrefix'), 'vmsssubnet')]", | |
"mysqlSubnetName": "[concat(parameters('envPrefix'), 'mysqlsubnet')]", | |
"appGWSubnetName": "[concat(parameters('envPrefix'), 'appgwsubnet')]", | |
"vNetName": "[concat(parameters('envPrefix'), 'vnetnet')]", | |
"vnetAddress": "10.0.0.0/22", | |
"jumpboxSubnet": "10.0.0.0/24", | |
"vmssSubnet": "10.0.1.0/24", | |
"mysqlSubnet": "10.0.2.0/24", | |
"appGWSubnet": "10.0.3.0/24", | |
"jumphostPubIPName": "[concat(parameters('envPrefix'), 'jbpubip')]", | |
"jumpBoxNicName": "[concat(parameters('envPrefix'), 'jbnic')]", | |
"jumpBoxVMName": "[concat(parameters('envPrefix'), 'jbox')]", | |
"jumpBoxSshKeyPath": "[concat('/home/',parameters('jumpBoxUsername'),'/.ssh/authorized_keys')]", | |
"osType": { | |
"publisher": "Canonical", | |
"offer": "UbuntuServer", | |
"sku": "18.04-LTS", | |
"version": "latest" | |
}, | |
"imageReference": "[variables('osType')]", | |
"jumpBoxBuiltInRoleType": "Contributor", | |
"jumpBoxRoleDefId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/', 'b24988ac-6180-42a0-ab88-20f7382dd24c')]", | |
"jumpBoxVmResourceId": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Compute/virtualMachines/', variables('jumpBoxVMName'))]", | |
"mysqlServerName": "[concat(parameters('envPrefix'), 'mysqlserver')]", | |
"databaseSkuSizeMB": 5120, | |
"databaseSku": { | |
"name": "B_Gen4_1", | |
"tier": "Basic", | |
"size": "[variables('databaseSkuSizeMB')]", | |
"family": "Gen4" | |
}, | |
"databaseSkuReference": "[variables('databaseSku')]", | |
"databaseName": "[concat(parameters('envPrefix'), 'db')]", | |
"vmssName": "[toLower(substring(concat(parameters('envPrefix'), 'vmss'), 0, 9))]", | |
"vmssVMSKU": "Basic_A0", | |
"appGwName": "[concat(parameters('envPrefix'), 'appgw')]", | |
"appGwBePoolName": "[concat(parameters('envPrefix'), 'appgwbepool')]", | |
"appGWPubIPName": "[concat(parameters('envPrefix'), 'agwpubip')]", | |
"appGwID": "[resourceId('Microsoft.Network/applicationGateways',variables('appGwName'))]" | |
}, | |
"resources": [ | |
{ | |
"type": "Microsoft.Network/virtualNetworks", | |
"name": "[variables('vNetName')]", | |
"location": "[parameters('envLocation')]", | |
"apiVersion": "2017-06-01", | |
"properties": { | |
"addressSpace": { | |
"addressPrefixes": [ | |
"[variables('vnetAddress')]" | |
] | |
}, | |
"subnets": [ | |
{ | |
"name": "[variables('jumpboxSubnetName')]", | |
"properties": { | |
"addressPrefix": "[variables('jumpboxSubnet')]", | |
"serviceEndpoints": [ | |
{ | |
"service": "Microsoft.Storage" | |
} | |
] | |
} | |
}, | |
{ | |
"name": "[variables('vmssSubnetName')]", | |
"properties": { | |
"addressPrefix": "[variables('vmssSubnet')]", | |
"serviceEndpoints": [ | |
{ | |
"service": "Microsoft.Storage" | |
} | |
] | |
} | |
}, | |
{ | |
"name": "[variables('mysqlSubnetName')]", | |
"properties": { | |
"addressPrefix": "[variables('mysqlSubnet')]" | |
} | |
}, | |
{ | |
"name": "[variables('appGWSubnetName')]", | |
"properties": { | |
"addressPrefix": "[variables('appGWSubnet')]" | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"type": "Microsoft.Network/publicIPAddresses", | |
"name": "[variables('jumphostPubIPName')]", | |
"location": "[parameters('envLocation')]", | |
"apiVersion": "2017-04-01", | |
"properties": { | |
"publicIPAllocationMethod": "Dynamic" | |
} | |
}, | |
{ | |
"type": "Microsoft.Network/publicIPAddresses", | |
"name": "[variables('appGWPubIPName')]", | |
"location": "[parameters('envLocation')]", | |
"apiVersion": "2017-04-01", | |
"properties": { | |
"publicIPAllocationMethod": "Dynamic" | |
} | |
}, | |
{ | |
"type": "Microsoft.Network/networkInterfaces", | |
"name": "[variables('jumpBoxNicName')]", | |
"location": "[parameters('envLocation')]", | |
"apiVersion": "2017-04-01", | |
"dependsOn": [ | |
"[concat('Microsoft.Network/publicIPAddresses/', variables('jumphostPubIPName'))]", | |
"[concat('Microsoft.Network/virtualNetworks/', variables('vNetName'))]" | |
], | |
"properties": { | |
"ipConfigurations": [ | |
{ | |
"name": "[concat(parameters('envPrefix'), 'jbipcfg')]", | |
"properties": { | |
"privateIPAllocationMethod": "Dynamic", | |
"publicIPAddress": { | |
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('jumphostPubIPName'))]" | |
}, | |
"subnet": { | |
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vNetName'), variables('jumpboxSubnetName'))]" | |
} | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"name": "[variables('storageAccountName')]", | |
"type": "Microsoft.Storage/storageAccounts", | |
"location": "[parameters('envLocation')]", | |
"apiVersion": "2018-02-01", | |
"dependsOn": [ | |
"[concat('Microsoft.Network/virtualNetworks/', variables('vNetName'))]" | |
], | |
"sku": { | |
"name": "Standard_LRS" | |
}, | |
"properties": { | |
"networkAcls": { | |
"defaultAction": "Deny", | |
"virtualNetworkRules": [ | |
{ | |
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vNetName'), variables('jumpboxSubnetName'))]", | |
"action": "Allow" | |
}, | |
{ | |
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vNetName'), variables('vmssSubnetName'))]", | |
"action": "Allow" | |
} | |
] | |
} | |
} | |
}, | |
{ | |
"apiVersion": "2017-09-01", | |
"type": "Microsoft.Authorization/roleAssignments", | |
"name": "[guid(parameters('envPrefix'), resourceGroup().id, parameters('hashSalt'))]", | |
"properties": { | |
"roleDefinitionId": "[variables('jumpBoxRoleDefId')]", | |
"principalId": "[reference(variables('jumpBoxVmResourceId'), '2017-12-01', 'Full').identity.principalId]", | |
"scope": "[resourceGroup().id]" | |
}, | |
"dependsOn": [ | |
"[concat('Microsoft.Compute/virtualMachines/', variables('jumpBoxVMName'))]" | |
] | |
}, | |
{ | |
"type": "Microsoft.Compute/virtualMachines", | |
"name": "[variables('jumpBoxVMName')]", | |
"location": "[parameters('envLocation')]", | |
"apiVersion": "2018-06-01", | |
"identity": { | |
"type": "SystemAssigned" | |
}, | |
"dependsOn": [ | |
"[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]", | |
"[concat('Microsoft.Network/networkInterfaces/', variables('jumpBoxNicName'))]" | |
], | |
"properties": { | |
"hardwareProfile": { | |
"vmSize": "[parameters('jumpBoxVMSize')]" | |
}, | |
"osProfile": { | |
"computerName": "[variables('jumpBoxVMName')]", | |
"adminUsername": "[parameters('jumpBoxUsername')]", | |
"linuxConfiguration": { | |
"disablePasswordAuthentication": true, | |
"ssh": { | |
"publicKeys": [ | |
{ | |
"path": "[variables('jumpBoxSshKeyPath')]", | |
"keyData": "[parameters('jumpBoxPubkey')]" | |
} | |
] | |
} | |
} | |
}, | |
"storageProfile": { | |
"imageReference": "[variables('imageReference')]", | |
"osDisk": { | |
"name": "[concat(variables('jumpBoxVMName'),'_OSDisk')]", | |
"caching": "ReadWrite", | |
"createOption": "FromImage", | |
"managedDisk": { | |
"storageAccountType": "Standard_LRS" | |
} | |
} | |
}, | |
"networkProfile": { | |
"networkInterfaces": [ | |
{ | |
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('jumpBoxNicName'))]" | |
} | |
] | |
} | |
} | |
}, | |
{ | |
"apiVersion": "2017-12-01-preview", | |
"location": "[parameters('envLocation')]", | |
"name": "[variables('mysqlServerName')]", | |
"type": "Microsoft.DBforMySQL/servers", | |
"properties": { | |
"version": "5.7", | |
"administratorLogin": "[parameters('mysqlAdminUsername')]", | |
"administratorLoginPassword": "[parameters('mysqlAdminPassword')]", | |
"storageProfile": { | |
"storageMB": "[variables('databaseSkuSizeMB')]", | |
"backupRetentionDays": "7", | |
"geoRedundantBackup": "Disabled" | |
}, | |
"sslEnforcement": "Disabled" | |
}, | |
"sku": "[variables('databaseSkuReference')]", | |
"resources": [ | |
{ | |
"name": "[variables('databaseName')]", | |
"type": "databases", | |
"apiVersion": "2017-12-01-preview", | |
"properties": { | |
"charset": "utf8", | |
"collation": "utf8_general_ci" | |
}, | |
"dependsOn": [ | |
"[concat('Microsoft.DBforMySQL/servers/', variables('mysqlServerName'))]" | |
] | |
}, | |
{ | |
"type": "firewallrules", | |
"apiVersion": "2017-12-01-preview", | |
"dependsOn": [ | |
"[concat('Microsoft.DBforMySQL/servers/', variables('mysqlServerName'),'/databases/' , variables('databaseName'))]", | |
"[concat('Microsoft.DBforMySQL/servers/', variables('mysqlServerName'))]" | |
], | |
"location": "[parameters('envLocation')]", | |
"name": "AllowAll", | |
"properties": { | |
"startIpAddress": "0.0.0.0", | |
"endIpAddress": "255.255.255.255" | |
} | |
} | |
] | |
}, | |
{ | |
"type": "Microsoft.Compute/virtualMachineScaleSets", | |
"name": "[variables('vmssName')]", | |
"location": "[parameters('envLocation')]", | |
"apiVersion": "2018-06-01", | |
"dependsOn": [ | |
"[concat('Microsoft.Network/virtualNetworks/', variables('vNetName'))]", | |
"[concat('Microsoft.Network/applicationGateways/', variables('appGwName'))]" | |
], | |
"sku": { | |
"name": "[variables('vmssVMSKU')]", | |
"tier": "Basic", | |
"capacity": "[parameters('vmssInstanceCount')]" | |
}, | |
"properties": { | |
"overprovision": true, | |
"upgradePolicy": { | |
"mode": "Manual" | |
}, | |
"virtualMachineProfile": { | |
"storageProfile": { | |
"imageReference": "[variables('imageReference')]", | |
"osDisk": { | |
"caching": "ReadWrite", | |
"createOption": "FromImage", | |
"managedDisk": { | |
"storageAccountType": "Standard_LRS" | |
} | |
} | |
}, | |
"osProfile": { | |
"computerNamePrefix": "[concat(parameters('envPrefix'), 'ssvm')]", | |
"adminUsername": "[parameters('jumpBoxUsername')]", | |
"linuxConfiguration": { | |
"disablePasswordAuthentication": true, | |
"ssh": { | |
"publicKeys": [ | |
{ | |
"path": "[variables('jumpBoxSshKeyPath')]", | |
"keyData": "[parameters('jumpBoxPubkey')]" | |
} | |
] | |
} | |
} | |
}, | |
"networkProfile": { | |
"networkInterfaceConfigurations": [ | |
{ | |
"name": "vmssnic", | |
"properties": { | |
"primary": true, | |
"ipConfigurations": [ | |
{ | |
"name": "ipconfig", | |
"properties": { | |
"subnet": { | |
"id": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Network/virtualNetworks/', variables('vNetName'), '/subnets/', variables('vmssSubnetName'))]" | |
}, | |
"ApplicationGatewayBackendAddressPools": [ | |
{ | |
"id": "[concat('/subscriptions/', subscription().subscriptionId,'/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Network/applicationGateways/', variables('appGwName'), '/backendAddressPools/', variables('appGwBePoolName'))]" | |
} | |
] | |
} | |
} | |
] | |
} | |
} | |
] | |
}, | |
"extensionProfile":{ | |
"extensions":[ | |
{ | |
"type":"Microsoft.Compute/virtualMachines/extensions", | |
"name":"vmsscustomscript", | |
"properties":{ | |
"publisher":"Microsoft.OSTCExtensions", | |
"type":"CustomScriptForLinux", | |
"typeHandlerVersion":"1.3", | |
"autoUpgradeMinorVersion":true, | |
"settings":{ | |
"commandToExecute":"bash -c 'nohup python -m SimpleHTTPServer &'" | |
} | |
} | |
} | |
] | |
} | |
} | |
} | |
}, | |
{ | |
"type": "Microsoft.Network/applicationGateways", | |
"name": "[variables('appGwName')]", | |
"location": "[parameters('envLocation')]", | |
"apiVersion": "2017-10-01", | |
"dependsOn": [ | |
"[concat('Microsoft.Network/virtualNetworks/', variables('vNetName'))]", | |
"[concat('Microsoft.Network/publicIPAddresses/', variables('appGWPubIPName'))]" | |
], | |
"properties": { | |
"sku": { | |
"name": "Standard_Small", | |
"tier": "Standard", | |
"capacity": "1" | |
}, | |
"gatewayIPConfigurations": [ | |
{ | |
"name": "appGwIpConfig", | |
"properties": { | |
"subnet": { | |
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vNetName'), variables('appGWSubnetName'))]" | |
} | |
} | |
} | |
], | |
"frontendIPConfigurations": [ | |
{ | |
"name": "appGwFrontendIP", | |
"properties": { | |
"PublicIPAddress": { | |
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('appGWPubIPName'))]" | |
} | |
} | |
} | |
], | |
"frontendPorts": [ | |
{ | |
"name": "appGwFrontendPort", | |
"properties": { | |
"Port": 80 | |
} | |
} | |
], | |
"backendAddressPools": [ | |
{ | |
"name": "[variables('appGwBePoolName')]" | |
} | |
], | |
"backendHttpSettingsCollection": [ | |
{ | |
"name": "appGwBackendHttpSettings", | |
"properties": { | |
"Port": 8000, | |
"Protocol": "Http", | |
"CookieBasedAffinity": "Disabled" | |
} | |
} | |
], | |
"httpListeners": [ | |
{ | |
"name": "appGwHttpListener", | |
"properties": { | |
"FrontendIPConfiguration": { | |
"Id": "[concat(variables('appGwID'), '/frontendIPConfigurations/appGwFrontendIP')]" | |
}, | |
"FrontendPort": { | |
"Id": "[concat(variables('appGwID'), '/frontendPorts/appGwFrontendPort')]" | |
}, | |
"Protocol": "Http", | |
"SslCertificate": null | |
} | |
} | |
], | |
"requestRoutingRules": [ | |
{ | |
"Name": "rule1", | |
"properties": { | |
"RuleType": "Basic", | |
"httpListener": { | |
"id": "[concat(variables('appGwID'), '/httpListeners/appGwHttpListener')]" | |
}, | |
"backendAddressPool": { | |
"id": "[concat(variables('appGwID'), '/backendAddressPools/', variables('appGwBePoolName'))]" | |
}, | |
"backendHttpSettings": { | |
"id": "[concat(variables('appGwID'), '/backendHttpSettingsCollection/appGwBackendHttpSettings')]" | |
} | |
} | |
} | |
] | |
} | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function setup_share_mount() { | |
local STORAGE_ACCOUNT_NAME="$1" | |
local FILE_SHARE_NAME="$2" | |
local STORAGE_ACCOUNT_KEY="$3" | |
grep -q -F "${STORAGE_ACCOUNT_NAME}.file.core.windows.net/${FILE_SHARE_NAME}" /etc/fstab && { echo 'already set up'; return 0; } | |
sudo mkdir "$LOCAL_WP_FILES_DIR" | |
chmod 0777 "$LOCAL_WP_FILES_DIR" | |
sudo mkdir -p /etc/smbcredentials | |
if [ ! -f "/etc/smbcredentials/${STORAGE_ACCOUNT_NAME}.cred" ]; then | |
echo -e "username=${STORAGE_ACCOUNT_NAME}\npassword=${STORAGE_ACCOUNT_KEY}" | sudo tee -a /etc/smbcredentials/${STORAGE_ACCOUNT_NAME}.cred | |
sudo chmod 600 /etc/smbcredentials/${STORAGE_ACCOUNT_NAME}.cred | |
fi | |
echo "//${STORAGE_ACCOUNT_NAME}.file.core.windows.net/${FILE_SHARE_NAME} "$LOCAL_WP_FILES_DIR" cifs nofail,vers=3.0,credentials=/etc/smbcredentials/${STORAGE_ACCOUNT_NAME}.cred,dir_mode=0777,file_mode=0677,serverino" | sudo tee -a /etc/fstab | |
} | |
STORAGE_ACCOUNT_NAME="" | |
FILE_SHARE_NAME="" | |
STORAGE_ACCOUNT_KEY="" | |
LOCAL_WP_FILES_DIR="/wpfiles" | |
while getopts "a:f:k:" opt; do | |
case $opt in | |
a) | |
STORAGE_ACCOUNT_NAME="$OPTARG" | |
;; | |
f) | |
FILE_SHARE_NAME="$OPTARG" | |
;; | |
k) | |
STORAGE_ACCOUNT_KEY="$OPTARG" | |
;; | |
*) | |
echo "Invalid option: -$opt" >&2 | |
exit 1 | |
;; | |
:) | |
echo "Option -$opt requires an argument." >&2 | |
exit 1 | |
;; | |
esac | |
done | |
for VAR_NAME in \ | |
STORAGE_ACCOUNT_NAME \ | |
FILE_SHARE_NAME \ | |
STORAGE_ACCOUNT_KEY \ | |
; do | |
eval "test -z \"\$$VAR_NAME\"" && { echo "$VAR_NAME is missing"; exit 1; } | |
done | |
setup_share_mount "$STORAGE_ACCOUNT_NAME" "$FILE_SHARE_NAME" "$STORAGE_ACCOUNT_KEY" | |
sudo mount -v "$LOCAL_WP_FILES_DIR" | |
sudo apt-get install -y nginx php-fpm php-mysql sendmail | |
sudo cp -v worker_nginx_virtualsite.conf /etc/nginx/sites-enabled/default | |
sudo systemctl restart nginx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80 default_server; | |
listen [::]:80 default_server; | |
root /wpfiles/; | |
index index.php index.html index.htm index.nginx-debian.html; | |
server_name _; | |
location / { | |
try_files $uri $uri/ =404; | |
} | |
location ~ \.php$ { | |
include snippets/fastcgi-php.conf; | |
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment