Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: env file improvements #3376

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading