Skip to content

Commit 5570ef7

Browse files
authored
standalone domains for dev/staging (#7009)
1 parent 6b8a4ff commit 5570ef7

File tree

5 files changed

+29
-52
lines changed

5 files changed

+29
-52
lines changed

deployment/index.ts

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -234,22 +234,28 @@ const hiveConfigSecret = new ServiceSecret('hive-config-secret', {
234234
usageAccessToken: hiveConfig.requireSecret('cliAccessToken'),
235235
});
236236

237-
const publishGraphQLSchemaCommand = publishGraphQLSchema({
238-
graphql,
239-
registry: {
240-
endpoint: `https://${environment.appDns}/registry`,
241-
accessToken: hiveConfigSecret.raw.usageAccessToken,
242-
target: hiveConfig.require('target'),
243-
},
244-
version: {
245-
commit: imagesTag,
246-
},
247-
schemaPath: graphqlSchemaAbsolutePath,
248-
});
237+
// You can change this to `false` in cases when you don't want to publish commands.
238+
// For example, if the entire env is down or if you are having SSL issues.
239+
const RUN_PUBLISH_COMMANDS: boolean = true;
240+
241+
const publishGraphQLSchemaCommand = RUN_PUBLISH_COMMANDS
242+
? publishGraphQLSchema({
243+
graphql,
244+
registry: {
245+
endpoint: `https://${environment.appDns}/registry`,
246+
accessToken: hiveConfigSecret.raw.usageAccessToken,
247+
target: hiveConfig.require('target'),
248+
},
249+
version: {
250+
commit: imagesTag,
251+
},
252+
schemaPath: graphqlSchemaAbsolutePath,
253+
})
254+
: null;
249255

250256
let publishAppDeploymentCommand: pulumi.Resource | undefined;
251257

252-
if (hiveAppPersistedDocumentsAbsolutePath) {
258+
if (hiveAppPersistedDocumentsAbsolutePath && RUN_PUBLISH_COMMANDS) {
253259
publishAppDeploymentCommand = publishAppDeployment({
254260
appName: 'hive-app',
255261
registry: {
@@ -268,7 +274,7 @@ if (hiveAppPersistedDocumentsAbsolutePath) {
268274
dockerSecret: docker.secret,
269275
},
270276
// We need to wait until the new GraphQL schema is published before we can publish the app deployment.
271-
dependsOn: [publishGraphQLSchemaCommand],
277+
dependsOn: publishGraphQLSchemaCommand ? [publishGraphQLSchemaCommand] : [],
272278
});
273279
}
274280

@@ -316,18 +322,6 @@ deployCloudFlareSecurityTransform({
316322
'/api/github',
317323
'/api/slack',
318324
],
319-
ignoredHosts: [
320-
// Ignore CSP for Production CDN
321-
'cdn.graphql-hive.com',
322-
// Staging
323-
'staging.graphql-hive.com',
324-
'app.staging.graphql-hive.com',
325-
'cdn.staging.graphql-hive.com',
326-
// Dev
327-
'dev.graphql-hive.com',
328-
'app.dev.graphql-hive.com',
329-
'cdn.dev.graphql-hive.com',
330-
],
331325
});
332326

333327
export const graphqlApiServiceId = graphql.service.id;

deployment/services/cf-broker.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ export function deployCFBroker({
2626
const broker = new CloudflareBroker({
2727
envName: environment.envName,
2828
zoneId: cfConfig.require('zoneId'),
29-
// We can't cdn for staging env, since CF certificate only covers
30-
// one level of subdomains. See: https://community.cloudflare.com/t/ssl-handshake-error-cloudflare-proxy/175088
31-
// So for staging env, we are going to use `broker-staging` instead of `broker.staging`.
32-
cdnDnsRecord: environment.isProduction
33-
? `broker.${environment.rootDns}`
34-
: `broker-${environment.rootDns}`,
29+
cdnDnsRecord: `broker.${environment.rootDns}`,
3530
secretSignature: cfBrokerSignature,
3631
sentryDsn: sentry.enabled && sentry.secret ? sentry.secret.raw.dsn : '',
3732
release: environment.release,

deployment/services/cf-cdn.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ export function deployCFCDN({
3131
// We can't cdn for staging env, since CF certificate only covers
3232
// one level of subdomains. See: https://community.cloudflare.com/t/ssl-handshake-error-cloudflare-proxy/175088
3333
// So for staging env, we are going to use `cdn-staging` instead of `cdn.staging`.
34-
cdnDnsRecord: environment.isProduction
35-
? `cdn.${environment.rootDns}`
36-
: `cdn-${environment.rootDns}`,
34+
cdnDnsRecord: `cdn.${environment.rootDns}`,
3735
sentryDsn: sentry.enabled && sentry.secret ? sentry.secret?.raw.dsn : '',
3836
release: environment.release,
3937
s3,

deployment/services/cloudflare-security.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,11 @@ function toExpressionList(items: string[]): string {
1717
export function deployCloudFlareSecurityTransform(options: {
1818
environment: Environment;
1919
ignoredPaths: string[];
20-
ignoredHosts: string[];
2120
}) {
22-
// We deploy it only once, because CloudFlare is not super friendly for multiple deployments of "http_response_headers_transform" rules
23-
// The single rule, deployed to prod, covers all other envs, and infers the hostname dynamically.
24-
if (!options.environment.isProduction) {
25-
console.warn(
26-
`Skipped deploy security headers (see "cloudflare-security.ts") for env ${options.environment.envName}`,
27-
);
28-
29-
return;
30-
}
31-
21+
const ignoredHosts = [`cdn.${options.environment.rootDns}`];
3222
const expression = `not http.request.uri.path in { ${toExpressionList(
3323
options.ignoredPaths,
34-
)} } and not http.host in { ${toExpressionList(options.ignoredHosts)} }`;
24+
)} } and not http.host in { ${toExpressionList(ignoredHosts)} }`;
3525

3626
// TODO: When Preflight PR is merged, we'll need to change this to build this host in a better way.
3727
const monacoCdnDynamicBasePath: `https://${string}/` = `https://cdn.jsdelivr.net/npm/monaco-editor@${monacoEditorVersion}/`;
@@ -57,7 +47,7 @@ export function deployCloudFlareSecurityTransform(options: {
5747
frame-src ${stripeHost} https://game.crisp.chat https://{DYNAMIC_HOST_PLACEHOLDER};
5848
style-src 'self' 'unsafe-inline' ${crispHost} fonts.googleapis.com rsms.me ${monacoCdnDynamicBasePath} ${monacoCdnStaticBasePath};
5949
script-src 'self' 'unsafe-eval' 'unsafe-inline' {DYNAMIC_HOST_PLACEHOLDER} ${monacoCdnDynamicBasePath} ${monacoCdnStaticBasePath} ${cspHosts};
60-
connect-src 'self' * {DYNAMIC_HOST_PLACEHOLDER} ${cspHosts};
50+
connect-src 'self' * {DYNAMIC_HOST_PLACEHOLDER} ${cspHosts};
6151
media-src ${crispHost};
6252
style-src-elem 'self' 'unsafe-inline' ${monacoCdnDynamicBasePath} ${monacoCdnStaticBasePath} fonts.googleapis.com rsms.me ${crispHost};
6353
font-src 'self' data: fonts.gstatic.com rsms.me ${monacoCdnDynamicBasePath} ${monacoCdnStaticBasePath} ${crispHost};
@@ -75,14 +65,14 @@ export function deployCloudFlareSecurityTransform(options: {
7565
return new cf.Ruleset('cloudflare-security-transform', {
7666
zoneId: cfConfig.require('zoneId'),
7767
description: 'Enforce security headers and CSP',
78-
name: `Security Transform (all envs)`,
68+
name: `Security Transform (${options.environment.envName})`,
7969
kind: 'zone',
8070
phase: 'http_response_headers_transform',
8171
rules: [
8272
{
8373
expression,
8474
enabled: true,
85-
description: `Security Headers (all envs)`,
75+
description: `Security Headers (${options.environment.envName})`,
8676
action: 'rewrite',
8777
actionParameters: {
8878
headers: [

deployment/utils/reverse-proxy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class Proxy {
7676
}
7777

7878
registerService(
79-
dns: { record: string; apex?: boolean },
79+
dns: { record: string },
8080
routes: {
8181
name: string;
8282
path: string;
@@ -135,7 +135,7 @@ export class Proxy {
135135
secretName: dns.record,
136136
},
137137
corsPolicy: {
138-
allowOrigin: ['https://app.graphql-hive.com', 'https://graphql-hive.com'],
138+
allowOrigin: [`https://${dns.record}`],
139139
allowMethods: ['GET', 'POST', 'OPTIONS'],
140140
allowHeaders: ['*'],
141141
exposeHeaders: ['*'],

0 commit comments

Comments
 (0)