From 6cff3a43dc5b13bbd7fb4720a299a5c3d4990f3c Mon Sep 17 00:00:00 2001 From: rayangler <27821750+rayangler@users.noreply.github.com> Date: Thu, 24 Aug 2023 13:26:37 -0400 Subject: [PATCH] Add Gatsby Cloud-related webhooks to Enhanced Autobuilder (#892) --- api/controllers/v2/jobs.ts | 4 ++- .../constructs/api/webhook-api-construct.ts | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/api/controllers/v2/jobs.ts b/api/controllers/v2/jobs.ts index 7f1cbff23..d6d56a741 100644 --- a/api/controllers/v2/jobs.ts +++ b/api/controllers/v2/jobs.ts @@ -9,7 +9,7 @@ import { JobStatus } from '../../../src/entities/job'; import { ECSContainer } from '../../../src/services/containerServices'; import { SQSConnector } from '../../../src/services/queue'; import { APIGatewayEvent, APIGatewayProxyResult, SQSEvent, SQSRecord } from 'aws-lambda'; -import { notifyBuildSummary } from '../../handlers/jobs'; +import { notifyBuildSummary, snootyBuildComplete } from '../../handlers/jobs'; export const TriggerLocalBuild = async (event: APIGatewayEvent): Promise => { const consoleLogger = new ConsoleLogger(); @@ -170,3 +170,5 @@ async function NotifyBuildProgress(jobId: string): Promise { entitlement['slack_user_id'] ); } + +export const SnootyBuildComplete = snootyBuildComplete; diff --git a/cdk-infra/lib/constructs/api/webhook-api-construct.ts b/cdk-infra/lib/constructs/api/webhook-api-construct.ts index f2f792de4..bbfaf33f1 100644 --- a/cdk-infra/lib/constructs/api/webhook-api-construct.ts +++ b/cdk-infra/lib/constructs/api/webhook-api-construct.ts @@ -74,6 +74,15 @@ export class WebhookApiConstruct extends Construct { timeout, }); + const githubDeleteArtifactsLambda = new NodejsFunction(this, 'githubDeleteArtifactsLambda', { + entry: `${HANDLERS_PATH}/github.ts`, + runtime, + handler: 'MarkBuildArtifactsForDeletion', + bundling, + environment, + timeout, + }); + const triggerLocalBuildLambda = new NodejsFunction(this, 'triggerLocalBuildLambda', { entry: `${HANDLERS_PATH}/jobs.ts`, runtime, @@ -92,6 +101,15 @@ export class WebhookApiConstruct extends Construct { timeout, }); + const snootyBuildCompleteLambda = new NodejsFunction(this, 'snootyBuildCompleteLambda', { + entry: `${HANDLERS_PATH}/jobs.ts`, + runtime, + handler: 'SnootyBuildComplete', + environment, + bundling, + timeout, + }); + // generic handler for the root endpoint const rootEndpointLambda = new Function(this, 'RootEndpointLambda', { code: Code.fromInline('exports.default = (event) => { console.log("hello, world!!"); }'), @@ -113,6 +131,7 @@ export class WebhookApiConstruct extends Construct { const dochubEndpoint = webhookEndpoint.addResource('dochub'); const githubEndpoint = webhookEndpoint.addResource('githubEndpoint'); const localEndpoint = webhookEndpoint.addResource('local'); + const snootyEndpoint = webhookEndpoint.addResource('snooty'); const defaultCorsPreflightOptions: CorsOptions = { allowOrigins: Cors.ALL_ORIGINS, @@ -139,11 +158,21 @@ export class WebhookApiConstruct extends Construct { .addResource('build', { defaultCorsPreflightOptions }) .addMethod('POST', new LambdaIntegration(githubTriggerLambda)); + githubEndpoint + .addResource('trigger') + .addResource('delete', { defaultCorsPreflightOptions }) + .addMethod('POST', new LambdaIntegration(githubDeleteArtifactsLambda)); + localEndpoint .addResource('trigger') .addResource('build', { defaultCorsPreflightOptions }) .addMethod('POST', new LambdaIntegration(triggerLocalBuildLambda)); + snootyEndpoint + .addResource('trigger') + .addResource('complete', { defaultCorsPreflightOptions }) + .addMethod('POST', new LambdaIntegration(snootyBuildCompleteLambda)); + // grant permission for lambdas to enqueue messages to the jobs queue jobsQueue.grantSendMessages(slackTriggerLambda); jobsQueue.grantSendMessages(githubTriggerLambda);