Skip to content

Commit

Permalink
Try to fix zip-in-zip problem
Browse files Browse the repository at this point in the history
Configure Run From Package in ARM templates
  • Loading branch information
idg10 committed Jan 24, 2020
1 parent ac25bfd commit 1d152e1
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 105 deletions.
2 changes: 0 additions & 2 deletions Solutions/Marain.Tenancy.Deployment/Marain-ArmDeploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Function MarainDeployment([MarainServiceDeploymentContext] $ServiceDeploymentCon
# don't want to be creating a storage account per service just to support this.
$TemplateParameters = @{
appName="tenancy"
functionsAppPackageFolder="MsDeploy"
functionsAppPackageFileName="Marain.Tenancy.Host.Functions.zip"
functionEasyAuthAadClientId=$ServiceDeploymentContext.Variables["TenancyAppId"]
}
$InstanceResourceGroupName = $InstanceDeploymentContext.MakeResourceGroupName("tenancy")
Expand Down
161 changes: 82 additions & 79 deletions Solutions/Marain.Tenancy.Deployment/Marain-PostDeploy.ps1
Original file line number Diff line number Diff line change
@@ -1,84 +1,87 @@
<#
.EXAMPLE
.\deploy.ps1 `
-Prefix "mar" `
-AppName "tenancy" `
-Environment "dev" `
-FunctionsMsDeployPackagePath "..\Marain.Tenancy.Host.Functions\bin\Release\package\Marain.Tenancy.Host.Functions.zip"
This is called during Marain.Instance infrastructure deployment after the Marain-ArmDeploy.ps
script. It is our opportunity to do any deployment work that needs to happen after Azure resources
have been deployed.
#>

[CmdletBinding(DefaultParametersetName='None')]
param(
[string] $Prefix = "mar",
[string] $AppName = "tenancy",
[ValidateLength(3,12)]
[string] $Suffix = "dev",
[string] $FunctionsMsDeployPackagePath = "..\Marain.Tenancy.Host.Functions\bin\Release\package\Marain.Tenancy.Host.Functions.zip",
[string] $ResourceGroupLocation = "northeurope",
[string] $ArtifactStagingDirectory = ".",
[string] $ArtifactStorageContainerName = "stageartifacts",
[switch] $IsDeveloperEnvironment,
[switch] $UpdateLocalConfigFiles,
[switch] $SkipDeployment
)

Begin{
# Setup options and variables
$ErrorActionPreference = 'Stop'
Set-Location $PSScriptRoot

$Suffix = $Suffix.ToLower()
$AppName = $AppName.ToLower()
$Prefix = $Prefix.ToLower()

$ResourceGroupName = $Prefix + "." + $AppName.ToLower() + "." + $Suffix
$DefaultName = $Prefix + $AppName.ToLower() + $Suffix

$ArtifactStorageResourceGroupName = $ResourceGroupName + ".artifacts";
$ArtifactStorageAccountName = $Prefix + $AppName + $Suffix + "ar"
$ArtifactStagingDirectory = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, $ArtifactStagingDirectory))

$FunctionsMsDeployPackageFolderName = "MsDeploy";

$FunctionsAppPackageFileName = [System.IO.Path]::GetFileName($FunctionsMsDeployPackagePath)

$CosmosDbName = $DefaultName
$KeyVaultName = $DefaultName
}

