From 4d9026f74da6d5f7ba266ce0abda50f53bec36fc Mon Sep 17 00:00:00 2001 From: ManAnRuck Date: Mon, 10 Jun 2024 18:28:31 +0200 Subject: [PATCH] fix: handling varfiles in remote actions (#6147) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: handling varfiles with helm sources Signed-off-by: Manuel Ruck * refactor: 🧹 reuse basePath Signed-off-by: Manuel Ruck * test(e2e): add varfiles to `remote-sources` e2e test * refactor: helpers for effective config file's dir resolution --------- Signed-off-by: Manuel Ruck Co-authored-by: Manuel Ruck Co-authored-by: Vladimir Vagaytsev --- core/src/actions/base.ts | 7 +++++++ core/src/config/base.ts | 7 ++++++- core/src/graph/actions.ts | 6 ++++-- core/src/tasks/resolve-action.ts | 4 +++- examples/remote-sources/worker/.env | 1 + examples/remote-sources/worker/garden.yml | 4 ++++ 6 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 examples/remote-sources/worker/.env diff --git a/core/src/actions/base.ts b/core/src/actions/base.ts index b1cc573ab7..3d9a9458b8 100644 --- a/core/src/actions/base.ts +++ b/core/src/actions/base.ts @@ -67,6 +67,7 @@ import { joinWithPosix } from "../util/fs.js" import type { LinkedSource } from "../config-store/local.js" import type { BaseActionTaskParams, ExecuteTask } from "../tasks/base.js" import { styles } from "../logger/styles.js" +import { dirname } from "node:path" // TODO: split this file @@ -476,6 +477,11 @@ export abstract class BaseAction< return this._config.internal.configFilePath } + effectiveConfigFileLocation() { + const configPath = this.configPath() + return !!configPath ? dirname(configPath) : this.sourcePath() + } + moduleName(): string | null { return this._moduleName || null } @@ -675,6 +681,7 @@ export abstract class BaseAction< set executeConcurrencyLimit(limit: number | undefined) { this._config.internal.executeConcurrencyLimit = limit } + get executeConcurrencyLimit(): number | undefined { return this._config.internal.executeConcurrencyLimit } diff --git a/core/src/config/base.ts b/core/src/config/base.ts index f9bbf193a3..07878cefbf 100644 --- a/core/src/config/base.ts +++ b/core/src/config/base.ts @@ -27,7 +27,7 @@ import { isNotNull, isTruthy } from "../util/util.js" import type { DeepPrimitiveMap, PrimitiveMap } from "./common.js" import { createSchema, joi } from "./common.js" import { emitNonRepeatableWarning } from "../warnings.js" -import type { ActionKind } from "../actions/types.js" +import type { ActionKind, BaseActionConfig } from "../actions/types.js" import { actionKinds } from "../actions/types.js" import { mayContainTemplateString } from "../template-string/template-string.js" import type { Log } from "../logger/log-entry.js" @@ -56,6 +56,11 @@ export interface YamlDocumentWithSource extends Document { source: string } +export function getEffectiveConfigFileLocation(actionConfig: BaseActionConfig): string { + const internal = actionConfig.internal + return !!internal.configFilePath ? dirname(internal.configFilePath) : internal.basePath +} + export interface GardenResourceInternalFields { /** * The path/working directory where commands and operations relating to the config should be executed. This is diff --git a/core/src/graph/actions.ts b/core/src/graph/actions.ts index 610a3e0c99..4550e001fd 100644 --- a/core/src/graph/actions.ts +++ b/core/src/graph/actions.ts @@ -34,7 +34,7 @@ import { BuildAction, buildActionConfigSchema, isBuildActionConfig } from "../ac import { DeployAction, deployActionConfigSchema, isDeployActionConfig } from "../actions/deploy.js" import { RunAction, runActionConfigSchema, isRunActionConfig } from "../actions/run.js" import { TestAction, testActionConfigSchema, isTestActionConfig } from "../actions/test.js" -import { noTemplateFields } from "../config/base.js" +import { getEffectiveConfigFileLocation, noTemplateFields } from "../config/base.js" import type { ActionReference, JoiDescription } from "../config/common.js" import { describeSchema, parseActionReference } from "../config/common.js" import type { GroupConfig } from "../config/group.js" @@ -456,8 +456,10 @@ async function processActionConfig({ config.internal.treeVersion || (await garden.vcs.getTreeVersion({ log, projectName: garden.projectName, config, scanRoot })) + const effectiveConfigFileLocation = getEffectiveConfigFileLocation(config) + let variables = await mergeVariables({ - basePath: config.internal.basePath, + basePath: effectiveConfigFileLocation, variables: config.variables, varfiles: config.varfiles, }) diff --git a/core/src/tasks/resolve-action.ts b/core/src/tasks/resolve-action.ts index 3ea89a0d16..50c5e05acf 100644 --- a/core/src/tasks/resolve-action.ts +++ b/core/src/tasks/resolve-action.ts @@ -157,9 +157,11 @@ export class ResolveActionTask extends BaseActionTask