@dotcom-tool-kit/serverless 1.0.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/.toolkitrc.yml +0 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +8 -0
- package/lib/tasks/deploy.d.ts +7 -0
- package/lib/tasks/deploy.d.ts.map +1 -0
- package/lib/tasks/deploy.js +39 -0
- package/lib/tasks/provision.d.ts +7 -0
- package/lib/tasks/provision.d.ts.map +1 -0
- package/lib/tasks/provision.js +45 -0
- package/lib/tasks/run.d.ts +7 -0
- package/lib/tasks/run.d.ts.map +1 -0
- package/lib/tasks/run.js +50 -0
- package/package.json +36 -0
- package/readme.md +40 -0
package/.toolkitrc.yml
ADDED
|
File without changes
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,gBAAgB,CAAA;AAI7C,eAAO,MAAM,KAAK,6BAAyD,CAAA"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tasks = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const deploy_1 = tslib_1.__importDefault(require("./tasks/deploy"));
|
|
6
|
+
const provision_1 = tslib_1.__importDefault(require("./tasks/provision"));
|
|
7
|
+
const run_1 = tslib_1.__importDefault(require("./tasks/run"));
|
|
8
|
+
exports.tasks = [run_1.default, deploy_1.default, provision_1.default];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Task } from '@dotcom-tool-kit/types';
|
|
2
|
+
import { ServerlessSchema } from '@dotcom-tool-kit/types/lib/schema/serverless';
|
|
3
|
+
export default class ServerlessDeploy extends Task<typeof ServerlessSchema> {
|
|
4
|
+
static description: string;
|
|
5
|
+
run(): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=deploy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/tasks/deploy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAA;AAI/E,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,IAAI,CAAC,OAAO,gBAAgB,CAAC;IACzE,MAAM,CAAC,WAAW,SAAmB;IAE/B,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAsC3B"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const error_1 = require("@dotcom-tool-kit/error");
|
|
4
|
+
const logger_1 = require("@dotcom-tool-kit/logger");
|
|
5
|
+
const types_1 = require("@dotcom-tool-kit/types");
|
|
6
|
+
const vault_1 = require("@dotcom-tool-kit/vault");
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
class ServerlessDeploy extends types_1.Task {
|
|
9
|
+
async run() {
|
|
10
|
+
const { useVault, configPath, buildNumVariable, regions } = this.options;
|
|
11
|
+
const buildNum = process.env[buildNumVariable];
|
|
12
|
+
if (buildNum === undefined) {
|
|
13
|
+
throw new error_1.ToolKitError(`the ${logger_1.styles.task('ServerlessDeploy')} task requires the ${logger_1.styles.code(`$${buildNumVariable}`)} environment variable to be defined`);
|
|
14
|
+
}
|
|
15
|
+
let vaultEnv = {};
|
|
16
|
+
if (useVault) {
|
|
17
|
+
const vault = new vault_1.VaultEnvVars(this.logger, {
|
|
18
|
+
environment: 'production'
|
|
19
|
+
});
|
|
20
|
+
vaultEnv = await vault.get();
|
|
21
|
+
}
|
|
22
|
+
regions.forEach((region) => {
|
|
23
|
+
this.logger.verbose('starting the child serverless process...');
|
|
24
|
+
const args = ['deploy', '--region', region, '--stage', 'prod'];
|
|
25
|
+
if (configPath) {
|
|
26
|
+
args.push('--config', configPath);
|
|
27
|
+
}
|
|
28
|
+
const child = (0, child_process_1.spawn)('serverless', args, {
|
|
29
|
+
env: {
|
|
30
|
+
...vaultEnv,
|
|
31
|
+
...process.env
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
(0, logger_1.hookFork)(this.logger, 'serverless', child);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.default = ServerlessDeploy;
|
|
39
|
+
ServerlessDeploy.description = 'Deploys on AWS';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Task } from '@dotcom-tool-kit/types';
|
|
2
|
+
import { ServerlessSchema } from '@dotcom-tool-kit/types/lib/schema/serverless';
|
|
3
|
+
export default class ServerlessProvision extends Task<typeof ServerlessSchema> {
|
|
4
|
+
static description: string;
|
|
5
|
+
run(): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=provision.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provision.d.ts","sourceRoot":"","sources":["../../src/tasks/provision.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAA;AAI/E,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,IAAI,CAAC,OAAO,gBAAgB,CAAC;IAC5E,MAAM,CAAC,WAAW,SAA4B;IAExC,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CA4C3B"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const error_1 = require("@dotcom-tool-kit/error");
|
|
4
|
+
const logger_1 = require("@dotcom-tool-kit/logger");
|
|
5
|
+
const types_1 = require("@dotcom-tool-kit/types");
|
|
6
|
+
const vault_1 = require("@dotcom-tool-kit/vault");
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
class ServerlessProvision extends types_1.Task {
|
|
9
|
+
async run() {
|
|
10
|
+
const { useVault, configPath, buildNumVariable, systemCode, regions } = this.options;
|
|
11
|
+
const buildNum = process.env[buildNumVariable];
|
|
12
|
+
if (buildNum === undefined) {
|
|
13
|
+
throw new error_1.ToolKitError(`the ${logger_1.styles.task('ServerlessProvision')} task requires the ${logger_1.styles.code(`$${buildNumVariable}`)} environment variable to be defined`);
|
|
14
|
+
}
|
|
15
|
+
let vaultEnv = {};
|
|
16
|
+
if (useVault) {
|
|
17
|
+
const vault = new vault_1.VaultEnvVars(this.logger, {
|
|
18
|
+
environment: 'development'
|
|
19
|
+
});
|
|
20
|
+
vaultEnv = await vault.get();
|
|
21
|
+
}
|
|
22
|
+
this.logger.verbose('starting the child serverless process...');
|
|
23
|
+
const args = [
|
|
24
|
+
'deploy',
|
|
25
|
+
'--region',
|
|
26
|
+
regions[0],
|
|
27
|
+
'--stage',
|
|
28
|
+
`ci${buildNum}`,
|
|
29
|
+
'--aws-profile',
|
|
30
|
+
`CircleCI-role-${systemCode}`
|
|
31
|
+
];
|
|
32
|
+
if (configPath) {
|
|
33
|
+
args.push('--config', './serverless.yml');
|
|
34
|
+
}
|
|
35
|
+
const child = (0, child_process_1.spawn)('serverless', args, {
|
|
36
|
+
env: {
|
|
37
|
+
...vaultEnv,
|
|
38
|
+
...process.env
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
(0, logger_1.hookFork)(this.logger, 'serverless', child);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.default = ServerlessProvision;
|
|
45
|
+
ServerlessProvision.description = 'Provisions a job on AWS';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Task } from '@dotcom-tool-kit/types';
|
|
2
|
+
import { ServerlessSchema } from '@dotcom-tool-kit/types/lib/schema/serverless';
|
|
3
|
+
export default class ServerlessRun extends Task<typeof ServerlessSchema> {
|
|
4
|
+
static description: string;
|
|
5
|
+
run(): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/tasks/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAA;AAO/E,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,IAAI,CAAC,OAAO,gBAAgB,CAAC;IACtE,MAAM,CAAC,WAAW,SAAqC;IAEjD,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CA6C3B"}
|
package/lib/tasks/run.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const types_1 = require("@dotcom-tool-kit/types");
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
const vault_1 = require("@dotcom-tool-kit/vault");
|
|
7
|
+
const logger_1 = require("@dotcom-tool-kit/logger");
|
|
8
|
+
const get_port_1 = tslib_1.__importDefault(require("get-port"));
|
|
9
|
+
const wait_port_1 = tslib_1.__importDefault(require("wait-port"));
|
|
10
|
+
class ServerlessRun extends types_1.Task {
|
|
11
|
+
async run() {
|
|
12
|
+
const { useVault, ports, configPath } = this.options;
|
|
13
|
+
let vaultEnv = {};
|
|
14
|
+
if (useVault) {
|
|
15
|
+
const vault = new vault_1.VaultEnvVars(this.logger, {
|
|
16
|
+
environment: 'development'
|
|
17
|
+
});
|
|
18
|
+
vaultEnv = await vault.get();
|
|
19
|
+
}
|
|
20
|
+
const port = Number(process.env.PORT) ||
|
|
21
|
+
(await (0, get_port_1.default)({
|
|
22
|
+
port: ports
|
|
23
|
+
}));
|
|
24
|
+
this.logger.verbose('starting the child serverless process...');
|
|
25
|
+
const args = ['offline', 'start', '--host', 'local.ft.com', '--httpPort', `${port}`];
|
|
26
|
+
if (configPath) {
|
|
27
|
+
args.push('--config', './serverless.yml');
|
|
28
|
+
}
|
|
29
|
+
const child = (0, child_process_1.spawn)('serverless', args, {
|
|
30
|
+
env: {
|
|
31
|
+
...vaultEnv,
|
|
32
|
+
PORT: port.toString(),
|
|
33
|
+
...process.env
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
(0, logger_1.hookFork)(this.logger, 'serverless', child);
|
|
37
|
+
const unhook = (0, logger_1.hookConsole)(this.logger, 'wait-port');
|
|
38
|
+
try {
|
|
39
|
+
await (0, wait_port_1.default)({
|
|
40
|
+
host: 'localhost',
|
|
41
|
+
port: port
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
unhook();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.default = ServerlessRun;
|
|
50
|
+
ServerlessRun.description = 'Run serverless functions locally';
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dotcom-tool-kit/serverless",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "a plugin to manage and deploy apps using AWS Serverless",
|
|
5
|
+
"main": "lib",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"author": "FT.com Platforms Team <platforms-team.customer-products@ft.com>",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/financial-times/dotcom-tool-kit.git",
|
|
15
|
+
"directory": "plugins/serverless"
|
|
16
|
+
},
|
|
17
|
+
"bugs": "https://github.com/financial-times/dotcom-tool-kit/issues",
|
|
18
|
+
"homepage": "https://github.com/financial-times/dotcom-tool-kit/tree/main/plugins/serverless",
|
|
19
|
+
"files": [
|
|
20
|
+
"/lib",
|
|
21
|
+
".toolkitrc.yml"
|
|
22
|
+
],
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"dotcom-tool-kit": "^2.6.0",
|
|
25
|
+
"serverless-offline": "^12.0.4"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@dotcom-tool-kit/error": "^2.0.1",
|
|
29
|
+
"@dotcom-tool-kit/state": "^2.0.1",
|
|
30
|
+
"@dotcom-tool-kit/types": "^2.10.0",
|
|
31
|
+
"@dotcom-tool-kit/vault": "^2.0.16",
|
|
32
|
+
"get-port": "^5.1.1",
|
|
33
|
+
"tslib": "^2.3.1",
|
|
34
|
+
"wait-port": "^0.2.9"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# @dotcom-tool-kit/serverless
|
|
2
|
+
|
|
3
|
+
Tool Kit plugin to manage Lambdas with [AWS serverless](https://www.serverless.com/framework/docs/getting-started/).
|
|
4
|
+
|
|
5
|
+
This plugin will be installed as a dependency of the [backend-serverless-app](https://github.com/Financial-Times/dotcom-tool-kit/tree/main/plugins/backend-serverless-app) plugin, which we recommend using instead of installing this plugin directly. That plugin will install additional plugins that will be useful or most Customer Products projects at the FT.
|
|
6
|
+
|
|
7
|
+
## Installation & usage
|
|
8
|
+
|
|
9
|
+
With Tool Kit [already set up](https://github.com/financial-times/dotcom-tool-kit#installing-and-using-tool-kit), install this plugin as a dev dependency:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install --save-dev @dotcom-tool-kit/serverless
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And add it to your repo's `.toolkitrc.yml`:
|
|
16
|
+
|
|
17
|
+
```yml
|
|
18
|
+
plugins:
|
|
19
|
+
- '@dotcom-tool-kit/serverless'
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Options
|
|
23
|
+
|
|
24
|
+
| Key | Description | Default value |
|
|
25
|
+
|-|-|-|
|
|
26
|
+
| `awsAccountId` | [required] the ID of the AWS account you wish to deploy to (account IDs can be found at the [FT login page](https://awslogin.in.ft.com/)) | none |
|
|
27
|
+
| `systemCode` | [required] the system code for your app | none |
|
|
28
|
+
| `region` | [require] what AWS region you want to deploy to (usually `eu-west-1`) | none |
|
|
29
|
+
| `configPath` | [optional] path to your serverless config file. If this is not provided aws defaults to `./serverless.yml` but [other config fomats are accepted](https://www.serverless.com/framework/docs/providers/aws/guide/intro#alternative-configuration-format)| |
|
|
30
|
+
| `useVault` | option to run the application with environment variables from Vault | `true` |
|
|
31
|
+
| `ports` | ports to try to bind to for this application | `[3001, 3002, 3003]` |
|
|
32
|
+
| `buildNumVariable` | an environment variable used to get a unique ID to use in the provisioning stage | `CIRCLE_BUILD_NUM` |
|
|
33
|
+
|
|
34
|
+
## Tasks
|
|
35
|
+
|
|
36
|
+
| Task | Description | Default hooks |
|
|
37
|
+
|-|-|-|
|
|
38
|
+
| `ServerlessRun` | Run application with `serverless` | `run:local` |
|
|
39
|
+
| `ServerlessProvision` | Deploy review app with `serverless` | `deploy:review` |
|
|
40
|
+
| `ServerlessDeploy` | Deploy production app with `serverless` | `deploy:production` |
|