Skip to content

Commit

Permalink
Merge pull request #3376 from artilleryio/fix/dotenv
Browse files Browse the repository at this point in the history
feat: env file improvements
  • Loading branch information
hassy authored Oct 18, 2024
2 parents f1acd0d + 58f9085 commit 2f24c13
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/artillery/lib/cli/common-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const CommonRunFlags = {
description: 'Write a JSON report to file'
}),
dotenv: Flags.string({
description: 'Path to a dotenv file to load environment variables from'
description: 'Path to a dotenv file to load environment variables from',
aliases: ['env-file']
}),
variables: Flags.string({
char: 'v',
Expand Down
17 changes: 15 additions & 2 deletions packages/artillery/lib/platform/az/aci.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const { IMAGE_VERSION } = require('../aws-ecs/legacy/constants');
const { regionNames } = require('./regions');
const path = require('path');
const { Timeout, sleep } = require('../aws-ecs/legacy/time');
const dotenv = require('dotenv');
const fs = require('node:fs');

class PlatformAzureACI {
constructor(script, variablePayload, opts, platformOpts) {
Expand Down Expand Up @@ -62,6 +64,8 @@ class PlatformAzureACI {
this.memory = parseInt(platformOpts.platformConfig.memory, 10) || 8;
this.region = platformOpts.platformConfig.region || 'eastus';

this.extraEnvVars = {};

if (!regionNames.includes(this.region)) {
const err = new Error(`Invalid region: ${this.region}`);
err.code = 'INVALID_REGION';
Expand Down Expand Up @@ -180,8 +184,13 @@ class PlatformAzureACI {
}

if (this.platformOpts.cliArgs.dotenv) {
this.artilleryArgs.push('--dotenv');
this.artilleryArgs.push(path.basename(this.platformOpts.cliArgs.dotenv));
const dotEnvPath = path.resolve(
process.cwd(),
this.platformOpts.cliArgs.dotenv
);
const contents = fs.readFileSync(dotEnvPath);
const envVars = dotenv.parse(contents);
this.extraEnvVars = Object.assign({}, this.extraEnvVars, envVars);
}

if (this.platformOpts.cliArgs['scenario-name']) {
Expand Down Expand Up @@ -519,6 +528,10 @@ class PlatformAzureACI {
});
}

for (const [name, value] of Object.entries(this.extraEnvVars)) {
environmentVariables.push({ name, value });
}

const containerGroup = {
location: this.region,
containers: [
Expand Down

0 comments on commit 2f24c13

Please sign in to comment.