Skip to content

Commit

Permalink
fix(core): don't add mutating env vars to runtime context
Browse files Browse the repository at this point in the history
This was causing unnecessary re-deployments of container modules.
We had previously flagged this as a breaking change, but on reflection
this behavior is undocumented and should not have been used for a long
while now, and it's causing meaningful user issues.
  • Loading branch information
edvald authored and thsig committed Sep 29, 2021
1 parent 3fece6f commit 18c0f1d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 62 deletions.
14 changes: 0 additions & 14 deletions core/src/runtime-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { getEnvVarName } from "./util/util"
import { PrimitiveMap, joiEnvVars, joiPrimitive, joi, joiIdentifier, moduleVersionSchema } from "./config/common"
import { Garden } from "./garden"
import { ConfigGraph, DependencyRelations } from "./config-graph"
import { ServiceStatus } from "./types/service"
import { RunTaskResult } from "./types/plugin/task/runTask"
import { joiArray } from "./config/common"
import { isPrimitive } from "util"

interface RuntimeDependency {
moduleName: string
Expand Down Expand Up @@ -79,7 +77,6 @@ interface PrepareRuntimeContextParams {
* This should be called just ahead of calling relevant service, task and test action handlers.
*/
export async function prepareRuntimeContext({
garden,
dependencies,
serviceStatuses,
taskResults,
Expand All @@ -91,15 +88,6 @@ export async function prepareRuntimeContext({
GARDEN_MODULE_VERSION: moduleVersion,
}

// DEPRECATED: Remove in v0.13
for (const [key, value] of Object.entries(garden.variables)) {
// Only store primitive values, objects and arrays cause issues further down.
if (isPrimitive(value)) {
const envVarName = `GARDEN_VARIABLES_${getEnvVarName(key)}`
envVars[envVarName] = value
}
}

const result: RuntimeContext = {
envVars,
dependencies: [],
Expand Down Expand Up @@ -147,7 +135,5 @@ export async function prepareRuntimeContext({
})
}

// Make the full list of dependencies without outputs available as JSON as well
result.envVars.GARDEN_DEPENDENCIES = JSON.stringify(result.dependencies.map((d) => ({ ...d, outputs: undefined })))
return result
}
48 changes: 0 additions & 48 deletions core/test/unit/src/runtime-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { makeTestGardenA } from "../../helpers"
import { ConfigGraph } from "../../../src/config-graph"
import { prepareRuntimeContext } from "../../../src/runtime-context"
import { expect } from "chai"
import { omit } from "lodash"

describe("prepareRuntimeContext", () => {
let garden: Garden
Expand Down Expand Up @@ -44,29 +43,6 @@ describe("prepareRuntimeContext", () => {
expect(runtimeContext.envVars.GARDEN_MODULE_VERSION).to.equal(module.version.versionString)
})

it("should add project variables to the output envVars", async () => {
const module = graph.getModule("module-a")

garden["variables"]["my-var"] = "foo"

const runtimeContext = await prepareRuntimeContext({
garden,
graph,
version: module.version.versionString,
moduleVersion: module.version.versionString,
dependencies: {
build: [],
deploy: [],
run: [],
test: [],
},
serviceStatuses: {},
taskResults: {},
})

expect(runtimeContext.envVars.GARDEN_VARIABLES_MY_VAR).to.equal("foo")
})

it("should add outputs for every build dependency output", async () => {
const module = graph.getModule("module-a")
const moduleB = graph.getModule("module-b")
Expand Down Expand Up @@ -184,28 +160,4 @@ describe("prepareRuntimeContext", () => {
},
])
})

it("should output the list of dependencies as an env variable", async () => {
const module = graph.getModule("module-a")
const serviceB = graph.getService("service-b")
const taskB = graph.getTask("task-c")

const runtimeContext = await prepareRuntimeContext({
garden,
graph,
version: module.version.versionString,
moduleVersion: module.version.versionString,
dependencies: {
build: [],
deploy: [serviceB],
run: [taskB],
test: [],
},
serviceStatuses: {},
taskResults: {},
})

const parsed = JSON.parse(runtimeContext.envVars.GARDEN_DEPENDENCIES as string)
expect(parsed).to.eql(runtimeContext.dependencies.map((d) => omit(d, "outputs")))
})
})

0 comments on commit 18c0f1d

Please sign in to comment.