From ac209b199e0a0255012f392619a1d81155b89602 Mon Sep 17 00:00:00 2001 From: hveldstra Date: Fri, 18 Oct 2024 11:41:50 +0100 Subject: [PATCH 1/2] feat: make values from --dotenv available to Azure workers Currently the values set in an env file are only made available to the Artillery process running in a worker Azure, instead of being set at the container level. This means that for example it's impossible to set the DEBUG environment variable in the worker to help debug issues. This change makes tests on Azure ACI work in the same way as tests on AWS Fargate. --- packages/artillery/lib/platform/az/aci.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/artillery/lib/platform/az/aci.js b/packages/artillery/lib/platform/az/aci.js index e9771b0cac..9112bd1fd7 100644 --- a/packages/artillery/lib/platform/az/aci.js +++ b/packages/artillery/lib/platform/az/aci.js @@ -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) { @@ -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'; @@ -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']) { @@ -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: [ From 58f9085b7b4e06956ea7a9bc0fe31302b1e682f5 Mon Sep 17 00:00:00 2001 From: hveldstra Date: Fri, 18 Oct 2024 11:49:28 +0100 Subject: [PATCH 2/2] feat: rename --dotenv to --env-file Add --env-file as an alias for the existing --dotenv flag. "--dotenv" is a confusing name when saying it out loud (e.g. on a support call). "--env-file" is more precise and is also used by Node.js v20 and above: https://nodejs.org/dist/latest-v20.x/docs/api/cli.html#--env-fileconfig --- packages/artillery/lib/cli/common-flags.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/artillery/lib/cli/common-flags.js b/packages/artillery/lib/cli/common-flags.js index d1461a0849..e01f597cd7 100644 --- a/packages/artillery/lib/cli/common-flags.js +++ b/packages/artillery/lib/cli/common-flags.js @@ -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',