@appliance.sh/api-server 1.12.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/pulumi/pulumi.service.ts +19 -16
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Injectable, Logger } from '@nestjs/common';
|
|
2
|
-
import * as path from 'node:path';
|
|
3
|
-
import * as fs from 'node:fs';
|
|
4
2
|
import * as auto from '@pulumi/pulumi/automation';
|
|
5
3
|
import * as aws from '@pulumi/aws';
|
|
6
4
|
import { ApplianceStack } from './ApplianceStack';
|
|
5
|
+
import { applianceBaseConfig } from '@appliance.sh/sdk';
|
|
7
6
|
|
|
8
7
|
export type PulumiAction = 'deploy' | 'destroy';
|
|
9
8
|
|
|
@@ -19,19 +18,17 @@ export interface PulumiResult {
|
|
|
19
18
|
export class PulumiService {
|
|
20
19
|
private readonly logger = new Logger(PulumiService.name);
|
|
21
20
|
private readonly region = process.env.AWS_REGION || 'us-east-1';
|
|
22
|
-
private readonly backendDir = this.ensureDir(path.resolve(__dirname, '../../.pulumi-state'));
|
|
23
21
|
private readonly projectName = 'appliance-api-managed-proj';
|
|
24
22
|
|
|
25
|
-
private
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
23
|
+
private readonly baseConfig = process.env.APPLIANCE_BASE_CONFIG
|
|
24
|
+
? applianceBaseConfig.parse(JSON.parse(process.env.APPLIANCE_BASE_CONFIG))
|
|
25
|
+
: undefined;
|
|
29
26
|
|
|
30
27
|
private inlineProgram() {
|
|
31
28
|
return async () => {
|
|
32
29
|
const name = 'appliance';
|
|
33
30
|
const regionalProvider = new aws.Provider(`${name}-regional`, {
|
|
34
|
-
region: 'ap-southeast-1',
|
|
31
|
+
region: this.baseConfig?.region ?? 'ap-southeast-1',
|
|
35
32
|
});
|
|
36
33
|
const globalProvider = new aws.Provider(`${name}-global`, {
|
|
37
34
|
region: 'us-east-1',
|
|
@@ -48,14 +45,8 @@ export class PulumiService {
|
|
|
48
45
|
}
|
|
49
46
|
);
|
|
50
47
|
|
|
51
|
-
const bucket = new aws.s3.Bucket('dummy-bucket', {
|
|
52
|
-
forceDestroy: true,
|
|
53
|
-
versioning: { enabled: true },
|
|
54
|
-
tags: { app: 'appliance-api' },
|
|
55
|
-
});
|
|
56
48
|
return {
|
|
57
49
|
applianceStack,
|
|
58
|
-
bucketName: bucket.bucket,
|
|
59
50
|
};
|
|
60
51
|
};
|
|
61
52
|
}
|
|
@@ -63,9 +54,15 @@ export class PulumiService {
|
|
|
63
54
|
private async getOrCreateStack(stackName: string): Promise<auto.Stack> {
|
|
64
55
|
const program = this.inlineProgram();
|
|
65
56
|
const envVars: Record<string, string> = {
|
|
66
|
-
PULUMI_BACKEND_URL: 'file://' + this.backendDir,
|
|
67
57
|
AWS_REGION: this.region,
|
|
68
58
|
};
|
|
59
|
+
if (!this.baseConfig) {
|
|
60
|
+
throw new Error('Missing base config');
|
|
61
|
+
}
|
|
62
|
+
if (this.baseConfig) {
|
|
63
|
+
envVars['PULUMI_BACKEND_URL'] = this.baseConfig.stateBackendUrl;
|
|
64
|
+
}
|
|
65
|
+
|
|
69
66
|
const stack = await auto.LocalWorkspace.createOrSelectStack(
|
|
70
67
|
{ projectName: this.projectName, stackName, program },
|
|
71
68
|
{ envVars }
|
|
@@ -76,9 +73,15 @@ export class PulumiService {
|
|
|
76
73
|
|
|
77
74
|
private async selectExistingStack(stackName: string): Promise<auto.Stack> {
|
|
78
75
|
const envVars: Record<string, string> = {
|
|
79
|
-
PULUMI_BACKEND_URL: 'file://' + this.backendDir,
|
|
80
76
|
AWS_REGION: this.region,
|
|
81
77
|
};
|
|
78
|
+
if (!this.baseConfig) {
|
|
79
|
+
throw new Error('Missing base config');
|
|
80
|
+
}
|
|
81
|
+
if (this.baseConfig) {
|
|
82
|
+
envVars['PULUMI_BACKEND_URL'] = this.baseConfig.stateBackendUrl;
|
|
83
|
+
}
|
|
84
|
+
|
|
82
85
|
const ws = await auto.LocalWorkspace.create({
|
|
83
86
|
projectSettings: { name: this.projectName, runtime: 'nodejs' },
|
|
84
87
|
envVars,
|