Skip to content

Commit d4437a7

Browse files
committed
chore: improve deployments
1 parent 736e9e1 commit d4437a7

File tree

4 files changed

+70
-56
lines changed

4 files changed

+70
-56
lines changed

infra/hooks/portal/.eslintrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"env": {
3+
"node": true,
4+
"commonjs": true
5+
},
6+
"extends": "eslint:recommended"
7+
}

infra/hooks/portal/predeploy.js

+34-27
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const blogPlaceholderValue = "{{SERVICE_BLOG_URI_PLACEHOLDER}}";
1313
const cmsRegex = /SERVICE_CMS_URI="([^"]+)"/;
1414
const cmsPlaceholderValue = "{{SERVICE_CMS_URI_PLACEHOLDER}}";
1515
const aiEnableRegex = /AI_ENABLE_CHAT="([^"]+)"/;
16-
const aiEnablePlaceholderValue = "\"{{AI_ENABLE_CHAT_PLACEHOLDER}}\"";
16+
const aiEnablePlaceholderValue = '"{{AI_ENABLE_CHAT_PLACEHOLDER}}"';
1717
const aiChatApiRegex = /AI_CHAT_API_URI="([^"]+)"/;
1818
const aiChatApiPlaceholderValue = "{{AI_CHAT_API_URI_PLACEHOLDER}}";
1919
const webPubSubUrlRegex = /SERVICE_WEB_PUB_SUB_URL="([^"]+)"/;
@@ -27,42 +27,49 @@ const distPath = resolve(__dirname, "../../../packages/portal/dist/contoso-app")
2727
function replaceEnvURIs(filePath) {
2828
const matchBlog = envVars.match(blogRegex);
2929
const matchCms = envVars.match(cmsRegex);
30-
const webPubSubUrl = envVars.match(webPubSubUrlRegex);
31-
const webPubSubPath = envVars.match(webPubSubPathRegex);
30+
const matchWebPubSubUrl = envVars.match(webPubSubUrlRegex);
31+
const matchWebPubSubPath = envVars.match(webPubSubPathRegex);
3232

33-
if (matchBlog && matchCms) {
34-
const blogValue = matchBlog[1];
35-
const cmsValue = matchCms[1];
36-
const fileContents = readFileSync(filePath, "utf-8");
37-
const newFileContent = fileContents
38-
.replace(blogPlaceholderValue, blogValue)
39-
.replace(cmsPlaceholderValue, cmsValue)
40-
.replace(webPubSubUrlPlaceholderValue, webPubSubUrl)
41-
.replace(webPubSubPathPlaceholderValue, webPubSubPath)
42-
;
43-
44-
writeFileSync(filePath, newFileContent);
45-
} else {
46-
if (!matchBlog) {
47-
console.log(`No match found for ${blogPlaceholderValue}. Skipping replacement.`);
48-
process.exit(1);
49-
}
50-
if (!matchCms) {
51-
console.log(`No match found for ${cmsPlaceholderValue}. Skipping replacement.`);
52-
process.exit(1);
53-
}
33+
if (!matchBlog) {
34+
console.log(`No match found for ${blogPlaceholderValue}. Skipping replacement.`);
35+
process.exit(1);
36+
}
37+
if (!matchCms) {
38+
console.log(`No match found for ${cmsPlaceholderValue}. Skipping replacement.`);
39+
process.exit(1);
40+
}
41+
if (!matchWebPubSubUrl) {
42+
console.log(`No match found for ${webPubSubUrlPlaceholderValue}. Skipping replacement.`);
43+
process.exit(1);
5444
}
45+
if (!matchWebPubSubPath) {
46+
console.log(`No match found for ${webPubSubPathPlaceholderValue}. Skipping replacement.`);
47+
process.exit(1);
48+
}
49+
50+
const blogValue = matchBlog[1];
51+
const cmsValue = matchCms[1];
52+
const webPubSubUrlValue = matchWebPubSubUrl[1];
53+
const webPubSubPathValue = matchWebPubSubPath[1];
54+
const fileContents = readFileSync(filePath, "utf-8");
5555

56+
// Replace the placeholder with the actual value
57+
let newFileContent = fileContents
58+
.replace(blogPlaceholderValue, blogValue)
59+
.replace(cmsPlaceholderValue, cmsValue)
60+
.replace(webPubSubUrlPlaceholderValue, webPubSubUrlValue)
61+
.replace(webPubSubPathPlaceholderValue, webPubSubPathValue);
62+
63+
// Special handling for AI chatbot
5664
const matchAiEnable = envVars.match(aiEnableRegex);
5765
const matchAiChatApi = envVars.match(aiChatApiRegex);
5866
const aiEnableValue = matchAiEnable ? matchAiEnable[1] : false;
59-
const aiChatApiValue = matchAiChatApi ? matchAiChatApi[1] : '';
67+
const aiChatApiValue = matchAiChatApi ? matchAiChatApi[1] : "";
6068
if (matchAiEnable && matchAiChatApi) {
6169
console.log(`AI chatbot is enabled. Chat API URI: ${aiChatApiValue}`);
6270
}
6371

64-
const fileContents = readFileSync(filePath, "utf-8");
65-
const newFileContent = fileContents
72+
newFileContent = newFileContent
6673
.replace(aiEnablePlaceholderValue, aiEnableValue)
6774
.replace(aiChatApiPlaceholderValue, aiChatApiValue);
6875

infra/main.bicep

+28-28
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ param adminJwtSecret string
5050

5151
param cmsDatabaseName string = 'strapi'
5252
param cmsDatabaseUser string = 'strapi'
53-
// param cmsDatabaseServerName string = ''
53+
param cmsDatabaseServerName string = ''
5454
param cmsDatabasePort string = '5432'
5555
@secure()
5656
param cmsDatabasePassword string
@@ -281,7 +281,7 @@ module api './app/api.bicep' = {
281281
STRAPI_DATABASE_NAME: cmsDatabaseName
282282
STRAPI_DATABASE_USERNAME: cmsDatabaseUser
283283
STRAPI_DATABASE_PASSWORD: cmsDatabasePassword
284-
// STRAPI_DATABASE_HOST: cmsDB.outputs.POSTGRES_DOMAIN_NAME
284+
STRAPI_DATABASE_HOST: cmsDB.outputs.POSTGRES_DOMAIN_NAME
285285
STRAPI_DATABASE_PORT: cmsDatabasePort
286286
STRAPI_DATABASE_SSL: 'true'
287287
}
@@ -303,7 +303,7 @@ module cms './app/cms.bicep' = {
303303
applicationInsightsName: monitoring.outputs.applicationInsightsName
304304
containerAppsEnvironmentName: !empty(containerAppsEnvironmentName) ? containerAppsEnvironmentName : '${abbrs.appManagedEnvironments}${resourceToken}'
305305
containerRegistryName: !empty(containerRegistryName) ? containerRegistryName : '${abbrs.containerRegistryRegistries}${resourceToken}'
306-
databaseHost: '' //cmsDB.outputs.POSTGRES_DOMAIN_NAME
306+
databaseHost: cmsDB.outputs.POSTGRES_DOMAIN_NAME
307307
databaseName: cmsDatabaseName
308308
databaseUsername: cmsDatabaseUser
309309
databasePassword: cmsDatabasePassword
@@ -321,28 +321,28 @@ module cms './app/cms.bicep' = {
321321
}
322322

323323
// // The cms database
324-
// module cmsDB './core/database/postgresql/flexibleserver.bicep' = {
325-
// name: 'postgresql'
326-
// scope: rg
327-
// params: {
328-
// name: !empty(cmsDatabaseServerName) ? cmsDatabaseServerName : '${abbrs.dBforPostgreSQLServers}db-${resourceToken}'
329-
// location: location
330-
// tags: tags
331-
// sku: {
332-
// name: 'Standard_B1ms'
333-
// tier: 'Burstable'
334-
// }
335-
// storage: {
336-
// storageSizeGB: 32
337-
// }
338-
// version: '13'
339-
// administratorLogin: cmsDatabaseUser
340-
// administratorLoginPassword: cmsDatabasePassword
341-
// databaseNames: [ cmsDatabaseName ]
342-
// allowAzureIPsFirewall: true
343-
// keyVaultName: keyVault.outputs.name
344-
// }
345-
// }
324+
module cmsDB './core/database/postgresql/flexibleserver.bicep' = {
325+
name: 'postgresql'
326+
scope: rg
327+
params: {
328+
name: !empty(cmsDatabaseServerName) ? cmsDatabaseServerName : '${abbrs.dBforPostgreSQLServers}db-${resourceToken}'
329+
location: location
330+
tags: tags
331+
sku: {
332+
name: 'Standard_B1ms'
333+
tier: 'Burstable'
334+
}
335+
storage: {
336+
storageSizeGB: 32
337+
}
338+
version: '13'
339+
administratorLogin: cmsDatabaseUser
340+
administratorLoginPassword: cmsDatabasePassword
341+
databaseNames: [ cmsDatabaseName ]
342+
allowAzureIPsFirewall: true
343+
keyVaultName: keyVault.outputs.name
344+
}
345+
}
346346

347347
/////////// Blog ///////////
348348

@@ -427,14 +427,14 @@ output SERVICE_STRIPE_NAME string = stripe.outputs.SERVICE_STRIPE_NAME
427427

428428
output STORAGE_ACCOUNT_NAME string = storageAccount.outputs.name
429429
output STORAGE_CONTAINER_NAME string = storageContainerName
430-
// output SERVICE_CMS_SERVER_HOST string = cmsDB.outputs.POSTGRES_DOMAIN_NAME
430+
output SERVICE_CMS_SERVER_HOST string = cmsDB.outputs.POSTGRES_DOMAIN_NAME
431431

432432
output STRAPI_DATABASE_NAME string = cmsDatabaseName
433433
output STRAPI_DATABASE_USERNAME string = cmsDatabaseUser
434-
// output STRAPI_DATABASE_HOST string = cmsDB.outputs.POSTGRES_DOMAIN_NAME
434+
output STRAPI_DATABASE_HOST string = cmsDB.outputs.POSTGRES_DOMAIN_NAME
435435
output STRAPI_DATABASE_PORT string = cmsDatabasePort
436436

437-
// output CMS_DATABASE_SERVER_NAME string = cmsDB.outputs.POSTGRES_SERVER_NAME
437+
output CMS_DATABASE_SERVER_NAME string = cmsDB.outputs.POSTGRES_SERVER_NAME
438438
// We need this to manually restore the database
439439
output STRAPI_DATABASE_PASSWORD string = cmsDatabasePassword
440440

packages/portal/angular.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
{
4040
"type": "initial",
4141
"maximumWarning": "900kb",
42-
"maximumError": "1mb"
42+
"maximumError": "2mb"
4343
},
4444
{
4545
"type": "anyComponentStyle",

0 commit comments

Comments
 (0)