@gershy/lilac 0.0.10 → 0.0.12
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/cmp/cjs/main.js +4 -12
- package/cmp/cjs/util/mockAws.d.ts +13 -0
- package/cmp/cjs/util/mockAws.js +39 -0
- package/cmp/mjs/main.js +1 -9
- package/cmp/mjs/util/mockAws.d.ts +13 -0
- package/cmp/mjs/util/mockAws.js +34 -0
- package/package.json +5 -3
package/cmp/cjs/main.js
CHANGED
|
@@ -30,6 +30,7 @@ const terraform_ts_1 = require("./petal/terraform/terraform.js");
|
|
|
30
30
|
const aws_ts_1 = require("./util/aws.js");
|
|
31
31
|
const clearing_1 = require("@gershy/clearing");
|
|
32
32
|
const procTerraform_ts_1 = __importDefault(require("./util/procTerraform.js"));
|
|
33
|
+
const util_try_with_healing_1 = __importDefault(require("@gershy/util-try-with-healing"));
|
|
33
34
|
const { File, Provider, Terraform } = terraform_ts_1.PetalTerraform;
|
|
34
35
|
class Flower {
|
|
35
36
|
constructor() { }
|
|
@@ -261,26 +262,17 @@ class Garden {
|
|
|
261
262
|
if (mode === 'test')
|
|
262
263
|
throw Error('test mode not implemented yet');
|
|
263
264
|
const { bootFact, mainFact } = await this.prepare();
|
|
264
|
-
const tryWithHealing = async (args) => {
|
|
265
|
-
const { fn, heal, canHeal } = args;
|
|
266
|
-
return fn().catch(async (err) => {
|
|
267
|
-
if (!canHeal(err))
|
|
268
|
-
throw err;
|
|
269
|
-
await heal();
|
|
270
|
-
return fn();
|
|
271
|
-
});
|
|
272
|
-
};
|
|
273
265
|
const logicalApply = (args) => {
|
|
274
|
-
return
|
|
266
|
+
return (0, util_try_with_healing_1.default)({
|
|
275
267
|
fn: () => this.terraformApply(args.mainFact),
|
|
276
268
|
canHeal: err => (err.output ?? '')[has]('please run "terraform init"'),
|
|
277
|
-
heal: () =>
|
|
269
|
+
heal: () => (0, util_try_with_healing_1.default)({
|
|
278
270
|
fn: async () => {
|
|
279
271
|
await this.terraformInit(args.mainFact);
|
|
280
272
|
await this.ctx.patioFact.kid(['main', '.terraform.lock.hcl']).setData(await args.mainFact.kid(['.terraform.lock.hcl']).getData('str'));
|
|
281
273
|
},
|
|
282
274
|
canHeal: err => true,
|
|
283
|
-
heal: () =>
|
|
275
|
+
heal: () => (0, util_try_with_healing_1.default)({
|
|
284
276
|
fn: () => this.terraformApply(args.bootFact),
|
|
285
277
|
canHeal: err => (err.output ?? '')[has]('please run "terraform init"'),
|
|
286
278
|
heal: () => this.terraformInit(args.bootFact)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type MockAwsArgs = {
|
|
2
|
+
port: number;
|
|
3
|
+
image: `localstack/localstack${':' | '@'}${string}`;
|
|
4
|
+
};
|
|
5
|
+
declare const _default: (args: MockAwsArgs) => Promise<{
|
|
6
|
+
netProc: {
|
|
7
|
+
proto: string;
|
|
8
|
+
addr: string;
|
|
9
|
+
port: number;
|
|
10
|
+
};
|
|
11
|
+
end: () => Promise<void>;
|
|
12
|
+
}>;
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const util_nodejs_proc_1 = __importDefault(require("@gershy/util-nodejs-proc"));
|
|
7
|
+
const disk_1 = require("@gershy/disk");
|
|
8
|
+
const util_http_1 = __importDefault(require("@gershy/util-http"));
|
|
9
|
+
const LOCALSTACK_IMAGE = 'localstack/localstack:latest';
|
|
10
|
+
const LOCALSTACK_PORT = 4566;
|
|
11
|
+
exports.default = async (args) => {
|
|
12
|
+
// Ensure docker is running
|
|
13
|
+
await (async () => {
|
|
14
|
+
const output = await (0, util_nodejs_proc_1.default)('docker ps', { cwd: disk_1.rootFact });
|
|
15
|
+
if (!output[has]('TODO'))
|
|
16
|
+
throw Error('docker unavailable');
|
|
17
|
+
})();
|
|
18
|
+
// Deploy localstack to docker
|
|
19
|
+
const { containerName } = await (async () => {
|
|
20
|
+
const containerName = `mockAws${Date.now()}`;
|
|
21
|
+
await (0, util_nodejs_proc_1.default)(`docker run --rm -d --name ${containerName} -p ${args.port}:${args.port} ${args.image}`, { cwd: disk_1.rootFact });
|
|
22
|
+
const readyEndpoint = {
|
|
23
|
+
$req: null,
|
|
24
|
+
$res: null,
|
|
25
|
+
netProc: { proto: 'http', addr: 'localhost', port: args.port },
|
|
26
|
+
path: ['health', 'ready'],
|
|
27
|
+
method: 'get'
|
|
28
|
+
};
|
|
29
|
+
const res = await (0, util_http_1.default)(readyEndpoint, { query: {}, body: {} });
|
|
30
|
+
console.log('localstack http health', { res });
|
|
31
|
+
return { containerName };
|
|
32
|
+
})();
|
|
33
|
+
return {
|
|
34
|
+
netProc: { proto: 'http', addr: 'localhost', port: args.port },
|
|
35
|
+
end: async () => {
|
|
36
|
+
await (0, util_nodejs_proc_1.default)(`docker rm -f ${containerName}`, { cwd: disk_1.rootFact });
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
};
|
package/cmp/mjs/main.js
CHANGED
|
@@ -10,6 +10,7 @@ import { PetalTerraform } from "./petal/terraform/terraform.js";
|
|
|
10
10
|
import { regions as awsRegions } from "./util/aws.js";
|
|
11
11
|
import { isCls, skip } from '@gershy/clearing';
|
|
12
12
|
import procTerraform from "./util/procTerraform.js";
|
|
13
|
+
import tryWithHealing from '@gershy/util-try-with-healing';
|
|
13
14
|
const { File, Provider, Terraform } = PetalTerraform;
|
|
14
15
|
export class Flower {
|
|
15
16
|
constructor() { }
|
|
@@ -239,15 +240,6 @@ export class Garden {
|
|
|
239
240
|
if (mode === 'test')
|
|
240
241
|
throw Error('test mode not implemented yet');
|
|
241
242
|
const { bootFact, mainFact } = await this.prepare();
|
|
242
|
-
const tryWithHealing = async (args) => {
|
|
243
|
-
const { fn, heal, canHeal } = args;
|
|
244
|
-
return fn().catch(async (err) => {
|
|
245
|
-
if (!canHeal(err))
|
|
246
|
-
throw err;
|
|
247
|
-
await heal();
|
|
248
|
-
return fn();
|
|
249
|
-
});
|
|
250
|
-
};
|
|
251
243
|
const logicalApply = (args) => {
|
|
252
244
|
return tryWithHealing({
|
|
253
245
|
fn: () => this.terraformApply(args.mainFact),
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type MockAwsArgs = {
|
|
2
|
+
port: number;
|
|
3
|
+
image: `localstack/localstack${':' | '@'}${string}`;
|
|
4
|
+
};
|
|
5
|
+
declare const _default: (args: MockAwsArgs) => Promise<{
|
|
6
|
+
netProc: {
|
|
7
|
+
proto: string;
|
|
8
|
+
addr: string;
|
|
9
|
+
port: number;
|
|
10
|
+
};
|
|
11
|
+
end: () => Promise<void>;
|
|
12
|
+
}>;
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import proc from '@gershy/util-nodejs-proc';
|
|
2
|
+
import { rootFact } from '@gershy/disk';
|
|
3
|
+
import http from '@gershy/util-http';
|
|
4
|
+
const LOCALSTACK_IMAGE = 'localstack/localstack:latest';
|
|
5
|
+
const LOCALSTACK_PORT = 4566;
|
|
6
|
+
export default async (args) => {
|
|
7
|
+
// Ensure docker is running
|
|
8
|
+
await (async () => {
|
|
9
|
+
const output = await proc('docker ps', { cwd: rootFact });
|
|
10
|
+
if (!output[has]('TODO'))
|
|
11
|
+
throw Error('docker unavailable');
|
|
12
|
+
})();
|
|
13
|
+
// Deploy localstack to docker
|
|
14
|
+
const { containerName } = await (async () => {
|
|
15
|
+
const containerName = `mockAws${Date.now()}`;
|
|
16
|
+
await proc(`docker run --rm -d --name ${containerName} -p ${args.port}:${args.port} ${args.image}`, { cwd: rootFact });
|
|
17
|
+
const readyEndpoint = {
|
|
18
|
+
$req: null,
|
|
19
|
+
$res: null,
|
|
20
|
+
netProc: { proto: 'http', addr: 'localhost', port: args.port },
|
|
21
|
+
path: ['health', 'ready'],
|
|
22
|
+
method: 'get'
|
|
23
|
+
};
|
|
24
|
+
const res = await http(readyEndpoint, { query: {}, body: {} });
|
|
25
|
+
console.log('localstack http health', { res });
|
|
26
|
+
return { containerName };
|
|
27
|
+
})();
|
|
28
|
+
return {
|
|
29
|
+
netProc: { proto: 'http', addr: 'localhost', port: args.port },
|
|
30
|
+
end: async () => {
|
|
31
|
+
await proc(`docker rm -f ${containerName}`, { cwd: rootFact });
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gershy/lilac",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "Luscious infrastructure Living as Code - an opinionated approach to IAC",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lilac",
|
|
@@ -29,8 +29,10 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@gershy/disk": "^0.0.10",
|
|
31
31
|
"@gershy/logger": "^0.0.3",
|
|
32
|
-
"@gershy/util-
|
|
33
|
-
"@gershy/util-
|
|
32
|
+
"@gershy/util-http": "^0.0.4",
|
|
33
|
+
"@gershy/util-nodejs-proc": "^0.0.10",
|
|
34
|
+
"@gershy/util-phrasing": "^0.0.4",
|
|
35
|
+
"@gershy/util-try-with-healing": "^0.0.2"
|
|
34
36
|
},
|
|
35
37
|
"type": "module",
|
|
36
38
|
"files": [
|