Skip to content

Commit

Permalink
Add Gatsby Cloud-related webhooks to Enhanced Autobuilder (#892)
Browse files Browse the repository at this point in the history
  • Loading branch information
rayangler authored Aug 24, 2023
1 parent ac38913 commit 6cff3a4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion api/controllers/v2/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<APIGatewayProxyResult> => {
const consoleLogger = new ConsoleLogger();
Expand Down Expand Up @@ -170,3 +170,5 @@ async function NotifyBuildProgress(jobId: string): Promise<void> {
entitlement['slack_user_id']
);
}

export const SnootyBuildComplete = snootyBuildComplete;
29 changes: 29 additions & 0 deletions cdk-infra/lib/constructs/api/webhook-api-construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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!!"); }'),
Expand All @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit 6cff3a4

Please sign in to comment.