-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.msbuild
159 lines (116 loc) · 13.9 KB
/
deploy.msbuild
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Deploy" ToolsVersion="4.0">
<PropertyGroup>
<GXDeployFileProject>$([System.IO.Path]::GetFullPath('$(DeployFullPath)\..\..\..\..\web\$(ProjectName).gxdproj'))</GXDeployFileProject>
</PropertyGroup>
<Import Project= "createpackage.msbuild" Condition = "'$(CreateCloudPackage)' == 'true'" />
<Import Project="$(GXDeployFileProject)" Condition = "'$(CreateCloudPackage)' == '' or '$(CreateCloudPackage)' == 'false'"/>
<Import Project="cosmosdb\deploycosmosdb.msbuild" />
<Import Project="blobstorage\deployblobstorage.msbuild" Condition= "'$(AZURE_FUNCTIONS_TRIGGER_TYPE)' == 'blobstorage'"/>
<Target Name = "CreateCloudPackage">
<CallTarget Targets="CreatePackage" Condition = "'$(CreateCloudPackage)' == 'true'"/>
</Target>
<Target Name="AzLogin">
<Exec Command="az login --service-principal --username $(AZURE_FUNCTIONS_SP_APP_ID) --tenant $(AZURE_FUNCTIONS_SP_TENANT_ID) --password $(AZURE_FUNCTIONS_SP_CREDENTIALS)" EchoOff="true" StandardOutputImportance="Low" />
<Message Text="Authentication to Azure finished." Importance="high"/>
</Target>
<Target Name="AzPublish">
<ItemGroup>
<pathToFile Include="$([MSBuild]::Escape('$(DeployFileFullPath)\$(ProjectName)_$(AZURE_FUNCTIONS_FUNCTION_NAME).zip'))" />
</ItemGroup>
<Message Text="Deploying to Azure functions ...." Importance="high"/>
<Exec Command="az functionapp deployment source config-zip -g $(AZURE_FUNCTIONS_RESOURCE_GROUP) -n $(AZURE_FUNCTIONS_FUNCTION_APP) --src %(pathToFile.Identity)" ConsoleToMSBuild="true" ContinueOnError="true" >
<Output TaskParameter="ConsoleOutput" PropertyName="OUTPUT_MESSAGE" />
<Output TaskParameter="ExitCode" PropertyName="AZ_EXIT_CODE"/>
</Exec>
<Error Text= "Error publishing to Azure Functions: $(OUTPUT_MESSAGE)" Condition = "'$(OUTPUT_MESSAGE)' != 'ServiceError: Unknown error' AND '$(AZ_EXIT_CODE)' == '1'" />
</Target>
<Target Name="InitializeMappingVars" Inputs="@(SelectedObject)" Outputs="%(SelectedObject.Identity)" >
<PropertyGroup>
<EntryPointClassName Condition = "'$(GENERATOR)' == 'Java' AND '%(SelectedObject.Module)' != '' AND $(Namespace) != ''">$(Namespace).%(SelectedObject.Module).a%(SelectedObject.Identity)</EntryPointClassName>
<EntryPointClassName Condition = "'$(GENERATOR)' == 'Java' AND '%(SelectedObject.Module)' == '' AND $(Namespace) != ''">$(Namespace).a%(SelectedObject.Identity)</EntryPointClassName>
<EntryPointClassName Condition = "'$(GENERATOR)' == 'Java' AND '%(SelectedObject.Module)' != '' AND $(Namespace) == ''">%(SelectedObject.Module).a%(SelectedObject.Identity)</EntryPointClassName>
<EntryPointClassName Condition = "'$(GENERATOR)' == 'Java' AND '%(SelectedObject.Module)' == '' AND $(Namespace) == ''">a%(SelectedObject.Identity)</EntryPointClassName>
<EntryPointClassName Condition = "('$(GENERATOR)' == '.NET Core' or '$(GENERATOR)' == '.NET') AND '%(SelectedObject.Module)' != ''">%(SelectedObject.Module).a%(SelectedObject.Identity)</EntryPointClassName>
<EntryPointClassName Condition = "('$(GENERATOR)' == '.NET Core' or '$(GENERATOR)' == '.NET') AND '%(SelectedObject.Module)' == ''">a%(SelectedObject.Identity)</EntryPointClassName>
<EntryPointClassName>$(EntryPointClassName.ToLower())</EntryPointClassName>
<UpperFunctionName>$(AZURE_FUNCTIONS_FUNCTION_NAME.ToUpperInvariant())</UpperFunctionName>
<EnvVarName>GX_AZURE_$(UpperFunctionName)_CLASS</EnvVarName>
</PropertyGroup>
</Target>
<Target Name="Deploy" DependsOnTargets="ValidateDeployment;CreateCloudPackage;AzLogin;AzPublish;InitializeMappingVars">
<Message Text="Deploying to Azure functions finished successfully." Condition="'$(AZ_EXIT_CODE)' == '0' Or '$(OUTPUT_MESSAGE)' == 'ServiceError: Unknown error'" Importance="high"/>
<PropertyGroup Condition="'$(AZ_EXIT_CODE)' == '0' Or '$(OUTPUT_MESSAGE)' == 'ServiceError: Unknown error'" >
<SuccessfullOperation>true</SuccessfullOperation>
</PropertyGroup>
<!-- Define App Settings -->
<Message Text="Pushing global app settings ..." Importance="high"/>
<!-- Azure mappings :map function to GX object -->
<Exec Command="az functionapp config appsettings set --name $(AZURE_FUNCTIONS_FUNCTION_APP) --resource-group $(AZURE_FUNCTIONS_RESOURCE_GROUP) --settings "$(EnvVarName)=$(EntryPointClassName)"" EchoOff="true" ContinueOnError="true" Condition="'$(EntryPointClassName)' != ' ' AND '$(EnvVarName)' != '' AND '$(SuccessfullOperation)' == 'true'">
<Output TaskParameter="ExitCode" PropertyName="PUSHMAPPING_EXIT_CODE"/>
</Exec>
<Message Text="Definition of $(EnvVarName) setting was successfull." Importance="high" Condition = "'$(SuccessfullOperation)' == 'true' AND '$(PUSHMAPPING_EXIT_CODE)' == '0'"/>
<!-- CosmosDB -->
<CallTarget Targets="DeployCosmosDB" Condition = "'$(AZURE_FUNCTIONS_TRIGGER_TYPE)' == 'cosmosdb'"/>
<!-- BlobStorage -->
<CallTarget Targets="DeployBlobStorage" Condition = "'$(AZURE_FUNCTIONS_TRIGGER_TYPE)' == 'blobstorage'"/>
<!-- Timer -->
<Exec Command="az functionapp config appsettings set --name $(AZURE_FUNCTIONS_FUNCTION_APP) --resource-group $(AZURE_FUNCTIONS_RESOURCE_GROUP) --settings "$(AZURE_FUNCTIONS_SCHEDULE_TIME_APPSETTINGNAME)=$(AZURE_FUNCTIONS_SCHEDULE_TIME_APPSETTINGVALUE)"" EchoOff="true" ContinueOnError="true" Condition="'$(AZURE_FUNCTIONS_TRIGGER_TYPE)' == 'Timer' AND '$(AZURE_FUNCTIONS_SCHEDULE_TIME_FORMAT)'=='appsettingvaluepair' AND '$(AZURE_FUNCTIONS_SCHEDULE_TIME_APPSETTINGNAME)' != '' AND '$(AZURE_FUNCTIONS_SCHEDULE_TIME_APPSETTINGVALUE)' != '' AND '$(SuccessfullOperation)' == 'true'">
<Output TaskParameter="ExitCode" PropertyName="PUSHTIMERSETTINGS_EXIT_CODE"/>
</Exec>
<!-- Queue -->
<Exec Command="az functionapp config appsettings set --name $(AZURE_FUNCTIONS_FUNCTION_APP) --resource-group $(AZURE_FUNCTIONS_RESOURCE_GROUP) --settings "$(AZURE_FUNCTIONS_QUEUE_CONNECTION)=$(AZURE_FUNCTIONS_QUEUE_CONNECTION_APPSETTINGVALUE)"" EchoOff="true" ContinueOnError="true" Condition="'$(AZURE_FUNCTIONS_TRIGGER_TYPE)' == 'Queue' AND '$(AZURE_FUNCTIONS_QUEUE_CONNECTION)' != '' AND '$(AZURE_FUNCTIONS_QUEUE_CONNECTION_APPSETTINGVALUE)' != '' AND '$(SuccessfullOperation)' == 'true'">
<Output TaskParameter="ExitCode" PropertyName="PUSHQUEUESETTINGS_EXIT_CODE"/>
</Exec>
<Exec Command="az functionapp config appsettings set --name $(AZURE_FUNCTIONS_FUNCTION_APP) --resource-group $(AZURE_FUNCTIONS_RESOURCE_GROUP) --settings "AzureWebJobs$(AZURE_FUNCTIONS_QUEUE_CONNECTION)=$(AZURE_FUNCTIONS_QUEUE_CONNECTION_APPSETTINGVALUE)"" EchoOff="true" ContinueOnError="true" Condition="'$(AZURE_FUNCTIONS_TRIGGER_TYPE)' == 'Queue' AND '$(AZURE_FUNCTIONS_QUEUE_CONNECTION)' != '' AND '$(AZURE_FUNCTIONS_QUEUE_CONNECTION_APPSETTINGVALUE)' != '' AND '$(SuccessfullOperation)' == 'true'">
<Output TaskParameter="ExitCode" PropertyName="PUSHQUEUESETTINGS_EXIT_CODE"/>
</Exec>
<!-- Service Bus -->
<Exec Command="az functionapp config appsettings set --name $(AZURE_FUNCTIONS_FUNCTION_APP) --resource-group $(AZURE_FUNCTIONS_RESOURCE_GROUP) --settings "$(AZURE_FUNCTIONS_SERVICEBUS_CONNECTION)=$(AZURE_FUNCTIONS_SERVICEBUS_CONNECTION_APPSETTINGVALUE)"" EchoOff="true" ContinueOnError="true" Condition="'$(AZURE_FUNCTIONS_TRIGGER_TYPE)' == 'servicebus' AND '$(AZURE_FUNCTIONS_SERVICEBUS_CONNECTION)' != '' AND '$(AZURE_FUNCTIONS_SERVICEBUS_CONNECTION_APPSETTINGVALUE)' != '' AND '$(SuccessfullOperation)' == 'true'">
<Output TaskParameter="ExitCode" PropertyName="PUSHSBSETTINGS_EXIT_CODE"/>
</Exec>
<Exec Command="az functionapp config appsettings set --name $(AZURE_FUNCTIONS_FUNCTION_APP) --resource-group $(AZURE_FUNCTIONS_RESOURCE_GROUP) --settings "AzureWebJobs$(AZURE_FUNCTIONS_SERVICEBUS_CONNECTION)=$(AZURE_FUNCTIONS_SERVICEBUS_CONNECTION_APPSETTINGVALUE)"" EchoOff="true" ContinueOnError="true" Condition="'$(AZURE_FUNCTIONS_TRIGGER_TYPE)' == 'servicebus' AND '$(AZURE_FUNCTIONS_SERVICEBUS_CONNECTION)' != '' AND '$(AZURE_FUNCTIONS_SERVICEBUS_CONNECTION_APPSETTINGVALUE)' != '' AND '$(SuccessfullOperation)' == 'true'">
<Output TaskParameter="ExitCode" PropertyName="PUSHSBSETTINGS_EXIT_CODE"/>
</Exec>
<!-- Define App Settings for GAM connection -->
<PropertyGroup>
<GAMConnectionKey>GX_GAMCONNECTIONKEY</GAMConnectionKey>
</PropertyGroup>
<Exec Command="az functionapp config appsettings set --name $(AZURE_FUNCTIONS_FUNCTION_APP) --resource-group $(AZURE_FUNCTIONS_RESOURCE_GROUP) --settings "$(GAMConnectionKey)=$(AZURE_FUNCTIONS_GAM_CONNECTION_KEY)"" EchoOff="true" ContinueOnError="true" Condition="'$(AZURE_FUNCTIONS_GAM_CONNECTION_KEY)' != '' and '$(AZURE_FUNCTIONS_TRIGGER_TYPE)' == 'http' AND '$(SuccessfullOperation)' == 'true'">
<Output TaskParameter="ExitCode" PropertyName="PUSHGAMSETTINGS_EXIT_CODE"/>
</Exec>
<Message Text="Pushing GAM app settings finished." Importance="high" Condition = "'$(SuccessfullOperation)' == 'true' and '$(PUSHGAMSETTINGS_EXIT_CODE)' == '0' and '$(IntegratedSecurityEnabled)' == 'true'"/>
<Message Text="Pushing GAM app settings failed. Please define the GX_GAMCONNECTIONKEY app setting in Azure." Importance="high" Condition = "'$(SuccessfullOperation)' == 'true' and '$(PUSHSETTINGS_EXIT_CODE)' != '0' and '$(IntegratedSecurityEnabled)' == 'true'"/>
<!-- Deploy to Azure API Management -->
<PropertyGroup>
<DeploytoAPIManagementOn Condition="$(AZURE_FUNCTIONS_TRIGGER_TYPE) == 'http' and $(AZURE_APIM_SERVICE_NAME) != '' and $(AZURE_APIM_RESOURCE_GROUP) != '' and
$(AZURE_APIM_API_ID) != '' and $(AZURE_APIM_API_SERVICE_URL) != '' and $(AZURE_APIM_API_DISPLAY_NAME) != ''">true</DeploytoAPIManagementOn>
</PropertyGroup>
<Message Text="Deploy to Azure API Management skipped because at least one property value is empty." Importance="high" Condition = "$(AZURE_FUNCTIONS_TRIGGER_TYPE) == 'http' AND $(DeploytoAPIManagementOn) != 'true'"/>
<Message Text="Deploying to Azure API Management..." Importance="high" Condition = "$(AZURE_FUNCTIONS_TRIGGER_TYPE) == 'http' AND $(DeploytoAPIManagementOn) == 'true'"/>
<Exec Command="az apim api versionset create --resource-group $(AZURE_APIM_RESOURCE_GROUP) --service-name $(AZURE_APIM_SERVICE_NAME) --version-set-id $(AZURE_APIM_API_VERSION_SET_ID) --display-name "$(AZURE_APIM_API_VERSION_SET_DISPLAY_NAME)" --versioning-scheme "Segment"" EchoOff="true" ContinueOnError="true" IgnoreStandardErrorWarningFormat = "true" Condition="'$(AZURE_FUNCTIONS_TRIGGER_TYPE)' == 'http' AND '$(DeploytoAPIManagementOn)'=='true' AND '$(AZURE_APIM_API_VERSION_SET_ID)' != '' AND $(AZURE_APIM_API_VERSION_SET_DISPLAY_NAME) != '' AND $(AZURE_APIM_API_VERSION) != '' AND '$(SuccessfullOperation)' == 'true'">
<Output TaskParameter="ExitCode" PropertyName="CREATE_VERSION_SET_EXIT_CODE"/>
</Exec>
<Warning
Text="APIM Version Set will not be created as any of these properties is empty : API Version Set Id, API Version Set display name, API Version."
Condition="$(DeploytoAPIManagementOn) =='true' AND $(SuccessfullOperation) == 'true' AND ($(AZURE_APIM_API_VERSION_SET_ID) == '' OR $(AZURE_APIM_API_VERSION_SET_DISPLAY_NAME) == '' OR $(AZURE_APIM_API_VERSION) == '')" />
<Exec Command="az apim api import --resource-group $(AZURE_APIM_RESOURCE_GROUP) --service-name $(AZURE_APIM_SERVICE_NAME) --specification-format OpenApiJson --api-id $(AZURE_APIM_API_ID) --service-url $(AZURE_APIM_API_SERVICE_URL) --specification-path "$(OpenAPIDefinitionOutputFile)" --subscription-required $(AZURE_APIM_API_SUBSCRIPTION_REQUIRED) --path "$(AZURE_APIM_API_PATH)" --display-name "$(AZURE_APIM_API_DISPLAY_NAME)"" EchoOff="true" ContinueOnError="true" IgnoreStandardErrorWarningFormat = "true" Condition="'$(AZURE_FUNCTIONS_TRIGGER_TYPE)' == 'http' AND '$(DeploytoAPIManagementOn)'=='true' AND '$(AZURE_APIM_API_VERSION_SET_ID)' == '' AND '$(AZURE_APIM_API_VERSION)' == '' AND '$(SuccessfullOperation)' == 'true'">
<Output TaskParameter="ExitCode" PropertyName="DEPLOYAPIM_EXIT_CODE"/>
</Exec>
<Exec Command="az apim api import --resource-group $(AZURE_APIM_RESOURCE_GROUP) --service-name $(AZURE_APIM_SERVICE_NAME) --specification-format OpenApiJson --api-id $(AZURE_APIM_API_ID) --service-url $(AZURE_APIM_API_SERVICE_URL) --specification-path "$(OpenAPIDefinitionOutputFile)" --subscription-required $(AZURE_APIM_API_SUBSCRIPTION_REQUIRED) --path "$(AZURE_APIM_API_PATH)" --display-name "$(AZURE_APIM_API_DISPLAY_NAME)" --api-version $(AZURE_APIM_API_VERSION) --api-version-set-id $(AZURE_APIM_API_VERSION_SET_ID)" EchoOff="true" ContinueOnError="true" IgnoreStandardErrorWarningFormat = "true" Condition="'$(AZURE_FUNCTIONS_TRIGGER_TYPE)' == 'http' AND '$(AZURE_APIM_API_VERSION_SET_ID)' != '' AND '$(AZURE_APIM_API_VERSION)' != '' AND '$(DeploytoAPIManagementOn)'=='true' AND '$(SuccessfullOperation)' == 'true'">
<Output TaskParameter="ExitCode" PropertyName="DEPLOYAPIM_EXIT_CODE"/>
</Exec>
<Message Text="Deployment to API Management finished." Importance="high" Condition = "'$(SuccessfullOperation)' == 'true' AND '$(DEPLOYAPIM_EXIT_CODE)' == '0'"/>
<Error Text="Deployment to API Management failed." Condition = "'$(DeploytoAPIManagementOn)' == 'true' AND '$(DEPLOYAPIM_EXIT_CODE)' != '0'" />
</Target>
<Target Name="ValidateDeployment" >
<Error
Text="Azure functions deployment failed: The Azure settings cannot be empty."
Condition="$(AZURE_FUNCTIONS_FUNCTION_APP) == '' Or $(AZURE_FUNCTIONS_RESOURCE_GROUP) == ''" />
<Error
Text="Azure functions deployment failed: The Azure Identity settings must be complete."
Condition="$(AZURE_FUNCTIONS_SP_APP_ID) == '' Or $(AZURE_FUNCTIONS_SP_TENANT_ID) == '' Or $(AZURE_FUNCTIONS_SP_CREDENTIALS) == ''" />
<Error
Text="Azure functions deployment failed: The APIM Version Set cannot be empty if the APIM API Version has a value."
Condition="$(AZURE_FUNCTIONS_TRIGGER_TYPE) == 'http' AND $(AZURE_APIM_API_VERSION_SET_ID) == '' AND $(AZURE_APIM_API_VERSION) != ''" />
</Target>
</Project>