@catladder/cli
Version:
Panter cli tool for cloud CI/CD and DevOps
91 lines • 4.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GCLOUD_RUN_DEPLOY_TYPE = exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX = exports.GCLOUD_DEPLOY_CREDENTIALS_KEY = void 0;
const BashExpression_1 = require("../../bash/BashExpression");
const context_1 = require("../../context");
const gitlab_1 = require("../../utils/gitlab");
const utils_1 = require("../cloudSql/utils");
const createJobs_1 = require("./createJobs");
const cloudRunExecutionUrl_1 = require("./utils/cloudRunExecutionUrl");
const database_1 = require("./utils/database");
exports.GCLOUD_DEPLOY_CREDENTIALS_KEY = "GCLOUD_DEPLOY_credentialsKey";
// FIXME: rename to internalHostSuffix, but this means that project-setup needs to be rerun, so its kindof a breaking change
exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX = "GCLOUD_RUN_canonicalHostSuffix";
const getCloudSqlVariables = ({ deployConfigRaw, environmentSlugPrefix, env, componentName, fullConfig, }) => {
var _a, _b, _c;
if (deployConfigRaw && deployConfigRaw.cloudSql) {
const DB_NAME = (0, utils_1.getFullDbName)(deployConfigRaw.cloudSql, fullConfig, environmentSlugPrefix, componentName);
const additionalQueryParamsString = Object.entries((_a = deployConfigRaw.cloudSql.dbAdditionalQueryParams) !== null && _a !== void 0 ? _a : {})
.map(([key, value]) => `&${key}=${value}`)
.join("");
const dbVars = {
CLOUD_SQL_INSTANCE_CONNECTION_NAME: deployConfigRaw.cloudSql.instanceConnectionName,
DB_NAME: DB_NAME,
DB_USER: (_b = deployConfigRaw.cloudSql.dbUser) !== null && _b !== void 0 ? _b : "postgres",
DB_PASSWORD: "$" + (0, context_1.getSecretVarName)(env, componentName, "DB_PASSWORD"),
};
return {
...dbVars,
DATABASE_URL: (0, database_1.getDatabaseConnectionString)(deployConfigRaw.cloudSql, dbVars).concat(additionalQueryParamsString),
DATABASE_JDBC_URL: (0, database_1.getDatabaseJdbcUrl)(dbVars, (_c = deployConfigRaw.cloudSql.dbConnectionStringVariablesMode) !== null && _c !== void 0 ? _c : database_1.DEFAULT_DB_VARIABLES_MODE),
};
}
return {};
};
exports.GCLOUD_RUN_DEPLOY_TYPE = {
jobs: createJobs_1.createGoogleCloudRunDeployJobs,
defaults: ({ deployConfigRaw, envType }) => {
if (deployConfigRaw && deployConfigRaw.cloudSql) {
return {
cloudSql: {
deleteDatabaseOnStop: envType === "review",
},
};
}
return {};
},
additionalSecretKeys: (ctx) => [
{
key: exports.GCLOUD_DEPLOY_CREDENTIALS_KEY,
hidden: true,
},
{
key: exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX,
hidden: true,
},
...(ctx.deployConfigRaw && ctx.deployConfigRaw.cloudSql
? [{ key: "DB_PASSWORD" }]
: []),
],
getAdditionalEnvVars: (ctx) => {
const { fullName, env, componentName, deployConfigRaw } = ctx;
const HOSTNAME_INTERNAL = (0, BashExpression_1.joinBashExpressions)([
fullName,
(0, BashExpression_1.getBashVariable)((0, context_1.getSecretVarName)(env, componentName, exports.GCLOUD_RUN_CANONICAL_HOST_SUFFIX)),
], "-").toLowerCase();
const jobTriggers = deployConfigRaw && deployConfigRaw.jobs
? Object.fromEntries(Object.entries(deployConfigRaw.jobs)
.filter(([name, job]) => Boolean(job))
.map(([name, job]) => [
"CLOUD_RUN_JOB_TRIGGER_URL_" + (0, gitlab_1.sanitizeForBashVariable)(name),
(0, cloudRunExecutionUrl_1.getCloudRunJobExecuteUrl)(name, {
appFullName: fullName,
projectId: deployConfigRaw.projectId,
region: deployConfigRaw.region,
}),
]))
: {};
return {
HOSTNAME_INTERNAL,
...getCloudSqlVariables(ctx),
...jobTriggers,
DEPLOY_CLOUD_RUN_PROJECT_ID: deployConfigRaw
? deployConfigRaw.projectId
: undefined,
DEPLOY_CLOUD_RUN_REGION: deployConfigRaw
? deployConfigRaw.region
: undefined,
};
},
};
//# sourceMappingURL=index.js.map