console/deployment/services/billing.ts
Kamil Kisiela b9d8e2ceac
Fix the new env vars setup (#450)
* Use 5432 as default port of pg

* Fix ssl

* fix: only set heartbeat env variable if heartbeat is enabled (#446)

* fix: only set heartbeat env variable if heartbeat is enabled

* fix: default port

Co-authored-by: Kamil Kisiela <kamil.kisiela@gmail.com>

* POSTGRES_SSL everywhere

* oh come on

* Fix Kafka connection

* Fix DOCS_URL

* Fix docs url

* But I can feel your heartbeat

I can feel your heartbeat (he said to me)

'I can feel your heartbeat' (running through me)

Feel your heartbeat

She said, 'I can feel your heartbeat' (she said to me)

'I can feel your heartbeat' (she said to me)

'I can feel your heartbeat' (running through me)

Your heartbeat, feel your heartbeat

* Your heartbeat, your heartbeat

Co-authored-by: Laurin Quast <laurinquast@googlemail.com>
2022-10-05 11:48:05 +02:00

61 lines
2.5 KiB
TypeScript

import * as pulumi from '@pulumi/pulumi';
import * as azure from '@pulumi/azure';
import { parse } from 'pg-connection-string';
import { RemoteArtifactAsServiceDeployment } from '../utils/remote-artifact-as-service';
import { PackageHelper } from '../utils/pack';
import { DeploymentEnvironment } from '../types';
import { DbMigrations } from './db-migrations';
import { UsageEstimator } from './usage-estimation';
import { serviceLocalEndpoint } from '../utils/local-endpoint';
const billingConfig = new pulumi.Config('billing');
const commonConfig = new pulumi.Config('common');
const commonEnv = commonConfig.requireObject<Record<string, string>>('env');
const apiConfig = new pulumi.Config('api');
export type StripeBillingService = ReturnType<typeof deployStripeBilling>;
export function deployStripeBilling({
storageContainer,
packageHelper,
deploymentEnv,
dbMigrations,
usageEstimator,
}: {
usageEstimator: UsageEstimator;
storageContainer: azure.storage.Container;
packageHelper: PackageHelper;
deploymentEnv: DeploymentEnvironment;
dbMigrations: DbMigrations;
}) {
const rawConnectionString = apiConfig.requireSecret('postgresConnectionString');
const connectionString = rawConnectionString.apply(rawConnectionString => parse(rawConnectionString));
return new RemoteArtifactAsServiceDeployment(
'stripe-billing',
{
storageContainer,
replicas: 1,
readinessProbe: '/_readiness',
livenessProbe: '/_health',
env: {
...deploymentEnv,
...commonEnv,
SENTRY: commonEnv.SENTRY_ENABLED,
RELEASE: packageHelper.currentReleaseId(),
USAGE_ESTIMATOR_ENDPOINT: serviceLocalEndpoint(usageEstimator.service),
STRIPE_SECRET_KEY: billingConfig.requireSecret('stripePrivateKey'),
POSTGRES_HOST: connectionString.apply(connection => connection.host ?? ''),
POSTGRES_PORT: connectionString.apply(connection => connection.port ?? '5432'),
POSTGRES_PASSWORD: connectionString.apply(connection => connection.password ?? ''),
POSTGRES_USER: connectionString.apply(connection => connection.user ?? ''),
POSTGRES_DB: connectionString.apply(connection => connection.database ?? ''),
POSTGRES_SSL: connectionString.apply(connection => (connection.ssl ? '1' : '0')),
},
exposesMetrics: true,
packageInfo: packageHelper.npmPack('@hive/stripe-billing'),
port: 4000,
},
[dbMigrations, usageEstimator.service, usageEstimator.deployment]
).deploy();
}