Skip to content

Commit

Permalink
Avoid DC's 'variable not set' warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kiturutin committed Dec 9, 2023
1 parent 37f135e commit f030246
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 15 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

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

6 changes: 5 additions & 1 deletion lib/browserup_cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import path from 'path';
import { fileURLToPath } from 'url';
import {LogSpinner} from "./utils/log_spinner.mjs";
import {readFileSync} from "fs";
import {BrowserUpPaths} from "./utils/browserup_paths.mjs";

global.appRoot = path.dirname(fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -156,7 +157,10 @@ export class BrowserUpCli {
}

versionMessage() {
return `BrowserUp CLI ${this.getVersion()}\nServices Version: ${SERVICES_VERSION}\nDefault Image: ${BROWSERUP_DEFAULT_IMAGE}`;
return `BrowserUp CLI ${this.getVersion()}\n` +
`Services Version: ${SERVICES_VERSION}\n` +
`Default Image: ${BROWSERUP_DEFAULT_IMAGE}\n` +
`Settings path: ${BrowserUpPaths.appSettingsPath("browserup")}`;
}

constructor(customExitCallback = undefined, outHsh = null) {
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/install.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ async function pullDockerImages(background = false){
log.debug("Looking for yaml at: " + BrowserUpPaths.dockerComposeYmlPath());
log.info("Pulling Docker images.");
log.info("Depending on your connection, this may take from five to fifteen minutes.");

await DockerClient.dockerPull({imageNameAndTag: BROWSERUP_DEFAULT_IMAGE, background: false});
await DockerClient.dockerComposePull(
{dockerComposePath: BrowserUpPaths.dockerComposeYmlPath(), services: '', background: false});
{dockerComposePath: BrowserUpPaths.dockerComposeYmlPath(), services: '', background: false});
}


Expand Down
1 change: 0 additions & 1 deletion lib/services/cluster_credentials_repository.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ dotenvConfig();

export class ClusterCredentialsRepository {
static getCredentials(options, requiredFields = []) {
log.debug("apiToken: " + this.getApiToken(options));
let opts=
{
apiToken: this.getApiToken(options),
Expand Down
28 changes: 22 additions & 6 deletions lib/services/docker_client.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import os from 'os';
import {exec as execCb, spawn, execSync} from 'child_process';
import { promisify } from 'util';
import {ErrorType, decoratedError} from "../browserup_errors.mjs";
import {Docker} from "../utils/docker.mjs";
import yaml from "js-yaml";

const exec = promisify(execCb);

Expand Down Expand Up @@ -226,7 +228,7 @@ export class DockerClient {
if (!fs.existsSync(dockerComposePath)) {
throw decoratedError(`Provided docker-compose file doesn't exist at path: '${dockerComposePath}'`);
}

const emptyEnvs = await this.getEmptyDockerComposeEnvs({dockerComposePath})
const cmd = `${await DockerClient.getDockerComposeExecutable()} -f "${dockerComposePath}" pull ${services}`;
log.debug(`Running command: ${cmd}`);
let result = null;
Expand All @@ -235,7 +237,7 @@ export class DockerClient {
this.execBackgroundCommand(cmd);
return;
} else {
result = await this.execCommand(cmd);
result = await this.execCommand(cmd, emptyEnvs);
}
if (result.exitCode !== 0) {
throw decoratedError(`Failed to run 'docker-compose pull': \n>> ${result.stderr.join(">> ")}`);
Expand Down Expand Up @@ -338,15 +340,29 @@ export class DockerClient {
if (!fs.existsSync(dockerComposePath)) {
throw decoratedError(`Provided docker-compose file doesn't exist at path: '${dockerComposePath}'`);
}

const emptyEnvs = await this.getEmptyDockerComposeEnvs({dockerComposePath})
const cmd = `${await DockerClient.getDockerComposeExecutable()} -f "${dockerComposePath}" rm`;
const result = await this.execCommand(cmd);
const result = await this.execCommand(cmd, emptyEnvs);

if (result.exitCode !== 0) {
throw decoratedError(`Failed to run 'docker-compose rm': \n>> ${result.stderr.join(">> ")}`);
}
}

static async getEmptyDockerComposeEnvs({dockerComposePath}) {
const dockerComposeYaml = fs.readFileSync(dockerComposePath, "utf8")
const templateVarRegex = /\${(.*?)}/g;
const matches = dockerComposeYaml.match(templateVarRegex) || [];

const result = {};
matches.forEach(match => {
const variableName = match.slice(2, -1).trim(); // Remove `${` and `}` and trim whitespace
result[variableName] = '';
});

return result;
}

static async dockerComposeDown({dockerComposePath, removeVolumes = true, env}) {
if (!fs.existsSync(dockerComposePath)) {
throw decoratedError(`Provided docker-compose file doesn't exist at path: '${dockerComposePath}'`);
Expand All @@ -359,8 +375,8 @@ export class DockerClient {
if (removeVolumes) {
cmd += ' -v';
}

const result = await this.execCommand(cmd);
const dummyEnvs = await this.getEmptyDockerComposeEnvs({dockerComposePath})
const result = await this.execCommand(cmd, dummyEnvs);

if (result.exitCode !== 0) {
let msg = `Failed to run 'docker-compose down': \n>> ${result.stderr.join(">> ")}`;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"scripts": {
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"windows-test": "set NODE_OPTIONS=--experimental-vm-modules && jest",
"prepare": "node prepare.mjs"
},
"keywords": [
Expand Down Expand Up @@ -52,8 +53,7 @@
"node"
],
"testMatch": [
",<rootDir>/tests/**/?(*.)+(spec|test).[jt]s?(x)",
"<rootDir>/tests/**/?(*.)+(spec|test).mjs"
"<rootDir>/tests/**/*.{spec,test}.mjs"
],
"testPathIgnorePatterns": [
"/node_modules/",
Expand Down

0 comments on commit f030246

Please sign in to comment.