Skip to content

Commit 789ec02

Browse files
authored
feat(deploy): adds runtime as a flag to the deploy command (#218)
1 parent 90a3e63 commit 789ec02

File tree

9 files changed

+33
-9
lines changed

9 files changed

+33
-9
lines changed

packages/serverless-api/examples/deploy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ async function run() {
1010
const result = await client.deployProject({
1111
...config,
1212
overrideExistingService: true,
13+
runtime: 'node12',
1314
env: {
1415
HELLO: 'ahoy',
1516
WORLD: 'welt',

packages/serverless-api/src/api/builds.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export async function triggerBuild(
8888
serviceSid: string,
8989
client: TwilioServerlessApiClient
9090
): Promise<BuildResource> {
91-
const { functionVersions, dependencies, assetVersions } = config;
91+
const { functionVersions, dependencies, assetVersions, runtime } = config;
9292
try {
9393
const body: ParsedUrlQueryInput = {};
9494

@@ -105,6 +105,10 @@ export async function triggerBuild(
105105
body.AssetVersions = assetVersions;
106106
}
107107

108+
if (runtime) {
109+
body.Runtime = runtime;
110+
}
111+
108112
const resp = await client.request('post', `Services/${serviceSid}/Builds`, {
109113
responseType: 'json',
110114
headers: {

packages/serverless-api/src/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,7 @@ export class TwilioServerlessApiClient extends events.EventEmitter {
437437
...this.config,
438438
...deployConfig,
439439
};
440-
441-
const { functions, assets } = config;
440+
const { functions, assets, runtime } = config;
442441

443442
let serviceSid = config.serviceSid;
444443
if (!serviceSid) {
@@ -541,7 +540,7 @@ export class TwilioServerlessApiClient extends events.EventEmitter {
541540
});
542541
const dependencies = getDependencies(config.pkgJson);
543542
const build = await triggerBuild(
544-
{ functionVersions, dependencies, assetVersions },
543+
{ functionVersions, dependencies, assetVersions, runtime },
545544
serviceSid,
546545
this
547546
);
@@ -575,6 +574,7 @@ export class TwilioServerlessApiClient extends events.EventEmitter {
575574
domain,
576575
functionResources,
577576
assetResources,
577+
runtime: build.runtime,
578578
};
579579
} catch (err) {
580580
convertApiErrorsAndThrow(err);

packages/serverless-api/src/types/deploy.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ type DeployProjectConfigBase = {
4343
* If no `serviceSid` is specified but a service with `serviceName` is found, it will deploy to that one.
4444
*/
4545
overrideExistingService?: boolean;
46+
/**
47+
* Version of Node.js to deploy with in Twilio Runtime. Can be "node10" or "node12"
48+
*/
49+
runtime?: string;
4650
};
4751

4852
/**
@@ -106,6 +110,7 @@ export type DeployResult = {
106110
domain: string;
107111
functionResources: FunctionResource[];
108112
assetResources: AssetResource[];
113+
runtime: string;
109114
};
110115

111116
export type StatusUpdate = {

packages/serverless-api/src/types/serverless-api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export interface BuildResource extends UpdateableResourceBase {
101101
status: BuildStatus;
102102
function_versions: FunctionVersion[];
103103
asset_versions: AssetVersion[];
104+
runtime: string;
104105
}
105106

106107
export interface BuildList extends BaseList<'builds'> {
@@ -122,6 +123,7 @@ export type BuildConfig = {
122123
dependencies?: Dependency[];
123124
functionVersions?: Sid[];
124125
assetVersions?: Sid[];
126+
runtime?: string;
125127
};
126128

127129
export interface LogApiResource extends ResourceBase {

packages/serverless-runtime-types/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"twilio": "^3.33.0"
3030
},
3131
"devDependencies": {
32+
"@types/express": "^4.17.11",
3233
"all-contributors-cli": "^6.7.0"
3334
},
3435
"publishConfig": {

packages/twilio-run/src/commands/deploy.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function handleError(
4545
const fullCommand = getFullCommand(flags);
4646
const messageBody = stripIndent`
4747
Here are a few ways to solve this problem:
48-
48+
4949
- Rename your project in the package.json "name" property
5050
- Pass an explicit name to your deployment
5151
> ${constructCommandName(fullCommand, 'deploy', [
@@ -59,7 +59,7 @@ function handleError(
5959
'--override-existing-project',
6060
])}
6161
- Run deployment in force mode
62-
> ${constructCommandName(fullCommand, 'deploy', ['--force'])}
62+
> ${constructCommandName(fullCommand, 'deploy', ['--force'])}
6363
`;
6464
logger.error(messageBody, err.message);
6565
} else if (err.name === 'TwilioApiError') {
@@ -203,6 +203,11 @@ export const cliInfo: CliInfo = {
203203
type: 'string',
204204
describe: 'Specific folder name to be used for static functions',
205205
},
206+
runtime: {
207+
type: 'string',
208+
describe:
209+
'The version of Node.js to deploy the build to. (node10 or node12)',
210+
},
206211
},
207212
};
208213

packages/twilio-run/src/config/deploy.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export type DeployCliFlags = Arguments<
3737
assets: boolean;
3838
assetsFolder?: string;
3939
functionsFolder?: string;
40+
runtime?: string;
4041
}
4142
>;
4243

@@ -100,8 +101,7 @@ export async function getConfigFromFlags(
100101
);
101102
}
102103

103-
const region = flags.region;
104-
const edge = flags.edge;
104+
const { region, edge, runtime } = flags;
105105

106106
return {
107107
cwd,
@@ -121,5 +121,6 @@ export async function getConfigFromFlags(
121121
noFunctions: !flags.functions,
122122
region,
123123
edge,
124+
runtime,
124125
};
125126
}

packages/twilio-run/src/printers/deploy.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ function plainPrintDeployedResources(
6060
environmentSuffix: config.functionsEnv,
6161
environmentSid: result.environmentSid,
6262
buildSid: result.buildSid,
63+
runtime: result.runtime,
6364
viewLiveLogs: getTwilioConsoleDeploymentUrl(
6465
result.serviceSid,
6566
result.environmentSid
@@ -92,6 +93,7 @@ function prettyPrintConfigInfo(config: DeployLocalProjectConfig) {
9293
{bold.cyan Root Directory}\t${config.cwd}
9394
{bold.cyan Dependencies}\t${dependencyString}
9495
{bold.cyan Env Variables}\t${Object.keys(config.env).join(', ')}
96+
{bold.cyan Runtime}\t\t${config.runtime}
9597
`
9698
);
9799
}
@@ -108,6 +110,7 @@ function plainPrintConfigInfo(config: DeployLocalProjectConfig) {
108110
rootDirectory: config.cwd,
109111
dependencies: dependencyString,
110112
environmentVariables: Object.keys(config.env).join(','),
113+
runtime: config.runtime,
111114
};
112115
writeOutput(`configInfo\n${printObjectWithoutHeaders(printObj)}\n`);
113116
}
@@ -131,9 +134,11 @@ function prettyPrintDeployedResources(
131134
{bold.cyan Service:}
132135
${config.serviceName} {dim (${result.serviceSid})}
133136
{bold.cyan Environment:}
134-
${config.functionsEnv} {dim (${result.environmentSid})}
137+
${config.functionsEnv} {dim (${result.environmentSid})}
135138
{bold.cyan Build SID:}
136139
${result.buildSid}
140+
{bold.cyan Runtime:}
141+
${result.runtime}
137142
{bold.cyan View Live Logs:}
138143
${twilioConsoleLogsLink}
139144
`.trim()

0 commit comments

Comments
 (0)