-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to use dynamic build property #620
Comments
We tried creating a fake |
Hey @wvanderdeijl thanks for reporting this. I can suggest a workaround to try here: import * as docker from "@pulumi/docker";
import { interpolate, output, runtime } from "@pulumi/pulumi";
import * as random from '@pulumi/random';
const apiKey = new random.RandomUuid('guid', {}).result
if (!runtime.isDryRun()) {
new docker.Image(
'image',
{
imageName: 'eu.gcr.io/my-project/foo:v1.0.0',
build: {
dockerfile: interpolate`./foo.Dockerfile`,
platform: 'linux/arm64',
args: {
KEY: apiKey,
},
},
skipPush: true,
},
);
} This will skip evaluating the Docker.Image during previews, ensuring that the If this works for you, let us know - we may file a follow up issue to track improving preview behavior. |
That's a great tip. I'm now using that in a slightly different way. Still creating the |
A somewhat bizarre fix for #676 ### Problem Let me try to explain what is going on in #676. The relevant snippet is (same as in the new test): ``` const image = new docker.Image("my-image", { build: { context: "app", cacheFrom: { images: [imageName] }, } ``` Where `imageName` depends on another resource R. In the problematic scenario, the resource R is being replaced, which turns `imageName` into unknown. Unfortunately, this turns the entire `build` object into a big unknown instead of the desired effect of it keeping its shape with only an unknown value inside `cacheFrom`. Here is a gRPC log: ``` {"build":"04da6b54-80e4-46f7-96ec-b56ff0331ba9","imageName":"04da6b54-80e4-46f7-96ec-b56ff0331ba9","registry":{"password":"04da6b54-80e4-46f7-96ec-b56ff0331ba9","server":"04da6b54-80e4-46f7-96ec-b56ff0331ba9","username":"04da6b54-80e4-46f7-96ec-b56ff0331ba9"},"skipPush":false} ``` It turns out that `build` is unknown because of the current implementation of Node.js codegen that sets the parent object as unknown if that object needs a default value (see [here](https://github.com/pulumi/pulumi-docker/blob/24161acd0433b061e3b5acfa128b9ddb599b965b/sdk/nodejs/image.ts#L177)). We then discard unknowns [here](https://github.com/pulumi/pulumi-docker/blob/24161acd0433b061e3b5acfa128b9ddb599b965b/provider/provider.go#L131) and proceed with filling default build properties in [`marshalBuildAndApplyDefaults`](https://github.com/pulumi/pulumi-docker/blob/24161acd0433b061e3b5acfa128b9ddb599b965b/provider/provider.go#L139), which causes the issue because `Dockerfile` is not available at its default location. ### Fix We don't really need to set the default `builderVersion` value in the schema. We assume the same default value in [`marshalBuilder`](https://github.com/pulumi/pulumi-docker/blob/24161acd0433b061e3b5acfa128b9ddb599b965b/provider/image.go#L563) and cover this scenario with a few unit tests ([example](https://github.com/pulumi/pulumi-docker/blob/24161acd0433b061e3b5acfa128b9ddb599b965b/provider/image_test.go#L55)). Therefore, in this PR I chose to remove the default value from schema and SDKs and, as a side effect, avoid turning `build` into an unknown. ### Test I tested it manually and adjusted the ACR test into a two-step test that exercises the scenario. You can see the test fail before my change [here](https://github.com/pulumi/pulumi-docker/actions/runs/6510330782/job/17684951125#step:27:166). Also added another test to validate #620. Fix #676 Fix #620
This pull request's intent is to allow a user to build their image during `pulumi preview` by using the new `buildOnPreview` resource field. This field is added to the Image schema as a boolean and defaults to false. The implementation specifics are as follows, with some things for the reviewer to weigh in on. 1. As a prerequisite, `supportPreview` is enabled and all implemented RPD methods should handle Unknowns. This should also help address #847 and #620. 2. `ContainsUnknowns()` checks are added to the marshaler and some of the `Check()` logic. I wasn't sure if `ContainsUnknowns()` or `IsComputed()`should be used here; the former contains a check for the latter. 3. Unit tests verify the new marshaling behavior. 4. When a Dockerfile is Unknown, we do not verify its location during Preview `Check()`, instead we apply other defaults and carry on. We will calculate the build hash on the `update` call once Unknowns are computed. 5. When in preview mode, and buildOnPreview is false, we return all inputs as-is in Update() and Create(). 6. When an attempt is made to build on preview, but there are Unknowns in the inputs or news, we send an error instructing the user to set `buildOnPreview` to false. 7. An integration test is added that verifies an image builds on preview if the `buildOnPreview` flag is set to true. 8. An integration test is added that verifies an image _fails_ to build on preview if there are Unknown inputs and the `buildOnPreview` flag is set to true Fixes #540. - Handle unknowns in Build object - Handle unknowns in Check; skip dockerfile location finding. - Set SupportPreview to true - Add ContainsUnknowns() checks for build: target, stages, platform, Dockerfile, Context; and registry: username, password, server - Add tests for Unknowns, and tweak Unknown checks as a result of a bit of TDD - Add logic to imageBuild that allows for buildOnPreview - Use Command.stdout to test unknowns - Add a few more Unknown checks in Check() - Add an integration test for Build On Preview - Build SDKs --------- Co-authored-by: Bryce Lampe <[email protected]>
What happened?
When the
build
property to theImage
resource is dynamic apulumi preview
fails since all command line arguments appear to be missing. This means our customfoo.Dockerfile
is not being used and docker tries to use the defaultDockerfile
resulting in the following error:Expected Behavior
pulumi preview
should not fail.Steps to reproduce
Full example at https://github.com/wvanderdeijl/docker-pulumi-issue
Output of
pulumi about
CLI
Version 3.65.1
Go Version go1.20.3
Go Compiler gc
Plugins
NAME VERSION
docker 4.2.0
nodejs unknown
random 4.13.0
Host
OS darwin
Version 13.3.1
Arch arm64
This project is written in nodejs: executable='/Users/*****/.nvm/versions/node/v16.17.1/bin/node' version='v16.17.1'
Backend
Name pulumi.com
URL https://app.pulumi.com/*****
User *****
Organizations *****, *****
Dependencies:
NAME VERSION
@pulumi/docker 4.2.0
@pulumi/pulumi 3.65.1
@pulumi/random 4.13.0
@types/node 16.18.25
Pulumi locates its logs in /var/folders/16/6r7yw0gd7593qv1z1zsp6xbh0000gn/T/ by default
warning: Failed to get information about the current stack: No current stack
Additional context
When running a
pulumi preview
orpulumi up
with--logtostderr --logflow -v=9 2> out.txt
we can see in the logging that thebuild
property is now a simpleoutput<string>
meaning the information fordockerfile
(andplatform
) have been lost:Contributing
Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).
The text was updated successfully, but these errors were encountered: