Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mats16 committed Dec 5, 2022
1 parent 3d782fe commit 15dcdf3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 30 deletions.
10 changes: 7 additions & 3 deletions src/ecs-force-deploy-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,19 @@ export class ForceDeployJob extends Construct {

addTrigger(props: TriggerProps) {
const rule = props.rule;
const services = props.services?.map(x => x.service.serviceArn);
const input = props.input || {};
const target = new targets.SfnStateMachine(this.stateMachine, {
input: events.RuleTargetInput.fromObject({ services }),
input: events.RuleTargetInput.fromObject(input),
});
rule.addTarget(target);
}
}

interface TriggerProps {
rule: events.Rule;
services?: BaseFargateService[];
input?: ForceDeployJobInput;
}

interface ForceDeployJobInput {
services?: string[];
}
59 changes: 32 additions & 27 deletions src/supabase-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,40 +396,45 @@ export class SupabaseStack extends FargateStack {
meta.connectDatabase(db);

const forceDeployJob = new ForceDeployJob(this, 'ForceDeployJob', { cluster });

const newServiceCreated = new events.Rule(this, 'NewServiceCreated', {
description: 'Supabase - New service created (for Service Connect)',
eventPattern: {
source: ['aws.servicediscovery'],
detailType: ['AWS API Call via CloudTrail'],
detail: {
eventName: ['CreateService'],
responseElements: {
service: {
namespaceId: [namespace.namespaceId],
type: ['HTTP'],
// for ECS Service Connect
forceDeployJob.addTrigger({
rule: new events.Rule(this, 'NewServiceCreated', {
description: 'Supabase - New service created (for Service Connect)',
eventPattern: {
source: ['aws.servicediscovery'],
detailType: ['AWS API Call via CloudTrail'],
detail: {
eventName: ['CreateService'],
responseElements: {
service: {
namespaceId: [namespace.namespaceId],
type: ['HTTP'],
},
},
},
},
},
}),
});

const authParameterChangedRule = new events.Rule(this, 'AuthParameterChanged', {
description: 'Supabase - Auth parameter changed',
eventPattern: {
source: ['aws.ssm'],
detailType: ['Parameter Store Change'],
detail: {
name: [{ prefix: `/${cdk.Aws.STACK_NAME}/${auth.node.id}/` }],
operation: ['Update'],
// for DB secret rotation
forceDeployJob.addTrigger({
rule: db.secretRotationSucceeded,
});
// for Auth provider settings changed
forceDeployJob.addTrigger({
input: { services: [auth.service.serviceArn] },
rule: new events.Rule(this, 'AuthParameterChanged', {
description: 'Supabase - Auth parameter changed',
eventPattern: {
source: ['aws.ssm'],
detailType: ['Parameter Store Change'],
detail: {
name: [{ prefix: `/${cdk.Aws.STACK_NAME}/${auth.node.id}/` }],
operation: ['Update'],
},
},
},
}),
});

forceDeployJob.addTrigger({ rule: newServiceCreated }); // for Service Connect
forceDeployJob.addTrigger({ rule: db.secretRotationSucceeded });
forceDeployJob.addTrigger({ rule: authParameterChangedRule, services: [auth] });

// Supabase Studio
const studioBranch = new cdk.CfnParameter(this, 'StudioBranch', {
type: 'String',
Expand Down

0 comments on commit 15dcdf3

Please sign in to comment.