Skip to content

Commit

Permalink
feat: make values from --dotenv available to Azure workers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hassy committed Oct 18, 2024
1 parent c34f4e2 commit ac209b1
Showing 1 changed file with 15 additions and 2 deletions.
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 ac209b1

Please sign in to comment.