Skip to content

Commit

Permalink
fix: handling varfiles in remote actions (#6147)
Browse files Browse the repository at this point in the history
* fix: handling varfiles with helm sources

Signed-off-by: Manuel Ruck <git@manuelruck.de>

* refactor: 馃Ч reuse basePath

Signed-off-by: Manuel Ruck <git@manuelruck.de>

* test(e2e): add varfiles to `remote-sources` e2e test

* refactor: helpers for effective config file's dir resolution

---------

Signed-off-by: Manuel Ruck <git@manuelruck.de>
Co-authored-by: Manuel Ruck <git@manuelruck.de>
Co-authored-by: Vladimir Vagaytsev <vladimir.vagaitsev@gmail.com>
  • Loading branch information
3 people committed Jun 10, 2024
1 parent d0a99da commit 4d9026f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
7 changes: 7 additions & 0 deletions core/src/actions/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion core/src/config/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions core/src/graph/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
})
Expand Down
4 changes: 3 additions & 1 deletion core/src/tasks/resolve-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ export class ResolveActionTask<T extends Action> extends BaseActionTask<T, Resol
})
}

const basePath = action.effectiveConfigFileLocation()

const actionVariables = resolveTemplateStrings({
value: await mergeVariables({
basePath: action.sourcePath(),
basePath,
variables: config.variables,
varfiles: config.varfiles,
}),
Expand Down
1 change: 1 addition & 0 deletions examples/remote-sources/worker/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FOO=bar
4 changes: 4 additions & 0 deletions examples/remote-sources/worker/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ source:
repository:
url: https://github.com/garden-io/garden-example-remote-module-jworker.git#main

# Do not delete, this must be resolved from the current path, not from the cloned sourced path
varfiles:
- ./.env

---
kind: Deploy
description: The worker that collects votes and stores results in a postgres table
Expand Down

0 comments on commit 4d9026f

Please sign in to comment.