Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve deployments #450

Merged
merged 1 commit into from Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions infra/hooks/portal/.eslintrc
@@ -0,0 +1,7 @@
{
"env": {
"node": true,
"commonjs": true
},
"extends": "eslint:recommended"
}
61 changes: 34 additions & 27 deletions infra/hooks/portal/predeploy.js
Expand Up @@ -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="([^"]+)"/;
Expand All @@ -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);

Expand Down
56 changes: 28 additions & 28 deletions infra/main.bicep
Expand Up @@ -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
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why it returning unbound var? It was commented out...?

STRAPI_DATABASE_HOST: cmsDB.outputs.POSTGRES_DOMAIN_NAME
STRAPI_DATABASE_PORT: cmsDatabasePort
STRAPI_DATABASE_SSL: 'true'
}
Expand All @@ -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
Expand All @@ -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 ///////////

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion packages/portal/angular.json
Expand Up @@ -39,7 +39,7 @@
{
"type": "initial",
"maximumWarning": "900kb",
"maximumError": "1mb"
"maximumError": "2mb"
},
{
"type": "anyComponentStyle",
Expand Down