console/deployment/services/app.ts

85 lines
2.8 KiB
TypeScript
Raw Normal View History

2022-05-18 07:26:57 +00:00
import * as pulumi from '@pulumi/pulumi';
2022-12-28 19:22:54 +00:00
import { serviceLocalEndpoint } from '../utils/local-endpoint';
import { ServiceDeployment } from '../utils/service-deployment';
2024-03-04 12:56:12 +00:00
import { StripeBilling } from './billing';
2022-12-28 19:22:54 +00:00
import { DbMigrations } from './db-migrations';
2024-03-04 12:56:12 +00:00
import { Docker } from './docker';
import { Environment } from './environment';
import { GitHubApp } from './github';
2022-12-28 19:22:54 +00:00
import { GraphQL } from './graphql';
2024-03-04 12:56:12 +00:00
import { Sentry } from './sentry';
import { SlackApp } from './slack-app';
import { Zendesk } from './zendesk';
2022-05-18 07:26:57 +00:00
export type App = ReturnType<typeof deployApp>;
export function deployApp({
graphql,
dbMigrations,
publishAppDeploymentCommand,
image,
2024-03-04 12:56:12 +00:00
docker,
zendesk,
github,
slackApp,
billing,
sentry,
environment,
2022-05-18 07:26:57 +00:00
}: {
2024-03-04 12:56:12 +00:00
environment: Environment;
image: string;
2022-05-18 07:26:57 +00:00
graphql: GraphQL;
dbMigrations: DbMigrations;
2024-03-04 12:56:12 +00:00
docker: Docker;
zendesk: Zendesk;
github: GitHubApp;
slackApp: SlackApp;
billing: StripeBilling;
sentry: Sentry;
publishAppDeploymentCommand: pulumi.Resource | undefined;
2022-05-18 07:26:57 +00:00
}) {
2024-03-04 12:56:12 +00:00
const appConfig = new pulumi.Config('app');
const appEnv = appConfig.requireObject<Record<string, string>>('env');
return new ServiceDeployment(
2022-05-18 07:26:57 +00:00
'app',
{
image,
2024-03-04 12:56:12 +00:00
replicas: environment.isProduction ? 3 : 1,
imagePullSecret: docker.secret,
2022-05-18 07:26:57 +00:00
readinessProbe: '/api/health',
livenessProbe: '/api/health',
startupProbe: '/api/health',
availabilityOnEveryNode: true,
2024-03-04 12:56:12 +00:00
env: {
...environment.envVars,
SENTRY: sentry.enabled ? '1' : '0',
GRAPHQL_PUBLIC_ENDPOINT: `https://${environment.appDns}/graphql`,
GRAPHQL_PUBLIC_SUBSCRIPTION_ENDPOINT: `https://${environment.appDns}/graphql/stream`,
GRAPHQL_PUBLIC_ORIGIN: `https://${environment.appDns}`,
2024-03-04 12:56:12 +00:00
SERVER_ENDPOINT: serviceLocalEndpoint(graphql.service),
APP_BASE_URL: `https://${environment.appDns}/`,
INTEGRATION_SLACK: '1',
INTEGRATION_GITHUB_APP_NAME: github.name,
GA_TRACKING_ID: appEnv.GA_TRACKING_ID,
DOCS_URL: 'https://the-guild.dev/graphql/hive/docs',
GRAPHQL_PERSISTED_OPERATIONS: publishAppDeploymentCommand ? '1' : '0',
2024-03-04 12:56:12 +00:00
ZENDESK_SUPPORT: zendesk.enabled ? '1' : '0',
AUTH_GITHUB: '1',
AUTH_GOOGLE: '1',
AUTH_REQUIRE_EMAIL_VERIFICATION: '1',
AUTH_ORGANIZATION_OIDC: '1',
MEMBER_ROLES_DEADLINE: appEnv.MEMBER_ROLES_DEADLINE,
PORT: '3000',
2024-03-04 12:56:12 +00:00
},
2022-05-18 07:26:57 +00:00
port: 3000,
},
[graphql.service, graphql.deployment, dbMigrations, publishAppDeploymentCommand],
2024-03-04 12:56:12 +00:00
)
.withSecret('INTEGRATION_SLACK_CLIENT_ID', slackApp.secret, 'clientId')
.withSecret('INTEGRATION_SLACK_CLIENT_SECRET', slackApp.secret, 'clientSecret')
.withSecret('STRIPE_PUBLIC_KEY', billing.secret, 'stripePublicKey')
.withConditionalSecret(sentry.enabled, 'SENTRY_DSN', sentry.secret, 'dsn')
.deploy();
2022-05-18 07:26:57 +00:00
}