@gershy/lilac 0.0.9 → 0.0.11
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/util/mockAws.d.ts +13 -0
- package/cmp/cjs/util/mockAws.js +39 -0
- package/cmp/mjs/util/mockAws.d.ts +13 -0
- package/cmp/mjs/util/mockAws.js +34 -0
- package/package.json +3 -2
|
@@ -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
|
+
};
|
|
@@ -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.11",
|
|
4
4
|
"description": "Luscious infrastructure Living as Code - an opinionated approach to IAC",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lilac",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@gershy/disk": "^0.0.10",
|
|
31
31
|
"@gershy/logger": "^0.0.3",
|
|
32
|
-
"@gershy/util-
|
|
32
|
+
"@gershy/util-http": "^0.0.4",
|
|
33
|
+
"@gershy/util-nodejs-proc": "^0.0.10",
|
|
33
34
|
"@gershy/util-phrasing": "^0.0.4"
|
|
34
35
|
},
|
|
35
36
|
"type": "module",
|