-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(pulumi): include build deps in plugin commands (#6260)
In 0.12, we included build dependencies for Pulumi modules (e.g. when previewing). A build dependency (e.g. on an `exec` Module or Build) is a common way to ensure that the relevant language SDK is installed for the module/action before running Pulumi. We didn't bring this logic along when we adapted the Pulumi plugin commands for 0.13—this is fixed here. Also added a lightweight test project to test this logic (which should also serve us well when making further fixes to this plugin).
- Loading branch information
Showing
33 changed files
with
11,119 additions
and
3,379 deletions.
There are no files selected for viewing
3,886 changes: 2,249 additions & 1,637 deletions
3,886
examples/pulumi/k8s-deployment/package-lock.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
config: | ||
kubernetes:context: docker-desktop | ||
pulumi-k8s:namespace: pulumi-k8s | ||
backend: | ||
url: https://api.pulumi.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3,898 changes: 2,254 additions & 1,644 deletions
3,898
examples/pulumi/k8s-namespace/package-lock.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"ignorePatterns": ["test-project*/"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (C) 2018-2024 Garden Technologies, Inc. <info@garden.io> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { dirname, join, resolve } from "path" | ||
import { fileURLToPath } from "node:url" | ||
import fsExtra from "fs-extra" | ||
import type { ResolvedConfigGraph } from "@garden-io/core/build/src/graph/config-graph.js" | ||
import type { PluginContext } from "@garden-io/core/build/src/plugin-context.js" | ||
import { makeTestGarden, type TestGarden } from "@garden-io/sdk/build/src/testing.js" | ||
import type { Log } from "@garden-io/sdk/build/src/types.js" | ||
import type { PulumiProvider } from "../src/provider.js" | ||
import { gardenPlugin as pulumiPlugin } from "../src/index.js" | ||
import { ensureNodeModules } from "./test-helpers.js" | ||
import { getPulumiCommands } from "../src/commands.js" | ||
import { expect } from "chai" | ||
|
||
const moduleDirName = dirname(fileURLToPath(import.meta.url)) | ||
|
||
// Careful here! | ||
// We have some packages in the test directory but when this here runs we're a subfolder of '/build' | ||
// so to actually find the files we need to traverse back to the source folder. | ||
// TODO: Find a better way to do this. | ||
const projectRoot = resolve(moduleDirName, "../../test/", "test-project-local-script") | ||
|
||
const deployARoot = join(projectRoot, "deploy-a") | ||
const deployBRoot = join(projectRoot, "deploy-b") | ||
|
||
// Looking for log entries indicating that these exec actions had run proved to be flaky, so we're using the | ||
// more robust method of touching a file in the source dir to indicate that the action was run. | ||
const buildAFile = join(deployARoot, "build-a.txt") | ||
const runAFile = join(deployARoot, "run-a.txt") | ||
|
||
const buildBFile = join(deployBRoot, "build-b.txt") | ||
const runBFile = join(deployBRoot, "run-b.txt") | ||
|
||
async function clearGeneratedFiles() { | ||
await Promise.all( | ||
[buildAFile, runAFile, buildBFile, runBFile].map(async (path) => { | ||
try { | ||
await fsExtra.remove(path) | ||
} catch (err) { | ||
// This file may not exist, we're just cleaning up in case of repeated test runs. | ||
} | ||
}) | ||
) | ||
} | ||
|
||
describe("pulumi plugin commands", () => { | ||
let garden: TestGarden | ||
let graph: ResolvedConfigGraph | ||
let ctx: PluginContext | ||
let log: Log | ||
let provider: PulumiProvider | ||
|
||
before(async () => { | ||
await ensureNodeModules([deployARoot, deployBRoot]) | ||
const plugin = pulumiPlugin() | ||
garden = await makeTestGarden(projectRoot, { plugins: [plugin] }) | ||
log = garden.log | ||
provider = (await garden.resolveProvider({ log, name: "pulumi" })) as PulumiProvider | ||
ctx = await garden.getPluginContext({ provider, templateContext: undefined, events: undefined }) | ||
graph = await garden.getResolvedConfigGraph({ log, emit: false }) | ||
await clearGeneratedFiles() | ||
}) | ||
|
||
after(async () => { | ||
await clearGeneratedFiles() | ||
}) | ||
|
||
// Note: Since the stacks in this test project don't have any side-effects, we don't need an after-cleanup step here. | ||
|
||
describe("preview command", () => { | ||
it("executes Build dependencies, but not Run dependencies", async () => { | ||
const previewCmd = getPulumiCommands().find((cmd) => cmd.name === "preview")! | ||
await previewCmd.handler({ garden, ctx, args: [], graph, log }) | ||
expect(await fsExtra.pathExists(buildAFile), "build-a.txt should exist").to.eql(true) | ||
expect(await fsExtra.pathExists(buildBFile), "build-b.txt should exist").to.eql(true) | ||
expect(await fsExtra.pathExists(runAFile), "run-a.txt should not exist").to.eql(false) | ||
expect(await fsExtra.pathExists(runBFile), "run-b.txt should not exist").to.eql(false) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.