console/deployment/services/commerce.ts

92 lines
3.1 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';
2024-03-04 12:56:12 +00:00
import { ServiceSecret } from '../utils/secrets';
2022-12-28 19:22:54 +00:00
import { ServiceDeployment } from '../utils/service-deployment';
import { Clickhouse } from './clickhouse';
2022-05-18 07:26:57 +00:00
import { DbMigrations } from './db-migrations';
2024-03-04 12:56:12 +00:00
import { Docker } from './docker';
import { Emails } from './emails';
2024-03-04 12:56:12 +00:00
import { Environment } from './environment';
2024-04-07 08:57:03 +00:00
import { Observability } from './observability';
2024-03-04 12:56:12 +00:00
import { Postgres } from './postgres';
import { Sentry } from './sentry';
2022-05-18 07:26:57 +00:00
export type CommerceService = ReturnType<typeof deployCommerce>;
2022-05-18 07:26:57 +00:00
2024-03-04 12:56:12 +00:00
class StripeSecret extends ServiceSecret<{
stripePrivateKey: pulumi.Output<string> | string;
stripePublicKey: string | pulumi.Output<string>;
}> {}
export function deployCommerce({
2024-04-07 08:57:03 +00:00
observability,
2024-03-04 12:56:12 +00:00
environment,
2022-05-18 07:26:57 +00:00
dbMigrations,
emails,
image,
2024-03-04 12:56:12 +00:00
docker,
postgres,
clickhouse,
2024-03-04 12:56:12 +00:00
sentry,
2022-05-18 07:26:57 +00:00
}: {
2024-04-07 08:57:03 +00:00
observability: Observability;
image: string;
2024-03-04 12:56:12 +00:00
environment: Environment;
2022-05-18 07:26:57 +00:00
dbMigrations: DbMigrations;
2024-03-04 12:56:12 +00:00
docker: Docker;
emails: Emails;
2024-03-04 12:56:12 +00:00
postgres: Postgres;
clickhouse: Clickhouse;
2024-03-04 12:56:12 +00:00
sentry: Sentry;
2022-05-18 07:26:57 +00:00
}) {
2024-03-04 12:56:12 +00:00
const billingConfig = new pulumi.Config('billing');
const stripeSecret = new StripeSecret('stripe', {
stripePrivateKey: billingConfig.requireSecret('stripePrivateKey'),
stripePublicKey: billingConfig.require('stripePublicKey'),
});
const { deployment, service } = new ServiceDeployment(
'commerce',
2022-05-18 07:26:57 +00:00
{
image,
2024-03-04 12:56:12 +00:00
imagePullSecret: docker.secret,
replicas: environment.podsConfig.general.replicas,
2022-05-18 07:26:57 +00:00
readinessProbe: '/_readiness',
livenessProbe: '/_health',
startupProbe: '/_health',
2022-05-18 07:26:57 +00:00
env: {
2024-03-04 12:56:12 +00:00
...environment.envVars,
SENTRY: sentry.enabled ? '1' : '0',
WEB_APP_URL: `https://${environment.appDns}/`,
OPENTELEMETRY_TRACE_USAGE_REQUESTS: observability.enabledForUsageService ? '1' : '',
2024-04-07 08:57:03 +00:00
OPENTELEMETRY_COLLECTOR_ENDPOINT:
observability.enabled && observability.tracingEndpoint
? observability.tracingEndpoint
: '',
2022-05-18 07:26:57 +00:00
},
exposesMetrics: true,
port: 4000,
},
[dbMigrations],
2024-03-04 12:56:12 +00:00
)
.withSecret('STRIPE_SECRET_KEY', stripeSecret, 'stripePrivateKey')
2024-03-19 12:01:00 +00:00
.withSecret('POSTGRES_HOST', postgres.pgBouncerSecret, 'host')
.withSecret('POSTGRES_PORT', postgres.pgBouncerSecret, 'port')
.withSecret('POSTGRES_USER', postgres.pgBouncerSecret, 'user')
.withSecret('POSTGRES_PASSWORD', postgres.pgBouncerSecret, 'password')
.withSecret('POSTGRES_DB', postgres.pgBouncerSecret, 'database')
.withSecret('POSTGRES_SSL', postgres.pgBouncerSecret, 'ssl')
.withSecret('CLICKHOUSE_HOST', clickhouse.secret, 'host')
.withSecret('CLICKHOUSE_PORT', clickhouse.secret, 'port')
.withSecret('CLICKHOUSE_USERNAME', clickhouse.secret, 'username')
.withSecret('CLICKHOUSE_PASSWORD', clickhouse.secret, 'password')
.withSecret('CLICKHOUSE_PROTOCOL', clickhouse.secret, 'protocol')
2024-03-04 12:56:12 +00:00
.withConditionalSecret(sentry.enabled, 'SENTRY_DSN', sentry.secret, 'dsn')
.deploy();
return {
deployment,
service,
stripeSecret,
2024-03-04 12:56:12 +00:00
};
2022-05-18 07:26:57 +00:00
}