-
Notifications
You must be signed in to change notification settings - Fork 1
/
prompt.txt
185 lines (167 loc) · 5.28 KB
/
prompt.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
update the src/amplify.ts file so that the createAmplifyApp function is more flexible. It should be able to also handle creating an amplify website based on the below example. Make sure to add or update function parameters of createAmplifyApp so that it can build either application
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as cloudflare from "@pulumi/cloudflare";
import * as op from "@1password/op-js";
import { secretsManager } from "infra-libs";
const stack = pulumi.getStack();
const defaultTags = {
ManagedBy: "pulumi",
PulumiStack: stack,
Project: "id-staking-v2",
};
const stakingBranches = Object({
review: "main",
staging: "staging-app",
production: "production-app",
});
const amplifyStage = Object({
review: "DEVELOPMENT",
staging: "BETA",
production: "PRODUCTION",
});
const prefix = "stake";
const coreInfraStack = new pulumi.StackReference(`gitcoin/core-infra/${stack}`);
const passportXYZDomain = coreInfraStack.getOutput("newPassportDomain");
// Get STAKING_APP_GITHUB_URL Variables
const APP_GITHUB_URL = op.read.parse(
// TODO: this should be moved to id-staking-v2-${stack}-env/ci/STAKING_APP_GITHUB_URL
`op://DevOps/passport-${stack}-env/ci-staking/STAKING_APP_GITHUB_URL`
);
// CLOUDFLARE_DOMAIN & CLOUDFLARE_ZONE_ID are only required for production
const CLOUDFLARE_DOMAIN = stack === "production" ? `passport.xyz` : "";
const CLOUDFLARE_ZONE_ID = op.read.parse(
// TODO: this should be moved to id-staking-v2-${stack}-env/ci/CLOUDFLARE_ZONE_ID
`op://DevOps/passport-${stack}-env/ci/CLOUDFLARE_ZONE_ID`
);
const stakingEnvironment = secretsManager
.getEnvironmentVars({
vault: "DevOps",
repo: "passport", // TODO: this should be moved to id-staking-v2
env: stack,
section: "staking", // TODO: this section should be `app` ?
})
.reduce((acc, { name, value }) => {
acc[name] = value;
return acc;
}, {} as Record<string, string | pulumi.Output<any>>);
passportXYZDomain.apply((domainName) => {
const name = `${prefix}.${domainName}`;
const amplifyApp = new aws.amplify.App(
name,
{
name: name,
repository: APP_GITHUB_URL,
platform: "WEB_COMPUTE",
buildSpec: `version: 1
applications:
- frontend:
phases:
preBuild:
commands:
- yarn install
build:
commands:
- yarn run build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- .next/cache/**/*
- node_modules/**/*
appRoot: app
`,
customRules: [
{
source: "/<*>",
status: "404",
target: "/index.html",
},
],
environmentVariables: {
AMPLIFY_DIFF_DEPLOY: "false",
AMPLIFY_MONOREPO_APP_ROOT: "app",
...stakingEnvironment,
},
tags: {
Name: name,
...defaultTags,
},
},
{ protect: true }
);
const branch = new aws.amplify.Branch(`${name}-${stakingBranches[stack]}`, {
appId: amplifyApp.id,
branchName: stakingBranches[stack],
displayName: stakingBranches[stack],
// stage: amplifyStage[stack],
ttl: "5",
});
const webHook = new aws.amplify.Webhook(`${name}-${stakingBranches[stack]}`, {
appId: amplifyApp.id,
branchName: stakingBranches[stack],
description: `trigger build from branch ${stakingBranches[stack]}`,
});
const domainAssociation = new aws.amplify.DomainAssociation(name, {
appId: amplifyApp.id,
domainName: domainName,
subDomains: [
{
branchName: branch.branchName,
prefix: prefix,
},
],
});
if (CLOUDFLARE_DOMAIN != "") {
// Handle custom / additional domain assotiation
const cloudFlareDomainAssociation = new aws.amplify.DomainAssociation(
`cloudflare-${name}`,
{
appId: amplifyApp.id,
domainName: CLOUDFLARE_DOMAIN,
waitForVerification: false,
subDomains: [
{
branchName: branch.branchName,
prefix: prefix,
},
],
}
);
const domainCert =
cloudFlareDomainAssociation.certificateVerificationDnsRecord;
// Manage CloudFlare Records
const certRecord = domainCert.apply((_cert) => {
const certDetails = _cert.split(" "); // Name Type Value
const certRecord = new cloudflare.Record(
"cloudflare-certificate-record",
{
name: certDetails[0].replace(`.${CLOUDFLARE_DOMAIN}.`, ""), // remove the autocomplete domain
zoneId: CLOUDFLARE_ZONE_ID,
type: certDetails[1],
value: certDetails[2],
allowOverwrite: true,
comment: `Certificate for *.${CLOUDFLARE_DOMAIN}`,
// ttl: 3600
}
);
return certRecord;
});
cloudFlareDomainAssociation.subDomains.apply((_subDomains) => {
_subDomains.map((_subD) => {
const domainDetails = _subD.dnsRecord.split(" "); // Name Type Value
const record = new cloudflare.Record(`${domainDetails[0]}-record`, {
name: domainDetails[0],
zoneId: CLOUDFLARE_ZONE_ID,
type: domainDetails[1],
value: domainDetails[2],
allowOverwrite: true,
comment: `Points to AWS Amplify for stake V2 app`,
});
return record;
});
});
}
});