From 36da045b9da477988288a19960c319448afd69a0 Mon Sep 17 00:00:00 2001 From: Helio Machado <0x2b3bfa0+git@googlemail.com> Date: Mon, 12 Sep 2022 21:41:25 +0000 Subject: [PATCH 1/3] Retrieve exclusion list from environment variable --- src/cml.js | 8 +++++++- src/drivers/bitbucket_cloud.js | 4 ++-- src/drivers/github.js | 4 ++-- src/drivers/gitlab.js | 5 +++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/cml.js b/src/cml.js index 505c1d749..5857095a0 100755 --- a/src/cml.js +++ b/src/cml.js @@ -402,7 +402,13 @@ class CML { } async startRunner(opts = {}) { - return await this.getDriver().startRunner(opts); + const env = {}; + const sensitive = + ['CML_RUNNER_SENSITIVE_ENV'] + + process.env.CML_RUNNER_SENSITIVE_ENV.split(':'); + for (const variable in process.env) + if (!sensitive.includes(variable)) env[variable] = process.env[variable]; + return await this.getDriver().startRunner({ ...opts, env }); } async registerRunner(opts = {}) { diff --git a/src/drivers/bitbucket_cloud.js b/src/drivers/bitbucket_cloud.js index 0c6a668dd..b626f467b 100644 --- a/src/drivers/bitbucket_cloud.js +++ b/src/drivers/bitbucket_cloud.js @@ -124,7 +124,7 @@ class BitbucketCloud { async startRunner(opts) { const { projectPath } = this; - const { workdir, name, labels } = opts; + const { workdir, name, labels, env } = opts; winston.warn( `Bitbucket runner is working under /tmp folder and not under ${workdir} as expected` @@ -155,7 +155,7 @@ class BitbucketCloud { ${gpu ? '--runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all' : ''} \ docker-public.packages.atlassian.com/sox/atlassian/bitbucket-pipelines-runner:1`; - return spawn(command, { shell: true }); + return spawn(command, { shell: true, env }); } catch (err) { throw new Error(`Failed preparing runner: ${err.message}`); } diff --git a/src/drivers/github.js b/src/drivers/github.js index fe25ef2c5..ee3b64b2c 100644 --- a/src/drivers/github.js +++ b/src/drivers/github.js @@ -250,7 +250,7 @@ class Github { } async startRunner(opts) { - const { workdir, single, name, labels } = opts; + const { workdir, single, name, labels, env } = opts; try { const runnerCfg = resolve(workdir, '.runner'); @@ -286,7 +286,7 @@ class Github { return spawn(resolve(workdir, 'run.sh'), { shell: true, - env: {} + env }); } catch (err) { throw new Error(`Failed preparing GitHub runner: ${err.message}`); diff --git a/src/drivers/gitlab.js b/src/drivers/gitlab.js index ebb594a20..ed5975958 100644 --- a/src/drivers/gitlab.js +++ b/src/drivers/gitlab.js @@ -176,7 +176,8 @@ class Gitlab { single, labels, name, - dockerVolumes = [] + dockerVolumes = [], + env } = opts; const gpu = await gpuPresent(); @@ -210,7 +211,7 @@ class Gitlab { ${dockerVolumesTpl} \ ${single ? '--max-builds 1' : ''}`; - return spawn(command, { shell: true, env: {} }); + return spawn(command, { shell: true, env }); } catch (err) { if (err.message === 'Forbidden') err.message += From aca6c5b36a54743c6d2c36eb0ef1c6f4f3f64e1a Mon Sep 17 00:00:00 2001 From: Helio Machado <0x2b3bfa0+git@googlemail.com> Date: Mon, 10 Oct 2022 06:00:01 +0200 Subject: [PATCH 2/3] Apply suggestions from code review --- src/cml.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cml.js b/src/cml.js index 5857095a0..81b6be033 100755 --- a/src/cml.js +++ b/src/cml.js @@ -404,8 +404,8 @@ class CML { async startRunner(opts = {}) { const env = {}; const sensitive = - ['CML_RUNNER_SENSITIVE_ENV'] + - process.env.CML_RUNNER_SENSITIVE_ENV.split(':'); + ['_CML_RUNNER_SENSITIVE_ENV'] + + process.env._CML_RUNNER_SENSITIVE_ENV.split(':'); for (const variable in process.env) if (!sensitive.includes(variable)) env[variable] = process.env[variable]; return await this.getDriver().startRunner({ ...opts, env }); From e29b8aad00437c8174c3f4ec49ea7944557f1c06 Mon Sep 17 00:00:00 2001 From: Helio Machado <0x2b3bfa0+git@googlemail.com> Date: Mon, 10 Oct 2022 06:05:25 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Fix=20=E2=80=9Cthe=20blunder=20of=20the=20c?= =?UTF-8?q?entury=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.youtube.com/watch?v=vcFBwt1nu2U --- src/cml.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cml.js b/src/cml.js index 81b6be033..63716f0ea 100755 --- a/src/cml.js +++ b/src/cml.js @@ -403,9 +403,10 @@ class CML { async startRunner(opts = {}) { const env = {}; - const sensitive = - ['_CML_RUNNER_SENSITIVE_ENV'] + - process.env._CML_RUNNER_SENSITIVE_ENV.split(':'); + const sensitive = [ + '_CML_RUNNER_SENSITIVE_ENV', + ...process.env._CML_RUNNER_SENSITIVE_ENV.split(':') + ]; for (const variable in process.env) if (!sensitive.includes(variable)) env[variable] = process.env[variable]; return await this.getDriver().startRunner({ ...opts, env });