Pass auction id in deployment requests
This commit is contained in:
parent
f445d0b956
commit
a7e3936d7f
@ -269,7 +269,7 @@ export class Registry {
|
|||||||
appName: string,
|
appName: string,
|
||||||
repository: string,
|
repository: string,
|
||||||
auctionId?: string,
|
auctionId?: string,
|
||||||
lrn?: string,
|
lrn: string,
|
||||||
environmentVariables: { [key: string]: string },
|
environmentVariables: { [key: string]: string },
|
||||||
dns: string,
|
dns: string,
|
||||||
}): Promise<{
|
}): Promise<{
|
||||||
@ -304,7 +304,7 @@ export class Registry {
|
|||||||
repository: data.repository,
|
repository: data.repository,
|
||||||
repository_ref: data.deployment.commitHash
|
repository_ref: data.deployment.commitHash
|
||||||
}),
|
}),
|
||||||
...(data.lrn && { deployer: data.lrn }),
|
deployer: data.lrn,
|
||||||
...(data.auctionId && { auction: data.auctionId }),
|
...(data.auctionId && { auction: data.auctionId }),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -287,7 +287,15 @@ export class Service {
|
|||||||
);
|
);
|
||||||
|
|
||||||
for (const project of projectsToBedeployed) {
|
for (const project of projectsToBedeployed) {
|
||||||
await this.createDeploymentFromAuction(project);
|
const deployerLrns = await this.registry.getAuctionWinners(project!.auctionId!);
|
||||||
|
|
||||||
|
// Update project with deployer LRNs
|
||||||
|
await this.db.updateProjectById(project.id!, {
|
||||||
|
deployerLrn: deployerLrns
|
||||||
|
})
|
||||||
|
for (const deployer of deployerLrns) {
|
||||||
|
await this.createDeploymentFromAuction(project, deployer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -660,6 +668,7 @@ export class Service {
|
|||||||
repository: repoUrl,
|
repository: repoUrl,
|
||||||
environmentVariables: environmentVariablesObj,
|
environmentVariables: environmentVariablesObj,
|
||||||
dns: `${newDeployment.project.name}`,
|
dns: `${newDeployment.project.name}`,
|
||||||
|
lrn
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -688,13 +697,8 @@ export class Service {
|
|||||||
|
|
||||||
async createDeploymentFromAuction(
|
async createDeploymentFromAuction(
|
||||||
project: DeepPartial<Project>,
|
project: DeepPartial<Project>,
|
||||||
) {
|
deployer: string
|
||||||
// Update project with deployer LRNs
|
): Promise<Deployment> {
|
||||||
const deployerLrns = await this.registry.getAuctionWinners(project!.auctionId!);
|
|
||||||
await this.db.updateProjectById(project.id!, {
|
|
||||||
deployerLrn: deployerLrns
|
|
||||||
})
|
|
||||||
|
|
||||||
const octokit = await this.getOctokit(project.ownerId!);
|
const octokit = await this.getOctokit(project.ownerId!);
|
||||||
const [owner, repo] = project.repository!.split('/');
|
const [owner, repo] = project.repository!.split('/');
|
||||||
|
|
||||||
@ -719,80 +723,82 @@ export class Service {
|
|||||||
const applicationRecordId = record.id;
|
const applicationRecordId = record.id;
|
||||||
const applicationRecordData = record.attributes;
|
const applicationRecordData = record.attributes;
|
||||||
|
|
||||||
for (const deployer of deployerLrns) {
|
// Create deployment with prod branch and latest commit
|
||||||
// Create deployment with prod branch and latest commit
|
const deploymentData = {
|
||||||
const deploymentData = {
|
project,
|
||||||
project,
|
branch: project.prodBranch,
|
||||||
branch: project.prodBranch,
|
environment: Environment.Production,
|
||||||
environment: Environment.Production,
|
domain: null,
|
||||||
domain: null,
|
commitHash: latestCommit.sha,
|
||||||
commitHash: latestCommit.sha,
|
commitMessage: latestCommit.commit.message,
|
||||||
commitMessage: latestCommit.commit.message,
|
};
|
||||||
};
|
|
||||||
|
|
||||||
const newDeployment = await this.db.addDeployment({
|
const newDeployment = await this.db.addDeployment({
|
||||||
project: project,
|
project: project,
|
||||||
branch: deploymentData.branch,
|
branch: deploymentData.branch,
|
||||||
commitHash: deploymentData.commitHash,
|
commitHash: deploymentData.commitHash,
|
||||||
commitMessage: deploymentData.commitMessage,
|
commitMessage: deploymentData.commitMessage,
|
||||||
environment: deploymentData.environment,
|
environment: deploymentData.environment,
|
||||||
status: DeploymentStatus.Building,
|
status: DeploymentStatus.Building,
|
||||||
applicationRecordId,
|
applicationRecordId,
|
||||||
applicationRecordData,
|
applicationRecordData,
|
||||||
domain: deploymentData.domain,
|
domain: deploymentData.domain,
|
||||||
createdBy: Object.assign(new User(), {
|
createdBy: Object.assign(new User(), {
|
||||||
id: project.ownerId!,
|
id: project.ownerId!,
|
||||||
}),
|
}),
|
||||||
|
deployerLrn: deployer
|
||||||
|
});
|
||||||
|
|
||||||
|
log(
|
||||||
|
`Created deployment ${newDeployment.id} and published application record ${applicationRecordId}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const environmentVariables =
|
||||||
|
await this.db.getEnvironmentVariablesByProjectId(project!.id!, {
|
||||||
|
environment: Environment.Production,
|
||||||
});
|
});
|
||||||
|
|
||||||
log(
|
const environmentVariablesObj = environmentVariables.reduce(
|
||||||
`Created deployment ${newDeployment.id} and published application record ${applicationRecordId}`,
|
(acc, env) => {
|
||||||
);
|
acc[env.key] = env.value;
|
||||||
|
|
||||||
const environmentVariables =
|
return acc;
|
||||||
await this.db.getEnvironmentVariablesByProjectId(project!.id!, {
|
},
|
||||||
environment: Environment.Production,
|
{} as { [key: string]: string },
|
||||||
});
|
);
|
||||||
|
|
||||||
const environmentVariablesObj = environmentVariables.reduce(
|
// To set project DNS
|
||||||
(acc, env) => {
|
if (deploymentData.environment === Environment.Production) {
|
||||||
acc[env.key] = env.value;
|
// On deleting deployment later, project DNS deployment is also deleted
|
||||||
|
// So publish project DNS deployment first so that ApplicationDeploymentRecord for the same is available when deleting deployment later
|
||||||
return acc;
|
await this.registry.createApplicationDeploymentRequest({
|
||||||
},
|
deployment: newDeployment,
|
||||||
{} as { [key: string]: string },
|
appName: repo,
|
||||||
);
|
repository: repoUrl,
|
||||||
|
environmentVariables: environmentVariablesObj,
|
||||||
// To set project DNS
|
dns: `${newDeployment.project.name}`,
|
||||||
if (deploymentData.environment === Environment.Production) {
|
lrn
|
||||||
// On deleting deployment later, project DNS deployment is also deleted
|
|
||||||
// So publish project DNS deployment first so that ApplicationDeploymentRecord for the same is available when deleting deployment later
|
|
||||||
await this.registry.createApplicationDeploymentRequest({
|
|
||||||
deployment: newDeployment,
|
|
||||||
appName: repo,
|
|
||||||
repository: repoUrl,
|
|
||||||
environmentVariables: environmentVariablesObj,
|
|
||||||
dns: `${newDeployment.project.name}`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const { applicationDeploymentRequestId, applicationDeploymentRequestData } =
|
|
||||||
// Create requests for all the deployers
|
|
||||||
await this.registry.createApplicationDeploymentRequest({
|
|
||||||
deployment: newDeployment,
|
|
||||||
appName: repo,
|
|
||||||
repository: repoUrl,
|
|
||||||
auctionId: project.auctionId!,
|
|
||||||
lrn: deployer,
|
|
||||||
environmentVariables: environmentVariablesObj,
|
|
||||||
dns: `${newDeployment.project.name}-${newDeployment.id}`,
|
|
||||||
});
|
|
||||||
|
|
||||||
await this.db.updateDeploymentById(newDeployment.id, {
|
|
||||||
applicationDeploymentRequestId,
|
|
||||||
applicationDeploymentRequestData,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { applicationDeploymentRequestId, applicationDeploymentRequestData } =
|
||||||
|
// Create requests for all the deployers
|
||||||
|
await this.registry.createApplicationDeploymentRequest({
|
||||||
|
deployment: newDeployment,
|
||||||
|
appName: repo,
|
||||||
|
repository: repoUrl,
|
||||||
|
auctionId: project.auctionId!,
|
||||||
|
lrn: deployer,
|
||||||
|
environmentVariables: environmentVariablesObj,
|
||||||
|
dns: `${newDeployment.project.name}-${newDeployment.id}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.db.updateDeploymentById(newDeployment.id, {
|
||||||
|
applicationDeploymentRequestId,
|
||||||
|
applicationDeploymentRequestData,
|
||||||
|
});
|
||||||
|
|
||||||
|
return newDeployment;
|
||||||
}
|
}
|
||||||
|
|
||||||
async addProjectFromTemplate(
|
async addProjectFromTemplate(
|
||||||
@ -972,9 +978,9 @@ export class Service {
|
|||||||
project,
|
project,
|
||||||
branch,
|
branch,
|
||||||
environment:
|
environment:
|
||||||
project.prodBranch === branch
|
project.prodBranch === branch
|
||||||
? Environment.Production
|
? Environment.Production
|
||||||
: Environment.Preview,
|
: Environment.Preview,
|
||||||
domain,
|
domain,
|
||||||
commitHash: headCommit.id,
|
commitHash: headCommit.id,
|
||||||
commitMessage: headCommit.message,
|
commitMessage: headCommit.message,
|
||||||
@ -1032,15 +1038,24 @@ export class Service {
|
|||||||
|
|
||||||
const octokit = await this.getOctokit(user.id);
|
const octokit = await this.getOctokit(user.id);
|
||||||
|
|
||||||
const newDeployment = await this.createDeployment(user.id, octokit, {
|
let newDeployment: Deployment;
|
||||||
project: oldDeployment.project,
|
|
||||||
// TODO: Put isCurrent field in project
|
if (oldDeployment.project.auctionId) {
|
||||||
branch: oldDeployment.branch,
|
newDeployment = await this.createDeploymentFromAuction(oldDeployment.project, oldDeployment.deployerLrn);
|
||||||
environment: Environment.Production,
|
} else {
|
||||||
domain: oldDeployment.domain,
|
newDeployment = await this.createDeployment(user.id, octokit,
|
||||||
commitHash: oldDeployment.commitHash,
|
{
|
||||||
commitMessage: oldDeployment.commitMessage,
|
project: oldDeployment.project,
|
||||||
}, oldDeployment.deployerLrn);
|
// TODO: Put isCurrent field in project
|
||||||
|
branch: oldDeployment.branch,
|
||||||
|
environment: Environment.Production,
|
||||||
|
domain: oldDeployment.domain,
|
||||||
|
commitHash: oldDeployment.commitHash,
|
||||||
|
commitMessage: oldDeployment.commitMessage,
|
||||||
|
},
|
||||||
|
oldDeployment.deployerLrn
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return newDeployment;
|
return newDeployment;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user