Skip to content

Commit

Permalink
feat(deploy): adds runtime as a flag to the deploy command (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
philnash authored Apr 15, 2021
1 parent 90a3e63 commit 789ec02
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/serverless-api/examples/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ async function run() {
const result = await client.deployProject({
...config,
overrideExistingService: true,
runtime: 'node12',
env: {
HELLO: 'ahoy',
WORLD: 'welt',
Expand Down
6 changes: 5 additions & 1 deletion packages/serverless-api/src/api/builds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export async function triggerBuild(
serviceSid: string,
client: TwilioServerlessApiClient
): Promise<BuildResource> {
const { functionVersions, dependencies, assetVersions } = config;
const { functionVersions, dependencies, assetVersions, runtime } = config;
try {
const body: ParsedUrlQueryInput = {};

Expand All @@ -105,6 +105,10 @@ export async function triggerBuild(
body.AssetVersions = assetVersions;
}

if (runtime) {
body.Runtime = runtime;
}

const resp = await client.request('post', `Services/${serviceSid}/Builds`, {
responseType: 'json',
headers: {
Expand Down
6 changes: 3 additions & 3 deletions packages/serverless-api/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,7 @@ export class TwilioServerlessApiClient extends events.EventEmitter {
...this.config,
...deployConfig,
};

const { functions, assets } = config;
const { functions, assets, runtime } = config;

let serviceSid = config.serviceSid;
if (!serviceSid) {
Expand Down Expand Up @@ -541,7 +540,7 @@ export class TwilioServerlessApiClient extends events.EventEmitter {
});
const dependencies = getDependencies(config.pkgJson);
const build = await triggerBuild(
{ functionVersions, dependencies, assetVersions },
{ functionVersions, dependencies, assetVersions, runtime },
serviceSid,
this
);
Expand Down Expand Up @@ -575,6 +574,7 @@ export class TwilioServerlessApiClient extends events.EventEmitter {
domain,
functionResources,
assetResources,
runtime: build.runtime,
};
} catch (err) {
convertApiErrorsAndThrow(err);
Expand Down
5 changes: 5 additions & 0 deletions packages/serverless-api/src/types/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ type DeployProjectConfigBase = {
* If no `serviceSid` is specified but a service with `serviceName` is found, it will deploy to that one.
*/
overrideExistingService?: boolean;
/**
* Version of Node.js to deploy with in Twilio Runtime. Can be "node10" or "node12"
*/
runtime?: string;
};

/**
Expand Down Expand Up @@ -106,6 +110,7 @@ export type DeployResult = {
domain: string;
functionResources: FunctionResource[];
assetResources: AssetResource[];
runtime: string;
};

export type StatusUpdate = {
Expand Down
2 changes: 2 additions & 0 deletions packages/serverless-api/src/types/serverless-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export interface BuildResource extends UpdateableResourceBase {
status: BuildStatus;
function_versions: FunctionVersion[];
asset_versions: AssetVersion[];
runtime: string;
}

export interface BuildList extends BaseList<'builds'> {
Expand All @@ -122,6 +123,7 @@ export type BuildConfig = {
dependencies?: Dependency[];
functionVersions?: Sid[];
assetVersions?: Sid[];
runtime?: string;
};

export interface LogApiResource extends ResourceBase {
Expand Down
1 change: 1 addition & 0 deletions packages/serverless-runtime-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"twilio": "^3.33.0"
},
"devDependencies": {
"@types/express": "^4.17.11",
"all-contributors-cli": "^6.7.0"
},
"publishConfig": {
Expand Down
9 changes: 7 additions & 2 deletions packages/twilio-run/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function handleError(
const fullCommand = getFullCommand(flags);
const messageBody = stripIndent`
Here are a few ways to solve this problem:
- Rename your project in the package.json "name" property
- Pass an explicit name to your deployment
> ${constructCommandName(fullCommand, 'deploy', [
Expand All @@ -59,7 +59,7 @@ function handleError(
'--override-existing-project',
])}
- Run deployment in force mode
> ${constructCommandName(fullCommand, 'deploy', ['--force'])}
> ${constructCommandName(fullCommand, 'deploy', ['--force'])}
`;
logger.error(messageBody, err.message);
} else if (err.name === 'TwilioApiError') {
Expand Down Expand Up @@ -203,6 +203,11 @@ export const cliInfo: CliInfo = {
type: 'string',
describe: 'Specific folder name to be used for static functions',
},
runtime: {
type: 'string',
describe:
'The version of Node.js to deploy the build to. (node10 or node12)',
},
},
};

Expand Down
5 changes: 3 additions & 2 deletions packages/twilio-run/src/config/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type DeployCliFlags = Arguments<
assets: boolean;
assetsFolder?: string;
functionsFolder?: string;
runtime?: string;
}
>;

Expand Down Expand Up @@ -100,8 +101,7 @@ export async function getConfigFromFlags(
);
}

const region = flags.region;
const edge = flags.edge;
const { region, edge, runtime } = flags;

return {
cwd,
Expand All @@ -121,5 +121,6 @@ export async function getConfigFromFlags(
noFunctions: !flags.functions,
region,
edge,
runtime,
};
}
7 changes: 6 additions & 1 deletion packages/twilio-run/src/printers/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function plainPrintDeployedResources(
environmentSuffix: config.functionsEnv,
environmentSid: result.environmentSid,
buildSid: result.buildSid,
runtime: result.runtime,
viewLiveLogs: getTwilioConsoleDeploymentUrl(
result.serviceSid,
result.environmentSid
Expand Down Expand Up @@ -92,6 +93,7 @@ function prettyPrintConfigInfo(config: DeployLocalProjectConfig) {
{bold.cyan Root Directory}\t${config.cwd}
{bold.cyan Dependencies}\t${dependencyString}
{bold.cyan Env Variables}\t${Object.keys(config.env).join(', ')}
{bold.cyan Runtime}\t\t${config.runtime}
`
);
}
Expand All @@ -108,6 +110,7 @@ function plainPrintConfigInfo(config: DeployLocalProjectConfig) {
rootDirectory: config.cwd,
dependencies: dependencyString,
environmentVariables: Object.keys(config.env).join(','),
runtime: config.runtime,
};
writeOutput(`configInfo\n${printObjectWithoutHeaders(printObj)}\n`);
}
Expand All @@ -131,9 +134,11 @@ function prettyPrintDeployedResources(
{bold.cyan Service:}
${config.serviceName} {dim (${result.serviceSid})}
{bold.cyan Environment:}
${config.functionsEnv} {dim (${result.environmentSid})}
${config.functionsEnv} {dim (${result.environmentSid})}
{bold.cyan Build SID:}
${result.buildSid}
{bold.cyan Runtime:}
${result.runtime}
{bold.cyan View Live Logs:}
${twilioConsoleLogsLink}
`.trim()
Expand Down

0 comments on commit 789ec02

Please sign in to comment.