forked from cerc-io/snowballtools-base
Use environment variables from DB in published record data (#70)
* Publish environment variables of deployment * Handle review changes * Use dummy gray image for projects --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
@@ -36,7 +36,7 @@
|
||||
"lint": "eslint .",
|
||||
"format": "prettier --write .",
|
||||
"format:check": "prettier --check .",
|
||||
"registry:init": "DEBUG=snowball:* ts-node scripts/initialize-registry.ts",
|
||||
"registry:init": "DEBUG=snowball:* ts-node ./test/initialize-registry.ts",
|
||||
"db:load:fixtures": "DEBUG=snowball:* ts-node ./test/initialize-db.ts",
|
||||
"db:delete": "DEBUG=snowball:* ts-node ./test/delete-db.ts"
|
||||
},
|
||||
|
||||
@@ -196,14 +196,15 @@ export class Database {
|
||||
return projectMembers;
|
||||
}
|
||||
|
||||
async getEnvironmentVariablesByProjectId (projectId: string): Promise<EnvironmentVariable[]> {
|
||||
async getEnvironmentVariablesByProjectId (projectId: string, filter?: FindOptionsWhere<EnvironmentVariable>): Promise<EnvironmentVariable[]> {
|
||||
const environmentVariableRepository = this.dataSource.getRepository(EnvironmentVariable);
|
||||
|
||||
const environmentVariables = await environmentVariableRepository.find({
|
||||
where: {
|
||||
project: {
|
||||
id: projectId
|
||||
}
|
||||
},
|
||||
...filter
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -92,7 +92,8 @@ export class Registry {
|
||||
async createApplicationDeploymentRequest (data: {
|
||||
appName: string,
|
||||
commitHash: string,
|
||||
repository: string
|
||||
repository: string,
|
||||
environmentVariables: { [key: string]: string }
|
||||
}): Promise<{
|
||||
registryRecordId: string,
|
||||
registryRecordData: ApplicationDeploymentRequest
|
||||
@@ -118,9 +119,7 @@ export class Registry {
|
||||
|
||||
// https://git.vdb.to/cerc-io/laconic-registry-cli/commit/129019105dfb93bebcea02fde0ed64d0f8e5983b
|
||||
config: JSON.stringify({
|
||||
env: {
|
||||
CERC_WEBAPP_DEBUG: `${applicationRecord.attributes.app_version}`
|
||||
}
|
||||
env: data.environmentVariables
|
||||
}),
|
||||
meta: JSON.stringify({
|
||||
note: `Added by Snowball @ ${DateTime.utc().toFormat('EEE LLL dd HH:mm:ss \'UTC\' yyyy')}`,
|
||||
|
||||
@@ -231,6 +231,7 @@ export class Service {
|
||||
recordData.repoUrl = repoDetails.html_url;
|
||||
}
|
||||
|
||||
// TODO: Set environment variables for each deployment (environment variables can`t be set in application record)
|
||||
const { registryRecordId, registryRecordData } = await this.registry.createApplicationRecord({
|
||||
packageJSON,
|
||||
appType: data.project!.template!,
|
||||
@@ -318,12 +319,22 @@ export class Service {
|
||||
}
|
||||
);
|
||||
|
||||
const environmentVariables = await this.db.getEnvironmentVariablesByProjectId(project.id, { environment: Environment.Production });
|
||||
|
||||
const environmentVariablesObj = environmentVariables.reduce((acc, env) => {
|
||||
acc[env.key] = env.value;
|
||||
|
||||
return acc;
|
||||
}, {} as { [key: string]: string });
|
||||
|
||||
const { registryRecordId, registryRecordData } = await this.registry.createApplicationDeploymentRequest(
|
||||
{
|
||||
appName: newDeployment.registryRecordData.name!,
|
||||
commitHash: latestCommit.sha,
|
||||
repository: repoDetails.html_url
|
||||
repository: repoDetails.html_url,
|
||||
environmentVariables: environmentVariablesObj
|
||||
});
|
||||
|
||||
await this.db.updateProjectById(project.id, {
|
||||
registryRecordId,
|
||||
registryRecordData
|
||||
@@ -351,7 +362,8 @@ export class Service {
|
||||
if (
|
||||
!(err instanceof RequestError &&
|
||||
err.status === 422 &&
|
||||
(err.response?.data as any).errors.some((err: any) => err.message === GITHUB_UNIQUE_WEBHOOK_ERROR))) {
|
||||
(err.response?.data as any).errors.some((err: any) => err.message === GITHUB_UNIQUE_WEBHOOK_ERROR))
|
||||
) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user