Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2730 amplify migration 1 #2756

Merged
merged 7 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/components/WelcomeFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const WelcomeFooter = ({ displayPrivacyPolicy, fixed }: { displayPrivacyPolicy:
Learn More
</a>
<a href="https://scorer.gitcoin.co/" className="hover:underline px-2">
Gitcoin Passport Scorer
Passport XYZ Scorer
</a>
<div className="flex items-end justify-end flex-wrap">
<div className="px-2">
Expand Down
4 changes: 2 additions & 2 deletions app/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default function Dashboard() {

useEffect(() => {
if (customization.key !== DEFAULT_CUSTOMIZATION_KEY) {
document.title = `Gitcoin Passport | ${
document.title = `Passport XYZ | ${
customization.key.charAt(0).toUpperCase() + customization.key.slice(1)
} Dashboard`;
TagManager.dataLayer({
Expand All @@ -93,7 +93,7 @@ export default function Dashboard() {
},
});
} else {
document.title = `Gitcoin Passport | Dashboard`;
document.title = `Passport XYZ | Dashboard`;
TagManager.dataLayer({
dataLayer: {
event: "default-dashboard-view",
Expand Down
2 changes: 1 addition & 1 deletion app/pages/Maintenance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function Maintenance() {
className="col-span-2 w-full max-w-md lg:col-start-1 lg:row-span-6 lg:mr-8 lg:max-w-2xl"
/>
<div className="col-span-2 max-w-md text-lg lg:max-w-sm">
Gitcoin Passport is currently down for scheduled maintenance. Please check back again as we will be back up
Passport XYZ is currently down for scheduled maintenance. Please check back again as we will be back up
shortly. For more information, check{" "}
<Hyperlink href="https://twitter.com/gitcoinpassport">@GitcoinPassport</Hyperlink> for updates.
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ function App({ Component, pageProps }: AppProps) {
return (
<>
<Head>
<link rel="shortcut icon" href="/favicon.ico" />
<title>Gitcoin Passport</title>
<link rel="shortcut icon" href="/favicon.png" />
<title>Passport XYZ</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" />
</Head>
<QueryClientProvider client={queryClient}>
Expand Down
Binary file added app/public/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 46 additions & 8 deletions infra/aws/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as op from "@1password/op-js";
import { createAmplifyApp } from "../lib/amplify/app";
import { secretsManager } from "infra-libs";

const stack = pulumi.getStack();
Expand All @@ -19,6 +20,7 @@ const PASSPORT_VC_SECRETS_ARN = op.read.parse(`op://DevOps/passport-${stack}-env

const route53Domain = op.read.parse(`op://DevOps/passport-${stack}-env/ci/ROUTE_53_DOMAIN`);
const route53Zone = op.read.parse(`op://DevOps/passport-${stack}-env/ci/ROUTE_53_ZONE`);
const cloudflareZoneId = op.read.parse(`op://DevOps/passport-${stack}-env/ci/CLOUDFLARE_ZONE_ID`);

const coreInfraStack = new pulumi.StackReference(`gitcoin/core-infra/${stack}`);

Expand Down Expand Up @@ -100,12 +102,12 @@ const iamEnvironment = pulumi
].sort(secretsManager.sortByName)
);

const stakingEnvironment = secretsManager
const passportEnvironment = secretsManager
.getEnvironmentVars({
vault: "DevOps",
repo: "passport",
env: stack,
section: "staking",
section: "app",
})
.reduce((acc, { name, value }) => {
acc[name] = value;
Expand Down Expand Up @@ -151,12 +153,6 @@ const alarmConfigurations: AlarmConfigurations = {
redisErrorPeriod: 1800, // period for redis logged errors, set to 30 min for now
};

const stakingBranches = Object({
review: "main",
staging: "staging-app",
production: "production-app",
});

//////////////////////////////////////////////////////////////
// Service IAM Role
// can be moved to core infrastructure if it is reused
Expand Down Expand Up @@ -539,3 +535,45 @@ const serviceRecord = new aws.route53.Record("passport-record", {
},
],
});

const PASSPORT_APP_GITHUB_URL = op.read.parse(`op://DevOps/passport-${stack}-env/ci/PASSPORT_APP_GITHUB_URL`);
const PASSPORT_APP_GITHUB_ACCESS_TOKEN_FOR_AMPLIFY = op.read.parse(
`op://DevOps/passport-${stack}-secrets/ci/PASSPORT_APP_GITHUB_ACCESS_TOKEN_FOR_AMPLIFY`
);

const CLOUDFLARE_DOMAIN = stack === "production" ? `passport.xyz` : "";
const CLOUDFLARE_ZONE_ID = op.read.parse(`op://DevOps/passport-${stack}-env/ci/CLOUDFLARE_ZONE_ID`);

// If we need to support gitcoinco domain this is needed
// const ROUTE53_PASSPORT_DOMAIN = Object({
// review: "review.passport.gitcoin.co",
// staging: "staging.passport.gitcoin.co",
// production: "passport.gitcoin.co",
// });

const passportBranches = Object({
review: "main",
staging: "staging-app",
production: "production-app",
});

const amplifyAppInfo = coreInfraStack.getOutput("newPassportDomain").apply((domainName) => {
const prefix = "app";
const stakingAppInfo = createAmplifyApp(
PASSPORT_APP_GITHUB_URL,
PASSPORT_APP_GITHUB_ACCESS_TOKEN_FOR_AMPLIFY,
domainName,
CLOUDFLARE_DOMAIN, // cloudflareDomain
CLOUDFLARE_ZONE_ID, // cloudFlareZoneId
prefix,
passportBranches[stack],
passportEnvironment,
{ ...defaultTags, Name: `${prefix}.${domainName}` },
false,
"",
""
);
return stakingAppInfo;
});

export const amplifyAppHookUrl = pulumi.secret(amplifyAppInfo.webHook.url);
43 changes: 22 additions & 21 deletions infra/lib/staking/app.ts → infra/lib/amplify/app.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import * as aws from "@pulumi/aws";
import { Input } from "@pulumi/pulumi";
import { Input, Output } from "@pulumi/pulumi";
import * as pulumi from "@pulumi/pulumi";
import * as std from "@pulumi/std";
import * as cloudflare from "@pulumi/cloudflare";
import * as github from "@pulumi/github";

export function createAmplifyStakingApp(
export function createAmplifyApp(
githubUrl: string,
githubAccessToken: string,
domainName: string,
cloudflareDomain: string,
cloudflareZoneId: string,
prefix: string,
branchName: string,
environmentVariables: Input<{
[key: string]: Input<string>;
}>,
environmentVariables: Record<string, string | Output<any>>,
tags: { [key: string]: string },
enableBasicAuth: boolean,
username?: string,
Expand All @@ -27,31 +25,30 @@ export function createAmplifyStakingApp(
name: name,
repository: githubUrl,
oauthToken: githubAccessToken,
platform: "WEB_COMPUTE",
platform: "WEB",
buildSpec: `version: 1
applications:
- frontend:
phases:
preBuild:
commands:
- yarn install
- nvm use 20.9.0
build:
commands:
- yarn run build
- npm install --g [email protected] && lerna bootstrap && rm -rf ../node_modules/@tendermint && npm run build
artifacts:
baseDirectory: .next
baseDirectory: out
files:
- '**/*'
cache:
paths:
- .next/cache/**/*
- node_modules/**/*
appRoot: app
`,
customRules: [
{
source: "/<*>",
status: "404",
source: "/",
status: "200",
target: "/index.html",
},
],
Expand Down Expand Up @@ -105,12 +102,12 @@ applications:
const certRecord = domainCert.apply((_cert) => {
const certDetails = _cert.split(" "); // Name Type Value
const certRecord = new cloudflare.Record("cloudflare-certificate-record", {
name: certDetails[0].replace(`.${cloudflareDomain}.`, ''), // remove the autocomplete domain
name: certDetails[0].replace(`.${cloudflareDomain}.`, ""), // remove the autocomplete domain
zoneId: cloudflareZoneId,
type: certDetails[1],
value: certDetails[2],
allowOverwrite: true,
comment: `Certificate for *.${cloudflareDomain}`
comment: `Certificate for *.${cloudflareDomain}`,

// ttl: 3600
});
Expand All @@ -126,18 +123,22 @@ applications:
type: domainDetails[1],
value: domainDetails[2],
allowOverwrite: true,
comment: `Points to AWS Amplify for stake V2 app`
comment: `Points to AWS Amplify for stake V2 app`,
});
return record;
});
});
}

const webHook = new aws.amplify.Webhook(`${name}-${branchName}`, {
appId: amplifyApp.id,
branchName: branchName,
description: `trigger build from branch ${branchName}`,
});
const webHook = new aws.amplify.Webhook(
`${name}-${branchName}`,
{
appId: amplifyApp.id,
branchName: branchName,
description: `trigger build from branch ${branchName}`,
},
{ dependsOn: branch }
);

// Note!!!: at the moment this step is done manually & it is required to be configured only once / repository / environment
// - To be improved: investigate & automate github webhook creation
Expand All @@ -158,4 +159,4 @@ applications:
// });

return { app: amplifyApp, webHook: webHook };
}
}
Loading