Skip to content

Commit

Permalink
fix(build): ensure that exec modules are rebuilt on when garden is run
Browse files Browse the repository at this point in the history
Prior to this commit, garden would skip building exec modules that had been built during a previous garden run, if none of the source files in the module changed.

While this is a good optimisation, it caused problems because staging would still happen, wiping out any previously built artifacts which other modules might have depended on.  Also, there is no way to guarantee/specify at the module level that there are no outside dependencies that aren't captured by the module's sources.

It is planned to properly support this in the future, but removing this optimisation for now.
  • Loading branch information
khaled authored and edvald committed Dec 14, 2019
1 parent 8009310 commit 4d2ccce
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 37 deletions.
21 changes: 1 addition & 20 deletions garden-service/src/plugins/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ import { createGardenPlugin } from "../types/plugin/plugin"
import { Module } from "../types/module"
import { CommonServiceSpec } from "../config/service"
import { BaseTestSpec, baseTestSpecSchema } from "../config/test"
import { readModuleVersionFile, writeModuleVersionFile, ModuleVersion } from "../vcs/vcs"
import { writeModuleVersionFile } from "../vcs/vcs"
import { GARDEN_BUILD_VERSION_FILENAME } from "../constants"
import { ModuleSpec, BaseBuildSpec, baseBuildSpecSchema, ModuleConfig } from "../config/module"
import { BaseTaskSpec, baseTaskSpecSchema } from "../config/task"
import { dedent } from "../util/string"
import { ConfigureModuleParams, ConfigureModuleResult } from "../types/plugin/module/configure"
import { GetBuildStatusParams, BuildStatus } from "../types/plugin/module/getBuildStatus"
import { BuildModuleParams, BuildResult } from "../types/plugin/module/build"
import { TestModuleParams } from "../types/plugin/module/testModule"
import { TestResult } from "../types/plugin/module/getTestResult"
Expand Down Expand Up @@ -200,23 +199,6 @@ export async function configureExecModule({
return { moduleConfig }
}

export async function getExecModuleBuildStatus({ module }: GetBuildStatusParams): Promise<BuildStatus> {
const buildVersionFilePath = join(module.buildMetadataPath, GARDEN_BUILD_VERSION_FILENAME)
let builtVersion: ModuleVersion | null = null

try {
builtVersion = await readModuleVersionFile(buildVersionFilePath)
} catch (_) {
// just ignore this error, can be caused by an outdated format
}

if (builtVersion && builtVersion.versionString === module.version.versionString) {
return { ready: true }
}

return { ready: false }
}

export async function buildExecModule({ module }: BuildModuleParams<ExecModule>): Promise<BuildResult> {
const output: BuildResult = {}
const { command } = module.spec.build
Expand Down Expand Up @@ -353,7 +335,6 @@ export const execPlugin = createGardenPlugin({
}),
handlers: {
configure: configureExecModule,
getBuildStatus: getExecModuleBuildStatus,
build: buildExecModule,
runTask: runExecTask,
testModule: testExecModule,
Expand Down
18 changes: 1 addition & 17 deletions garden-service/test/unit/src/plugins/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { LogEntry } from "../../../../src/logger/log-entry"
import { keyBy } from "lodash"
import { getDataDir, makeTestModule, expectError } from "../../../helpers"
import { TaskTask } from "../../../../src/tasks/task"
import { writeModuleVersionFile, readModuleVersionFile } from "../../../../src/vcs/vcs"
import { readModuleVersionFile } from "../../../../src/vcs/vcs"
import { dataDir, makeTestGarden } from "../../../helpers"
import { ModuleConfig } from "../../../../src/config/module"
import { ConfigGraph } from "../../../../src/config-graph"
Expand Down Expand Up @@ -249,22 +249,6 @@ describe("exec plugin", () => {
})
})

describe("getBuildStatus", () => {
it("should read a build version file if it exists", async () => {
const module = await graph.getModule(moduleName)
const version = module.version
const buildMetadataPath = module.buildMetadataPath
const versionFilePath = join(buildMetadataPath, GARDEN_BUILD_VERSION_FILENAME)

await writeModuleVersionFile(versionFilePath, version)

const actions = await garden.getActionRouter()
const result = await actions.getBuildStatus({ log, module })

expect(result.ready).to.be.true
})
})

describe("build", () => {
it("should write a build version file after building", async () => {
const module = await graph.getModule(moduleName)
Expand Down

0 comments on commit 4d2ccce

Please sign in to comment.