Skip to content

Commit

Permalink
fat(infra): creating hook for amplify app to trigger rebuilds (passpo…
Browse files Browse the repository at this point in the history
  • Loading branch information
nutrina authored Mar 17, 2024
1 parent b775e24 commit 863c455
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
7 changes: 5 additions & 2 deletions infra/aws/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ const serviceRecord = new aws.route53.Record("passport-record", {
],
});

coreInfraStack.getOutput("newPassportDomain").apply((domainName) => {
const stakingApp = createAmplifyStakingApp(
const amplifyAppInfo = coreInfraStack.getOutput("newPassportDomain").apply((domainName) => {
const stakingAppInfo = createAmplifyStakingApp(
`${process.env["STAKING_APP_GITHUB_URL"]}`,
`${process.env["STAKING_APP_GITHUB_ACCESS_TOKEN_FOR_AMPLIFY"]}`,
domainName,
Expand All @@ -485,4 +485,7 @@ coreInfraStack.getOutput("newPassportDomain").apply((domainName) => {
process.env["STAKING_APP_BASIC_AUTH_USERNAME"],
process.env["STAKING_APP_BASIC_AUTH_PASSWORD"]
);
return stakingAppInfo;
});

export const amplifyAppHookUrl = pulumi.secret(amplifyAppInfo.webHook.url);
26 changes: 24 additions & 2 deletions infra/lib/staking/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as aws from "@pulumi/aws";
import { Input } from "@pulumi/pulumi";
import * as std from "@pulumi/std";
import * as github from "@pulumi/github";

export function createAmplifyStakingApp(
githubUrl: string,
Expand All @@ -15,7 +16,7 @@ export function createAmplifyStakingApp(
enableBasicAuth: boolean,
username?: string,
password?: string
): aws.amplify.App {
): { app: aws.amplify.App; webHook: aws.amplify.Webhook } {
const name = `${prefix}.${domainName}`;
const amplifyApp = new aws.amplify.App(name, {
name: name,
Expand Down Expand Up @@ -77,6 +78,27 @@ applications:
},
],
});
const webHook = new aws.amplify.Webhook(`${name}-${branchName}`, {
appId: amplifyApp.id,
branchName: branchName,
description: `trigger build from branch ${branchName}`,
});

// // Define a GitHub repository webhook for the repository to trigger Amplify builds.
// const repoWebhook = new github.RepositoryWebhook("repoWebhook", {
// // Use the repository name and owner from above
// repository: "id-staking-v2-app",
// // Set the configuration for the webhook.
// configuration: {
// url: webHook.url, // Use the webhook URL from the Amplify app
// contentType: "json", // Webhook payload format
// insecureSsl: false, // Use SSL for communication
// secret: "<YOUR_WEBHOOK_SECRET>", // Use a secret token for securing webhook payloads
// },
// // Trigger the webhook on push events to any branch.
// events: ["push"],
// active: true, // The webhook is active
// });

return amplifyApp;
return { app: amplifyApp, webHook: webHook };
}
1 change: 1 addition & 0 deletions infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dependencies": {
"@pulumi/aws": "^5.0.0",
"@pulumi/awsx": "^0.40.0",
"@pulumi/github": "^6.1.0",
"@pulumi/pulumi": "^3.0.0",
"@pulumi/std": "^1.6.2"
}
Expand Down
7 changes: 7 additions & 0 deletions infra/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,13 @@
"@pulumi/pulumi" "^3.0.0"
semver "^5.4.0"

"@pulumi/github@^6.1.0":
version "6.1.0"
resolved "https://registry.yarnpkg.com/@pulumi/github/-/github-6.1.0.tgz#301006c034cf47f4847d262b6556f476b38211c9"
integrity sha512-zSN0bT80T/QPhWRheJBhQxikBGSfPbRa9VKBzPSlGHNcsptxZRpZLyjw7MDr7IDne9QfzfG5VE+HSZEtmMlS4Q==
dependencies:
"@pulumi/pulumi" "^3.0.0"

"@pulumi/pulumi@^3.0.0":
version "3.109.0"
resolved "https://registry.yarnpkg.com/@pulumi/pulumi/-/pulumi-3.109.0.tgz#9d0171a43c195f386eb59364e3f0d263427b7b13"
Expand Down

0 comments on commit 863c455

Please sign in to comment.