@studion/infra-code-blocks
Version:
Studion common infra components
116 lines (115 loc) • 3.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebServerBuilder = void 0;
const pulumi = require("@pulumi/pulumi");
const _1 = require(".");
class WebServerBuilder {
_name;
_container;
_vpc;
_ecsConfig;
_domain;
_hostedZoneId;
_certificate;
_healthCheckPath;
_healthCheckConfig;
_loadBalancingAlgorithmType;
_otelCollector;
_initContainers = [];
_sidecarContainers = [];
_volumes = [];
constructor(name) {
this._name = name;
}
withContainer(image, port, config = {}) {
this._container = {
image,
port,
...config,
};
return this;
}
withEcsConfig(config) {
this._ecsConfig = {
cluster: config.cluster,
name: config.name,
deploymentController: config.deploymentController,
desiredCount: config.desiredCount,
autoscaling: config.autoscaling,
family: config.family,
size: config.size,
logGroupNamePrefix: config.logGroupNamePrefix,
taskExecutionRoleInlinePolicies: config.taskExecutionRoleInlinePolicies,
taskRoleInlinePolicies: config.taskRoleInlinePolicies,
tags: config.tags,
};
return this;
}
withVpc(vpc) {
this._vpc = pulumi.output(vpc);
return this;
}
withVolume(volume) {
this._volumes.push(volume);
return this;
}
withCustomDomain(domain, hostedZoneId) {
this._domain = domain;
this._hostedZoneId = hostedZoneId;
return this;
}
withCertificate(certificate, hostedZoneId, domain) {
this._certificate = certificate;
this._hostedZoneId = hostedZoneId;
this._domain = domain;
return this;
}
addInitContainer(container) {
this._initContainers.push(container);
return this;
}
addSidecarContainer(container) {
this._sidecarContainers.push(container);
return this;
}
withOtelCollector(collector) {
this._otelCollector = collector;
return this;
}
withHealthCheck(path, config) {
this._healthCheckPath = path;
this._healthCheckConfig = config;
return this;
}
withLoadBalancingAlgorithm(algorithm) {
this._loadBalancingAlgorithmType = algorithm;
return this;
}
build(opts = {}) {
if (!this._container) {
throw new Error('Web server not configured. Make sure to call WebServerBuilder.withContainer().');
}
if (!this._ecsConfig) {
throw new Error('ECS not configured. Make sure to call WebServerBuilder.withEcsConfig().');
}
if (!this._vpc) {
throw new Error('VPC not provided. Make sure to call WebServerBuilder.withVpc().');
}
return new _1.WebServer(this._name, {
...this._ecsConfig,
...this._container,
vpc: this._vpc,
volumes: this._volumes,
domain: this._domain,
hostedZoneId: this._hostedZoneId,
certificate: this._certificate,
healthCheckPath: this._healthCheckPath,
healthCheckConfig: this._healthCheckConfig,
loadBalancingAlgorithmType: this._loadBalancingAlgorithmType,
otelCollector: this._otelCollector,
initContainers: this._initContainers,
sidecarContainers: this._sidecarContainers,
}, opts);
}
}
exports.WebServerBuilder = WebServerBuilder;