ancient-eve-13947
08/05/2021, 1:28 PMgreat-sunset-355
08/05/2021, 1:32 PMancient-eve-13947
08/05/2021, 1:46 PMprehistoric-activity-61023
08/05/2021, 2:08 PMancient-eve-13947
08/05/2021, 2:21 PMfunction createService(name: string, archiveName: string, settings: azure.types.input.web.NameValuePairArgs[][]){
var plan= new web.AppServicePlan(`${name}plan`, {
resourceGroupName,
kind: "Linux",
sku: {
size: "S1",
tier: "Standard",
name: "S1"
}
});
const filename = `${archiveName}.zip`;
const blobname= `${archiveName}.${formatForPath(new Date())}.zip`
const fullPath= path.join(cfg.require("PackagePath"), filename);
const deploymentBlob= new storage.Blob(blobname, {
resourceGroupName: resourceGroupName,
accountName: deploymentStorage[0],
containerName: deploymentStorage[1],
source: new pulumi.asset.FileAsset(fullPath)
})
const deploymentUrl= pulumi.all(
[deploymentStorage[0], deploymentStorage[1], resourceGroupName, deploymentBlob.name, deploymentBlob.id]).apply(
([accountName, containerName, rgName, blobName]) => getSASToken(accountName, containerName, rgName, blobName));
const appSettings= settings.reduce((current, v)=> current.concat(v), [
{
name: "WEBSITE_RUN_FROM_PACKAGE",
value: deploymentUrl
},
{
name: "ASPNETCORE_ENVIRONMENT",
value: getEnvironmentName()
}
]);
return new web.WebApp(name, {
resourceGroupName,
enabled: true,
serverFarmId: plan.id,
siteConfig: {
appSettings
}
});
function getEnvironmentName() : string {
switch (pulumi.getStack().toLowerCase()){
case "dev":
return "Development";
case "staging":
return "Staging";
case "production":
return "Production";
}
return "";
}
function formatForPath(when: Date){
const year= when.getFullYear();
const month= 1+when.getMonth();
const day= when.getDate();
const hour= when.getHours();
const minute= when.getMinutes();
const second= when.getSeconds();
return `${year}${pad(month)}${pad(day)}${pad(hour)}${pad(minute)}${pad(second)}`;
}
function getSASToken(storageAccountName: string, storageContainerName: string, resourceGroupName: string, blobName: string): pulumi.Output<string> {
const blobSAS = storage.listStorageAccountServiceSAS({
accountName: storageAccountName,
protocols: storage.HttpProtocol.Https,
sharedAccessStartTime: format(new Date()),
sharedAccessExpiryTime: format(nextYear()),
resource: storage.SignedResource.C,
resourceGroupName: resourceGroupName,
permissions: storage.Permissions.R,
canonicalizedResource: "/blob/" + storageAccountName + "/" + storageContainerName,
contentType: "application/json",
cacheControl: "max-age=5",
contentDisposition: "inline",
contentEncoding: "deflate",
});
return pulumi.interpolate `https://${storageAccountName}.<http://blob.core.windows.net/${storageContainerName}/${blobName}?${blobSAS.then(x|blob.core.windows.net/${storageContainerName}/${blobName}?${blobSAS.then(x> => x.serviceSasToken)}`;
function format(when: Date){
const year= when.getFullYear();
const month= 1+when.getMonth();
const day= when.getDate();
return `${year}-${pad(month)}-${pad(day)}`;
}
function nextYear():Date {
const result= new Date();
result.setFullYear(result.getFullYear()+1);
return result;
}
}
function pad(n: number){
return n.toString().padStart(2, '0');
}
}
prehistoric-activity-61023
08/05/2021, 2:25 PMancient-eve-13947
08/05/2021, 2:25 PMprehistoric-activity-61023
08/05/2021, 2:27 PMancient-eve-13947
08/05/2021, 2:27 PMprehistoric-activity-61023
08/05/2021, 2:28 PM