From 6da797686cb1367f6e7976b693222406615ae923 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Mon, 15 Jun 2020 12:33:09 +1000 Subject: [PATCH 1/2] fix(activate): activating with environment variables Previously activating a build would not set any env vars, this fixes that. https://github.com/twilio-labs/twilio-run/issues/109 --- examples/activate.js | 23 +++++++++++++++++++++++ src/client.ts | 7 +++++++ src/types/activate.ts | 2 ++ 3 files changed, 32 insertions(+) create mode 100644 examples/activate.js diff --git a/examples/activate.js b/examples/activate.js new file mode 100644 index 0000000..949b0c4 --- /dev/null +++ b/examples/activate.js @@ -0,0 +1,23 @@ +const { TwilioServerlessApiClient } = require('../dist'); +const serviceSid = process.argv[2]; +async function run() { + const config = { + accountSid: process.env.TWILIO_ACCOUNT_SID, + authToken: process.env.TWILIO_AUTH_TOKEN, + }; + + const client = new TwilioServerlessApiClient(config); + console.log('Activating'); + const result = await client.activateBuild({ + ...config, + env: {}, + serviceSid, + sourceEnvironment: 'test', + targetEnvironment: 'stage3', + createEnvironment: true, + }); + console.log('Done Activating'); + console.dir(result); +} + +run().catch(console.error); diff --git a/src/client.ts b/src/client.ts index 1f73349..b3035c8 100644 --- a/src/client.ts +++ b/src/client.ts @@ -318,6 +318,7 @@ export class TwilioServerlessApiClient extends events.EventEmitter { targetEnvironment, serviceSid, sourceEnvironment, + env, } = activateConfig; if (!buildSid && !sourceEnvironment) { @@ -372,6 +373,12 @@ export class TwilioServerlessApiClient extends events.EventEmitter { throw new Error('Could not determine build SID'); } + this.emit('status-update', { + status: DeployStatus.SETTING_VARIABLES, + message: 'Setting environment variables', + }); + await setEnvironmentVariables(env, targetEnvironment, serviceSid, this); + const { domain_name } = await getEnvironment( targetEnvironment, serviceSid, diff --git a/src/types/activate.ts b/src/types/activate.ts index 1e3f256..854abf1 100644 --- a/src/types/activate.ts +++ b/src/types/activate.ts @@ -2,6 +2,7 @@ import { ClientConfig } from './client'; import { Sid } from './serverless-api'; +import { EnvironmentVariables } from './generic'; export type ActivateConfig = ClientConfig & { force?: boolean; @@ -10,6 +11,7 @@ export type ActivateConfig = ClientConfig & { buildSid?: Sid; targetEnvironment: string | Sid; sourceEnvironment?: string | Sid; + env: EnvironmentVariables; }; export type ActivateResult = { From 5976b3146aaa45748b62b5644797abf4e47b1c5c Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 16 Jun 2020 10:43:35 +1000 Subject: [PATCH 2/2] fix(activate): update activate example --- examples/activate.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/activate.js b/examples/activate.js index 949b0c4..6b2d7ce 100644 --- a/examples/activate.js +++ b/examples/activate.js @@ -1,3 +1,7 @@ +// This can be run after examples/deploy.js you just need the service Sid. +// Run this example with: +// node deploy/activate.js SERVICE_SID + const { TwilioServerlessApiClient } = require('../dist'); const serviceSid = process.argv[2]; async function run() { @@ -10,10 +14,13 @@ async function run() { console.log('Activating'); const result = await client.activateBuild({ ...config, - env: {}, + env: { + HELLO: 'hello', + WORLD: 'world', + }, serviceSid, sourceEnvironment: 'test', - targetEnvironment: 'stage3', + targetEnvironment: 'stage', createEnvironment: true, }); console.log('Done Activating');