Skip to content

Commit

Permalink
Support passing environment variables to dapr cli (#327)
Browse files Browse the repository at this point in the history
* Support passing environment variables to dapr cli

* Add env vars to dapr command

* Add task definition to package.json

---------

Co-authored-by: Yevgen Polyak <[email protected]>
  • Loading branch information
evhen14 and yevgen-el8 authored Apr 18, 2024
1 parent 0f6642f commit 481fd0f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Dapr",
"description": "Makes it easy to run, debug, and interact with Dapr-enabled applications.",
"icon": "assets/images/extensionIcon.png",
"version": "0.8.0",
"version": "0.8.1",
"preview": true,
"publisher": "ms-azuretools",
"license": "SEE LICENSE IN LICENSE.txt",
Expand Down Expand Up @@ -459,6 +459,17 @@
"description": "%vscode-dapr.tasks.dapr.properties.metricsPort.description%",
"default": -1
},
"options": {
"type": "object",
"description": "%vscode-dapr.tasks.dapr.properties.options.description%",
"additionalProperties":true,
"properties": {
"env": {
"type": "object",
"description": "%vscode-dapr.tasks.dapr.properties.options.env.description%"
}
}
},
"placementHostAddress": {
"type": "string",
"description": "%vscode-dapr.tasks.dapr.properties.placementHostAddress.description%",
Expand Down Expand Up @@ -658,6 +669,17 @@
],
"default": "standalone"
},
"options": {
"type": "object",
"description": "%vscode-dapr.tasks.daprd.properties.options.description%",
"additionalProperties":true,
"properties": {
"env": {
"type": "object",
"description": "%vscode-dapr.tasks.daprd.properties.options.env.description%"
}
}
},
"placementHostAddress": {
"type": "string",
"description": "%vscode-dapr.tasks.daprd.properties.placementHostAddress.description%"
Expand Down
4 changes: 4 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
"vscode-dapr.tasks.dapr.properties.listenAddresses.description": "One or more addresses for the Dapr API to listen on, CSV limited.",
"vscode-dapr.tasks.dapr.properties.logLevel.description": "Sets the log verbosity.",
"vscode-dapr.tasks.dapr.properties.metricsPort.description": "The port of metrics on dapr.",
"vscode-dapr.tasks.dapr.properties.options.description": "Task execution options.",
"vscode-dapr.tasks.dapr.properties.options.env.description": "Task execution environment variables.",
"vscode-dapr.tasks.dapr.properties.placementHostAddress.description": "The host on which the placement service resides.",
"vscode-dapr.tasks.dapr.properties.profilePort.description": "The port for the profile server to listen on.",
"vscode-dapr.tasks.dapr.properties.resourcesPath.description": "(Deprecated in v1.11.) The path for resources directory (default \"<user>/.dapr/components\").",
Expand Down Expand Up @@ -105,6 +107,8 @@
"vscode-dapr.tasks.daprd.properties.logLevel.description": "Sets the log verbosity.",
"vscode-dapr.tasks.daprd.properties.metricsPort.description": "The port for the metrics server.",
"vscode-dapr.tasks.daprd.properties.mode.description": "Runtime mode for Dapr.",
"vscode-dapr.tasks.daprd.properties.options.description": "Task execution options.",
"vscode-dapr.tasks.daprd.properties.options.env.description": "Task execution environment variables.",
"vscode-dapr.tasks.daprd.properties.placementHostAddress.description": "Address for the Dapr placement service.",
"vscode-dapr.tasks.daprd.properties.profilePort.description": "The port for the profile server.",
"vscode-dapr.tasks.daprd.properties.publicPort.description": "Public port for Dapr Health and Metadata to listen on.",
Expand Down
4 changes: 2 additions & 2 deletions src/tasks/daprCommandTaskProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default class DaprCommandTaskProvider extends CommandTaskProvider {
// if any property being set means do not need to infer dapr.yaml
if (Object.prototype.hasOwnProperty.call(daprDefinition, def) && def !== "type" && def !== undefined) {
const command = createCommandLineBuilder(daprPathProvider, daprDefinition).build();
return callback(command, { cwd: definition.cwd });
return callback(command, { cwd: definition.cwd, env: Object.assign({}, definition.options?.env, process.env) });
}
}

Expand All @@ -86,7 +86,7 @@ export default class DaprCommandTaskProvider extends CommandTaskProvider {
await checkFileExists(runFilePath).then((fileExists) => {
if (fileExists) {
const command = createCommandLineBuilder(daprPathProvider, { type: 'dapr', runFile: runFilePath }).build();
return callback(command, { cwd: definition.cwd });
return callback(command, { cwd: definition.cwd, env: Object.assign({}, definition.options?.env, process.env) });
} else {
throw new Error(localize('tasks.daprCommandTaskProvider.noRunFile', 'there is no dapr.yaml in this folder or workspace.'));
}
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/daprdCommandTaskProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default class DaprdCommandTaskProvider extends CommandTaskProvider {
.withArgs(daprDefinition.args)
.build();

await callback(command, { cwd: definition.cwd });
await callback(command, { cwd: definition.cwd, env: Object.assign({}, process.env, definition.options?.env) });
});
},
/* isBackgroundTask: */ true,
Expand Down
9 changes: 9 additions & 0 deletions src/tasks/taskDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ export interface DependsOn {
type?: string;
}

export interface Dictionary<T> {
[Key: string]: T;
}

export interface Options {
env?: Dictionary<string>
}

export interface TaskDefinition extends vscode.TaskDefinition {
cwd?: string;
options?: Options;
dependsOn?: string | string[] | DependsOn;
label?: string;
}

0 comments on commit 481fd0f

Please sign in to comment.