https://pulumi.com logo
#general
Title
# general
c

curved-pharmacist-41509

03/10/2021, 3:21 AM
Is the preview phase skipped for a new stack? We seem to have an issue where the first
up
doesn’t run code which is checking for
isDryMode()
w

white-balloon-205

03/10/2021, 3:32 AM
No. Preview runs on initial stack preview. Any more details you can share?
c

curved-pharmacist-41509

03/10/2021, 3:58 AM
Yep, two secs
Copy code
import * as pulumi from '@pulumi/pulumi'
import { runCommandThatMustSucceed } from './run-command'

export interface BuildStepArgs {
    /**
     * The command to run
     */
    command: pulumi.Input<string>
    /**
     * The command arguments
     */
    args: pulumi.Input<string[]>

    /**
     * The cwd of the command
     */
    cwd?: pulumi.Input<string>

    /**
     * The env of the command
     */
    env?: {
        [key: string]: pulumi.Input<string>
    }
}

export class BuildStep extends pulumi.ComponentResource {
    public buildStdOut: pulumi.Output<string>
    public done: pulumi.Output<boolean>

    constructor(
        name: string,
        args: BuildStepArgs,
        opts?: pulumi.ComponentResourceOptions,
    ) {
        super('build-step', name, {}, opts)

        const buildStdOut = pulumi.output(args).apply(async (buildArgs) => {
            if (
                (pulumi.runtime.isDryRun() &&
                    !pulumi.runtime.isTestModeEnabled())
            ) {
                const stdOut = await runCommandThatMustSucceed({
                    cmd: buildArgs.command,
                    args: buildArgs.args,
                    cwd: buildArgs.cwd,
                    logResource: this,
                    reportFullCommandLine: true,
                    env: buildArgs.env,
                })

                return stdOut
            }

            return 'Build run during preview'
        })

        this.buildStdOut = buildStdOut
        this.done = buildStdOut.apply(() => true)

        this.registerOutputs({
            buildStdOut: this.buildStdOut,
            done: this.done,
        })
    }
}
This is a resource inspired by your docker build, just a bit more generic.
We are just noticing that one of our build steps is not being run when we first
up
a stack. It works on subsequent `up`s
2 Views