From 0ded077c45357860632ffdffa72cc4ea660d8c0d Mon Sep 17 00:00:00 2001 From: Wassim Chegham Date: Fri, 8 Mar 2024 12:19:15 +0100 Subject: [PATCH] chore: improve deployments --- infra/hooks/portal/.eslintrc | 7 ++++ infra/hooks/portal/predeploy.js | 61 ++++++++++++++++++--------------- infra/main.bicep | 56 +++++++++++++++--------------- packages/portal/angular.json | 2 +- 4 files changed, 70 insertions(+), 56 deletions(-) create mode 100644 infra/hooks/portal/.eslintrc diff --git a/infra/hooks/portal/.eslintrc b/infra/hooks/portal/.eslintrc new file mode 100644 index 00000000..7d6dfc22 --- /dev/null +++ b/infra/hooks/portal/.eslintrc @@ -0,0 +1,7 @@ +{ + "env": { + "node": true, + "commonjs": true + }, + "extends": "eslint:recommended" +} diff --git a/infra/hooks/portal/predeploy.js b/infra/hooks/portal/predeploy.js index 4c4f98be..e5c91d96 100755 --- a/infra/hooks/portal/predeploy.js +++ b/infra/hooks/portal/predeploy.js @@ -13,7 +13,7 @@ const blogPlaceholderValue = "{{SERVICE_BLOG_URI_PLACEHOLDER}}"; const cmsRegex = /SERVICE_CMS_URI="([^"]+)"/; const cmsPlaceholderValue = "{{SERVICE_CMS_URI_PLACEHOLDER}}"; const aiEnableRegex = /AI_ENABLE_CHAT="([^"]+)"/; -const aiEnablePlaceholderValue = "\"{{AI_ENABLE_CHAT_PLACEHOLDER}}\""; +const aiEnablePlaceholderValue = '"{{AI_ENABLE_CHAT_PLACEHOLDER}}"'; const aiChatApiRegex = /AI_CHAT_API_URI="([^"]+)"/; const aiChatApiPlaceholderValue = "{{AI_CHAT_API_URI_PLACEHOLDER}}"; const webPubSubUrlRegex = /SERVICE_WEB_PUB_SUB_URL="([^"]+)"/; @@ -27,42 +27,49 @@ const distPath = resolve(__dirname, "../../../packages/portal/dist/contoso-app") function replaceEnvURIs(filePath) { const matchBlog = envVars.match(blogRegex); const matchCms = envVars.match(cmsRegex); - const webPubSubUrl = envVars.match(webPubSubUrlRegex); - const webPubSubPath = envVars.match(webPubSubPathRegex); + const matchWebPubSubUrl = envVars.match(webPubSubUrlRegex); + const matchWebPubSubPath = envVars.match(webPubSubPathRegex); - if (matchBlog && matchCms) { - const blogValue = matchBlog[1]; - const cmsValue = matchCms[1]; - const fileContents = readFileSync(filePath, "utf-8"); - const newFileContent = fileContents - .replace(blogPlaceholderValue, blogValue) - .replace(cmsPlaceholderValue, cmsValue) - .replace(webPubSubUrlPlaceholderValue, webPubSubUrl) - .replace(webPubSubPathPlaceholderValue, webPubSubPath) - ; - - writeFileSync(filePath, newFileContent); - } else { - if (!matchBlog) { - console.log(`No match found for ${blogPlaceholderValue}. Skipping replacement.`); - process.exit(1); - } - if (!matchCms) { - console.log(`No match found for ${cmsPlaceholderValue}. Skipping replacement.`); - process.exit(1); - } + if (!matchBlog) { + console.log(`No match found for ${blogPlaceholderValue}. Skipping replacement.`); + process.exit(1); + } + if (!matchCms) { + console.log(`No match found for ${cmsPlaceholderValue}. Skipping replacement.`); + process.exit(1); + } + if (!matchWebPubSubUrl) { + console.log(`No match found for ${webPubSubUrlPlaceholderValue}. Skipping replacement.`); + process.exit(1); } + if (!matchWebPubSubPath) { + console.log(`No match found for ${webPubSubPathPlaceholderValue}. Skipping replacement.`); + process.exit(1); + } + + const blogValue = matchBlog[1]; + const cmsValue = matchCms[1]; + const webPubSubUrlValue = matchWebPubSubUrl[1]; + const webPubSubPathValue = matchWebPubSubPath[1]; + const fileContents = readFileSync(filePath, "utf-8"); + // Replace the placeholder with the actual value + let newFileContent = fileContents + .replace(blogPlaceholderValue, blogValue) + .replace(cmsPlaceholderValue, cmsValue) + .replace(webPubSubUrlPlaceholderValue, webPubSubUrlValue) + .replace(webPubSubPathPlaceholderValue, webPubSubPathValue); + + // Special handling for AI chatbot const matchAiEnable = envVars.match(aiEnableRegex); const matchAiChatApi = envVars.match(aiChatApiRegex); const aiEnableValue = matchAiEnable ? matchAiEnable[1] : false; - const aiChatApiValue = matchAiChatApi ? matchAiChatApi[1] : ''; + const aiChatApiValue = matchAiChatApi ? matchAiChatApi[1] : ""; if (matchAiEnable && matchAiChatApi) { console.log(`AI chatbot is enabled. Chat API URI: ${aiChatApiValue}`); } - const fileContents = readFileSync(filePath, "utf-8"); - const newFileContent = fileContents + newFileContent = newFileContent .replace(aiEnablePlaceholderValue, aiEnableValue) .replace(aiChatApiPlaceholderValue, aiChatApiValue); diff --git a/infra/main.bicep b/infra/main.bicep index 06ff0d39..c00989a7 100644 --- a/infra/main.bicep +++ b/infra/main.bicep @@ -50,7 +50,7 @@ param adminJwtSecret string param cmsDatabaseName string = 'strapi' param cmsDatabaseUser string = 'strapi' -// param cmsDatabaseServerName string = '' +param cmsDatabaseServerName string = '' param cmsDatabasePort string = '5432' @secure() param cmsDatabasePassword string @@ -281,7 +281,7 @@ module api './app/api.bicep' = { STRAPI_DATABASE_NAME: cmsDatabaseName STRAPI_DATABASE_USERNAME: cmsDatabaseUser STRAPI_DATABASE_PASSWORD: cmsDatabasePassword - // STRAPI_DATABASE_HOST: cmsDB.outputs.POSTGRES_DOMAIN_NAME + STRAPI_DATABASE_HOST: cmsDB.outputs.POSTGRES_DOMAIN_NAME STRAPI_DATABASE_PORT: cmsDatabasePort STRAPI_DATABASE_SSL: 'true' } @@ -303,7 +303,7 @@ module cms './app/cms.bicep' = { applicationInsightsName: monitoring.outputs.applicationInsightsName containerAppsEnvironmentName: !empty(containerAppsEnvironmentName) ? containerAppsEnvironmentName : '${abbrs.appManagedEnvironments}${resourceToken}' containerRegistryName: !empty(containerRegistryName) ? containerRegistryName : '${abbrs.containerRegistryRegistries}${resourceToken}' - databaseHost: '' //cmsDB.outputs.POSTGRES_DOMAIN_NAME + databaseHost: cmsDB.outputs.POSTGRES_DOMAIN_NAME databaseName: cmsDatabaseName databaseUsername: cmsDatabaseUser databasePassword: cmsDatabasePassword @@ -321,28 +321,28 @@ module cms './app/cms.bicep' = { } // // The cms database -// module cmsDB './core/database/postgresql/flexibleserver.bicep' = { -// name: 'postgresql' -// scope: rg -// params: { -// name: !empty(cmsDatabaseServerName) ? cmsDatabaseServerName : '${abbrs.dBforPostgreSQLServers}db-${resourceToken}' -// location: location -// tags: tags -// sku: { -// name: 'Standard_B1ms' -// tier: 'Burstable' -// } -// storage: { -// storageSizeGB: 32 -// } -// version: '13' -// administratorLogin: cmsDatabaseUser -// administratorLoginPassword: cmsDatabasePassword -// databaseNames: [ cmsDatabaseName ] -// allowAzureIPsFirewall: true -// keyVaultName: keyVault.outputs.name -// } -// } +module cmsDB './core/database/postgresql/flexibleserver.bicep' = { + name: 'postgresql' + scope: rg + params: { + name: !empty(cmsDatabaseServerName) ? cmsDatabaseServerName : '${abbrs.dBforPostgreSQLServers}db-${resourceToken}' + location: location + tags: tags + sku: { + name: 'Standard_B1ms' + tier: 'Burstable' + } + storage: { + storageSizeGB: 32 + } + version: '13' + administratorLogin: cmsDatabaseUser + administratorLoginPassword: cmsDatabasePassword + databaseNames: [ cmsDatabaseName ] + allowAzureIPsFirewall: true + keyVaultName: keyVault.outputs.name + } +} /////////// Blog /////////// @@ -427,14 +427,14 @@ output SERVICE_STRIPE_NAME string = stripe.outputs.SERVICE_STRIPE_NAME output STORAGE_ACCOUNT_NAME string = storageAccount.outputs.name output STORAGE_CONTAINER_NAME string = storageContainerName -// output SERVICE_CMS_SERVER_HOST string = cmsDB.outputs.POSTGRES_DOMAIN_NAME +output SERVICE_CMS_SERVER_HOST string = cmsDB.outputs.POSTGRES_DOMAIN_NAME output STRAPI_DATABASE_NAME string = cmsDatabaseName output STRAPI_DATABASE_USERNAME string = cmsDatabaseUser -// output STRAPI_DATABASE_HOST string = cmsDB.outputs.POSTGRES_DOMAIN_NAME +output STRAPI_DATABASE_HOST string = cmsDB.outputs.POSTGRES_DOMAIN_NAME output STRAPI_DATABASE_PORT string = cmsDatabasePort -// output CMS_DATABASE_SERVER_NAME string = cmsDB.outputs.POSTGRES_SERVER_NAME +output CMS_DATABASE_SERVER_NAME string = cmsDB.outputs.POSTGRES_SERVER_NAME // We need this to manually restore the database output STRAPI_DATABASE_PASSWORD string = cmsDatabasePassword diff --git a/packages/portal/angular.json b/packages/portal/angular.json index d0cb6588..d12286a6 100644 --- a/packages/portal/angular.json +++ b/packages/portal/angular.json @@ -39,7 +39,7 @@ { "type": "initial", "maximumWarning": "900kb", - "maximumError": "1mb" + "maximumError": "2mb" }, { "type": "anyComponentStyle",