Process{

#.\Scripts\Grant-CurrentAadUserKeyVaultSecretAccess `
# -ResourceGroupName $ResourceGroupName `
# -KeyVaultName $KeyVaultName

.\Scripts\Add-CosmosAccessKeyToKeyVault `
-ResourceGroupName $ResourceGroupName `
-KeyVaultName $KeyVaultName `
-CosmosDbName $CosmosDbName `
-SecretName 'tenancystorecosmosdbkey'

Write-Host 'Grant the function access to the KV'

$FunctionAppName = $Prefix + $AppName.ToLower() + $Suffix

.\Scripts\Grant-KeyVaultSecretGetToMsi `
-ResourceGroupName $ResourceGroupName `
-KeyVaultName $KeyVaultName `
-AppName $FunctionAppName

Write-Host 'Revoking KV secret access to current user'

.\Scripts\Revoke-CurrentAadUserKeyVaultSecretAccess `
-ResourceGroupName $ResourceGroupName `
-KeyVaultName $KeyVaultName
}

End{
Write-Host -ForegroundColor Green "`n######################################################################`n"
Write-Host -ForegroundColor Green "Deployment finished"
Write-Host -ForegroundColor Green "`n######################################################################`n"
# Marain.Instance expects us to define just this one function.
Function MarainDeployment([MarainServiceDeploymentContext] $ServiceDeploymentContext) {

$ServiceDeploymentContext.UploadReleaseAssetAsAppServiceSitePackage(
"Marain.Tenancy.Host.Functions.zip",
$ServiceDeploymentContext.AppName
)

# [CmdletBinding(DefaultParametersetName='None')]
# param(
# [string] $Prefix = "mar",
# [string] $AppName = "tenancy",
# [ValidateLength(3,12)]
# [string] $Suffix = "dev",
# [string] $FunctionsMsDeployPackagePath = "..\Marain.Tenancy.Host.Functions\bin\Release\package\Marain.Tenancy.Host.Functions.zip",
# [string] $ResourceGroupLocation = "northeurope",
# [string] $ArtifactStagingDirectory = ".",
# [string] $ArtifactStorageContainerName = "stageartifacts",
# [switch] $IsDeveloperEnvironment,
# [switch] $UpdateLocalConfigFiles,
# [switch] $SkipDeployment
# )

# Begin{
# # Setup options and variables
# $ErrorActionPreference = 'Stop'
# Set-Location $PSScriptRoot

# $Suffix = $Suffix.ToLower()
# $AppName = $AppName.ToLower()
# $Prefix = $Prefix.ToLower()

# $ResourceGroupName = $Prefix + "." + $AppName.ToLower() + "." + $Suffix
# $DefaultName = $Prefix + $AppName.ToLower() + $Suffix

# $ArtifactStorageResourceGroupName = $ResourceGroupName + ".artifacts";
# $ArtifactStorageAccountName = $Prefix + $AppName + $Suffix + "ar"
# $ArtifactStagingDirectory = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, $ArtifactStagingDirectory))

# $FunctionsMsDeployPackageFolderName = "MsDeploy";

# $FunctionsAppPackageFileName = [System.IO.Path]::GetFileName($FunctionsMsDeployPackagePath)

# $CosmosDbName = $DefaultName
# $KeyVaultName = $DefaultName
# }

# Process{

# #.\Scripts\Grant-CurrentAadUserKeyVaultSecretAccess `
# # -ResourceGroupName $ResourceGroupName `
# # -KeyVaultName $KeyVaultName

# .\Scripts\Add-CosmosAccessKeyToKeyVault `
# -ResourceGroupName $ResourceGroupName `
# -KeyVaultName $KeyVaultName `
# -CosmosDbName $CosmosDbName `
# -SecretName 'tenancystorecosmosdbkey'

# Write-Host 'Grant the function access to the KV'

# $FunctionAppName = $Prefix + $AppName.ToLower() + $Suffix

# .\Scripts\Grant-KeyVaultSecretGetToMsi `
# -ResourceGroupName $ResourceGroupName `
# -KeyVaultName $KeyVaultName `
# -AppName $FunctionAppName

# Write-Host 'Revoking KV secret access to current user'

# .\Scripts\Revoke-CurrentAadUserKeyVaultSecretAccess `
# -ResourceGroupName $ResourceGroupName `
# -KeyVaultName $KeyVaultName
# }

# End{
# Write-Host -ForegroundColor Green "`n######################################################################`n"
# Write-Host -ForegroundColor Green "Deployment finished"
# Write-Host -ForegroundColor Green "`n######################################################################`n"
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
"storageAccountConnectionString": {
"type": "string"
},
"runFromPackage": {
"type": "string",
"defaultValue": ""
},
"functionsAppName": {
"type": "string",
"minLength": 1
},
"keyVaultName": {
"keyVaultName": {
"type": "string",
"minLength": 1
},
"cosmosDbName": {
"cosmosDbName": {
"type": "string",
"minLength": 1
},
Expand Down Expand Up @@ -45,6 +49,7 @@
"properties": {
"WEBSITE_CONTENTAZUREFILECONNECTIONSTRING": "[parameters('storageAccountConnectionString')]",
"WEBSITE_CONTENTSHARE": "[toLower(parameters('functionsAppName'))]",
"WEBSITE_RUN_FROM_PACKAGE": "[parameters('runFromPackage')]",
"AzureConfigurationStorage": "[parameters('storageAccountConnectionString')]",
"APPINSIGHTS_INSTRUMENTATIONKEY": "[parameters('applicationInsightsInstrumentationKey')]",
"FUNCTIONS_EXTENSION_VERSION": "beta",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
},
"functionsAppPackageFolder": {
"type": "string",
"minLength": 1,
"defaultValue": "",
"metadata": {
"description": "WebDeploy package location. This path is relative to the artifactsLocation parameter"
}
},
"functionsAppPackageFileName": {
"type": "string",
"minLength": 1,
"defaultValue": "",
"metadata": {
"description": "Name of the webdeploy package"
}
Expand Down Expand Up @@ -114,6 +114,7 @@
"name": "MSDeploy",
"type": "Extensions",
"apiVersion": "2015-02-01",
"condition": "[not(empty(parameters('functionsAppPackageFileName')))]",
"dependsOn": [
"[concat('Microsoft.Web/sites/', parameters('functionsAppName'))]"
],
Expand Down
14 changes: 1 addition & 13 deletions Solutions/Marain.Tenancy.Deployment/deploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@
"environmentSuffix": {
"type": "string"
},
"functionsAppPackageFolder": {
"type": "string",
"minLength": 1
},
"functionsAppPackageFileName": {
"type": "string",
"minLength": 1,
"metadata": {
"description": "Name of the webdeploy package for host function"
}
},
"functionEasyAuthAadClientId": {
"type": "string",
"defaultValue": "",
Expand Down Expand Up @@ -139,8 +128,6 @@
},
"parameters": {
"functionsAppName": { "value": "[variables('functionsAppName')]" },
"functionsAppPackageFolder": { "value": "[parameters('functionsAppPackageFolder')]" },
"functionsAppPackageFileName": { "value": "[parameters('functionsAppPackageFileName')]" },
"easyAuthAadClientId": { "value": "[parameters('functionEasyAuthAadClientId')]" },
"_artifactsLocation": { "value": "[parameters('_artifactsLocation')]" },
"_artifactsLocationSasToken": { "value": "[parameters('_artifactsLocationSasToken')]" }
Expand All @@ -163,6 +150,7 @@
},
"parameters": {
"storageAccountConnectionString": { "value": "[reference('functions-app', '2016-09-01').outputs.storageAccountConnectionString.value]" },
"runFromPackage": { "value": "1" },
"functionsAppName": { "value": "[variables('functionsAppName')]" },
"tenantId": { "value": "[variables('tenantId')]" },
"subscriptionId": { "value": "[variables('subscriptionId')]" },
Expand Down
22 changes: 15 additions & 7 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,19 @@ jobs:
arguments: '--configuration $(BuildConfiguration) /p:Version=$(GitVersion.SemVer) --no-build -o $(Build.SourcesDirectory)/Solutions/Marain.Tenancy.Host.Functions/bin/$(BuildConfiguration)/publish/'
versioningScheme: byBuildNumber
publishWebProjects: false
- task: ArchiveFiles@2
displayName: 'Create Run-From-Package ZIP'
#- task: ArchiveFiles@2
# displayName: 'Create Run-From-Package ZIP'
# inputs:
# rootFolderOrFile: '$(Build.SourcesDirectory)/Solutions/Marain.Tenancy.Host.Functions/bin/$(BuildConfiguration)/publish/'
# includeRootFolder: false
# archiveType: 'zip'
# archiveFile: '$(Build.ArtifactStagingDirectory)/Release/Marain.Deployment.Functions/Marain.Tenancy.Host.Functions.zip'
# replaceExistingArchive: true
# Even though running the command above at the command line produces the output as a bunch of folders and
# files, on the build server it appears to produce an actual ZIP, so we just need to copy the result
- task: CopyFiles@2
displayName: 'Copy Azure Deployment ZIPs to Release Folder'
inputs:
rootFolderOrFile: '$(Build.SourcesDirectory)/Solutions/Marain.Tenancy.Host.Functions/bin/$(BuildConfiguration)/publish/'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/Release/Marain.Deployment.Functions/Marain.Tenancy.Host.Functions.zip'
replaceExistingArchive: true
SourceFolder: '$(Build.SourcesDirectory)/Solutions/Marain.Tenancy.Host.Functions/bin/$(BuildConfiguration)/publish/'
Contents: '*.zip'
TargetFolder: '$(Build.ArtifactStagingDirectory)/Release/Marain.Deployment.Functions'

0 comments on commit 1d152e1

Please sign in to comment.