Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix azure arm template #3

Merged
merged 1 commit into from Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions deploy/arm-deploy-function-app.ps1
@@ -0,0 +1,24 @@
# create a resource group
$resourceGroup = "RevitRoomParser"
$location = "westeurope"
az group create -n $resourceGroup -l $location

# to check our deployement app
az deployment group what-if -g $resourceGroup --template-file deploy\azuredeploy.json `
--parameters deploy\parameters.json

# to deploy our function app
az deployment group create -g $resourceGroup --template-file deploy\azuredeploy.json `
--parameters deploy\parameters.json

# see what's in the resource group we just created
az resource list -g $resourceGroup -o table

$functionName = ($functionAppName + "Function")

# check the app settings were configured correctly
az functionapp config appsettings list `
-n $functionName -g $resourceGroup -o table

# to clean up when we're done
az group delete -n $resourceGroup --no-wait -y
223 changes: 223 additions & 0 deletions deploy/azuredeploy.json
@@ -0,0 +1,223 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appName": {
"type": "string",
"metadata": {
"description": "The name of the function app that you wish to create."
}
},
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [ "Standard_LRS", "Standard_GRS", "Standard_RAGRS" ],
"metadata": {
"description": "Storage Account type"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
},
"runtime": {
"type": "string",
"defaultValue": "dotnet",
"allowedValues": [ "node", "dotnet", "java" ],
"metadata": {
"description": "The language worker runtime to load in the function app."
}
},
"repositoryUrl": {
"type": "string",
"metadata": {
"description": "URL to the Github repository"
}
},
"repositoryToken": {
"type": "string",
"metadata": {
"description": "Token to the Github repository"
}
},
"RevitRoomParserForgeClientID": {
"type": "string",
"metadata": {
"description": "RevitToIFC Forge Client ID"
}
},
"RevitRoomParserForgeSecret": {
"type": "string",
"metadata": {
"description": "RevitToIFC Forge Client Secret"
}
},
"branch": {
"type": "string",
"defaultValue": "main",
"allowedValues": [ "master", "main" ],
"metadata": {
"description": "Branch in the Github repository"
}
},
"appLocation": {
"type": "string",
"defaultValue": "/",
"metadata": {
"description": "App Location"
}
},
"apiLocation": {
"type": "string",
"defaultValue": "",
"metadata": {
"description": "API Location"
}
},
"appArtifactLocation": {
"type": "string",
"defaultValue": "/",
"metadata": {
"description": "Artifact Location"
}
}
},
"variables": {
"functionAppName": "[concat(parameters('appName'), 'Function')]",
"hostingPlanName": "[parameters('appName')]",
"applicationInsightsName": "[parameters('appName')]",
"storageAccountName": "[substring(toLower(concat(parameters('appName'),uniquestring(resourceGroup().id))),0,23)]",
"storageAccountId": "[concat(resourceGroup().id,'/providers/','Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
"storageApiVersion": "[providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"apiVersion": "2016-01-01",
"location": "[parameters('location')]",
"kind": "Storage",
"sku": {
"name": "[parameters('storageAccountType')]"
}
},
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2015-08-01",
"name": "[variables('hostingPlanName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Y1",
"tier": "Dynamic"
},
"properties": {
"name": "[variables('hostingPlanName')]",
"computeMode": "Dynamic"
}
},
{
"apiVersion": "2015-08-01",
"type": "Microsoft.Web/sites",
"name": "[variables('functionAppName')]",
"location": "[parameters('location')]",
"kind": "functionapp",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]"
],
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
"siteConfig": {
"appSettings": [
{
"name": "FUNCTIONS_EXTENSION_VERSION",
"value": "~3"
},
{
"name": "Project",
"value": "api"
}
]
}
},
"resources": [
{
"apiVersion": "2018-11-01",
"name": "appsettings",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', variables('functionAppName'))]",
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]",
"[resourceId('Microsoft.Insights/components/', variables('applicationInsightsName'))]"
],
"properties": {
"WEBSITE_CONTENTAZUREFILECONNECTIONSTRING": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountId'),variables('storageApiVersion')).keys[0].value)]",
"WEBSITE_CONTENTSHARE": "[toLower(variables('functionAppName'))]",
"WEBSITE_NODE_DEFAULT_VERSION": "8.11.1",
"FUNCTIONS_WORKER_RUNTIME": "[parameters('runtime')]",
"StorageConnectionString": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountId'),variables('storageApiVersion')).keys[0].value)]",
"FUNCTIONS_EXTENSION_VERSION": "~3",
"APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId('microsoft.insights/components/', variables('applicationInsightsName')), '2015-05-01').InstrumentationKey]",
"FORGE_CLIENT_ID": "[parameters('RevitRoomParserForgeClientID')]",
"FORGE_CLIENT_SECRET": "[parameters('RevitRoomParserForgeSecret')]",
"local_uri": "[concat('https://',reference(resourceId('Microsoft.Web/staticSites', parameters('appName')), '2019-12-01-preview').defaultHostName)]"
}
}
]
},
{
"apiVersion": "2019-12-01-preview",
"name": "[parameters('appName')]",
"type": "Microsoft.Web/staticSites",
"location": "[parameters('location')]",
"tags": null,
"properties": {
"repositoryUrl": "[parameters('repositoryUrl')]",
"branch": "[parameters('branch')]",
"repositoryToken": "[parameters('repositoryToken')]",
"buildProperties": {
"appLocation": "[parameters('appLocation')]",
"apiLocation": "[parameters('apiLocation')]",
"appArtifactLocation": "[parameters('appArtifactLocation')]"
}
},
"sku": {
"Tier": "Free",
"Name": "Free"
},
"resources": [
{
"apiVersion": "2019-12-01-preview",
"name": "appsettings",
"type": "config",
"location": "[parameters('location')]",
"properties": {
"Project": ""
},
"dependsOn": [
"[resourceId('Microsoft.Web/staticSites', parameters('appName'))]",
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]",
"[resourceId('Microsoft.Insights/components/', variables('applicationInsightsName'))]"
]
}
]
},
{
"apiVersion": "2018-05-01-preview",
"name": "[variables('applicationInsightsName')]",
"type": "Microsoft.Insights/components",
"location": "[parameters('location')]",
"kind": "web",
"tags": {
"[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', variables('applicationInsightsName'))]": "Resource"
},
"properties": {
"ApplicationId": "[variables('applicationInsightsName')]",
"Request_Source": "IbizaWebAppExtensionCreate",
"Application_Type": "web"
}
}
]
}
118 changes: 118 additions & 0 deletions deploy/forge-deploy.ps1
@@ -0,0 +1,118 @@

try {
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
}
catch {
$scriptDir = 'C:\Users\Simon\Github\Forge\RevitRoomParser\deploy'
}

$settingsFile = Join-Path -Path $scriptDir -ChildPath ..\api\local.settings.json
$bundlePath = Join-Path -Path $scriptDir -ChildPath RevitToIFCBundle.zip

$settings = Get-Content -Raw -Path $settingsFile | ConvertFrom-Json

$env:FORGE_CLIENT_ID = $settings.Values.FORGE_CLIENT_ID
$env:FORGE_CLIENT_SECRET = $settings.Values.FORGE_CLIENT_SECRET

## Create the Forge bucket to store the converted files
# forge-dm create-bucket -r transient $settings.Values.ossBucketKey

## Create an array with every version of the engine
$engineVersions = '2018','2019', '2020', '2021'
$appName = 'RevitToIFC'

forge-da list-appbundles
forge-da list-activities

function DeployApplication($revitVersion,$bundle) {

$nickName = 'RevitToIFC'
$appbundle_file = $bundle
$appbundle_name = [string]::Format('{0}Bundle{1}',$appName,$revitVersion) # Your own appbundle name here
$appbundle_alias = $revitVersion # Your own alias name here
$appbundle_engine = [string]::Format('Autodesk.Revit+{0}',$revitVersion) # Your own appbundle engine here
$appDescription = [string]::Format('Export Revit {0} files to IFC',$engineVersion)

$activity_name = [string]::Format('{0}Activity{1}',$appName,$revitVersion) # Your own activity name here
$activity_alias = $revitVersion # Your own activity alias here

# Create or update an appbundle
Write-Host "Creating an appbundle $appbundle_name with zip file $appbundle_file"
$result = forge-da list-appbundles --short
$result = $result | Select-String -Pattern $appbundle_name | Measure-Object -Line
if ($result.Lines -eq 0) {
Write-Host "Creating new appbundle"
forge-da create-appbundle $appbundle_name $appbundle_file $appbundle_engine $appDescription
} else {
Write-Host "Updating existing appbundle"
forge-da update-appbundle $appbundle_name $appbundle_file $appbundle_engine $appDescription
}

# Create or update an appbundle alias
Write-Host "Creating an appbundle alias $appbundle_alias"
$result = forge-da list-appbundle-versions $appbundle_name --short
$appbundle_version = $result | Select-Object -Last 1
Write-Host "Last appbundle version: $appbundle_version"
$result = forge-da list-appbundle-aliases $appbundle_name --short
$result = $result | Select-String -Pattern $appbundle_alias | Measure-Object -Line
if ($result.Lines -eq 0) {
Write-Host "Creating new appbundle alias"
forge-da create-appbundle-alias $appbundle_alias $appbundle_name $appbundle_version
} else {
Write-Host "Updating existing appbundle alias"
forge-da update-appbundle-alias $appbundle_alias $appbundle_name $appbundle_version
}

# Create or update an activity
Write-Host "Creating an activity $activity_name"
Write-Host $activity_name $appbundle_name $appbundle_alias $appbundle_engine
$result = forge-da list-activities --short
$result = $result | Select-String -Pattern $activity_name | Measure-Object -Line
if ($result.Lines -eq 0) {
Write-Host "Creating new activity"
forge-da create-activity $activity_name $appbundle_name $appbundle_alias $appbundle_engine --update --nickname $nickName `
--input rvtFile --input-verb get --input-zip false --input-required true --input-description "Input Revit model" --input-local-name input.rvt `
--output result --output-verb put --output-zip false --output-required true --output-description "Results" --output-local-name output.ifc
} else {
Write-Host "Updating existing activity"
forge-da update-activity $activity_name $appbundle_name $appbundle_alias $appbundle_engine --update --nickname $nickName `
--input rvtFile --input-verb get --input-zip false --input-required true --input-description "Input Revit model" --input-local-name input.rvt `
--output result --output-verb put --output-zip false --output-required true --output-description "Results" --output-local-name output.ifc
}

# Create or update an activity alias
Write-Host "Creating an activity alias $activity_alias"
$result = forge-da list-activity-versions $activity_name --short
$activity_version = $result | Select-Object -Last 1
Write-Host "Last activity version: $activity_version"
$result = forge-da list-activity-aliases $activity_name --short
$result = $result | Select-String -Pattern $activity_alias | Measure-Object -Line
if ($result.Lines -eq 0) {
Write-Host "Creating new activity alias"
forge-da create-activity-alias $activity_alias $activity_name $activity_version
} else {
Write-Host "Updating existing activity alias"
forge-da update-activity-alias $activity_alias $activity_name $activity_version
}
}

## Loop on each version
foreach ($engineVersion in $engineVersions) {
DeployApplication -revitVersion $engineVersion -bundle $bundlePath
}

# # Delete all AppBundle
# foreach ($engineVersion in $engineVersions) {
# $appBundleId = [string]::Format('{0}Bundle{1}',$appName,$engineVersion)
# Write-Host "Deleting the existing appbundle $appBundleId"
# forge-da delete-appbundle $appBundleId
# }

# # Delete all activity
# foreach ($engineVersion in $engineVersions) {
# $appActivityId = [string]::Format('{0}Activity{1}',$appName,$engineVersion)
# Write-Host "Deleting the activity $appActivityId"
# forge-da delete-activity $appActivityId
# }