https://pulumi.com logo
b

better-rainbow-14549

02/19/2020, 1:42 PM
i need to be able to throw an error during the preview step if a particular image tag doesn't exist in a particular docker repo so that we can reject a pull request which will ultimately fail. can anybody suggest a good way of doing this? is it going to be a matter of writing a dynamic provider?
l

limited-rainbow-51650

02/19/2020, 1:46 PM
No, use an
if
-statement with
pulumi.isDryRun
to check if you are in preview mode. Within the if block, check your tag values and throw
ResourceError
when not OK. https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/pulumi/runtime/#isDryRun https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/pulumi/#ResourceError
b

better-rainbow-14549

02/19/2020, 1:50 PM
ok interesting thanks, how about detecting the image presence
l

limited-rainbow-51650

02/19/2020, 1:51 PM
What do you mean with “the image presence” ?
b

better-rainbow-14549

02/19/2020, 1:51 PM
checking if the image is present on that repository
l

limited-rainbow-51650

02/19/2020, 1:52 PM
Well, for a Kubernetes deployment, if it can fetch the image, your deployment will be succesful. If not, your deployment will fail.
g

gentle-diamond-70147

02/19/2020, 3:55 PM
.getImage
will fail if it cannot find the image. You could potentially use that. https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/aws/ecr/#getImage
b

better-rainbow-14549

02/19/2020, 3:55 PM
i'm about to test
Copy code
export const verifyImageExistsInRegistry = (imageVersion: pulumi.Input<string>) =>
    pulumi.output(imageVersion).apply(async image => {
        try {
            await docker.getRegistryImage({ name: image });
        }
        catch (e) {
            new pulumi.ResourceError(`${image} metadata could not be loaded`, undefined);
        };
    });
is that likely to work against an ACR?
g

gentle-diamond-70147

02/19/2020, 3:58 PM
Do you mean Azure? Sorry, I just assumed AWS. Looks like we don't have an equivalent for Azure unfortunately, but your code using the Docker provider looks mostly good.
I say mostly because unfortunately you won't be able to catch the error if the getRegistryImage call fails.
b

better-rainbow-14549

02/19/2020, 3:59 PM
ah, how can i make pulumi fail-fast if its not there?
g

gentle-diamond-70147

02/19/2020, 4:00 PM
Pulumi will fail, you just can't handle the error yourself. The Pulumi engine itself will fail and exit.
https://github.com/pulumi/pulumi/issues/3364 tracks allowing you to handle the error itself.
b

better-rainbow-14549

02/19/2020, 4:00 PM
ah very interesting
thanks a lot
maybe i'm best doing this as a pre check before hitting pulumi until that issue's fixed then
i

icy-london-58403

02/19/2020, 8:24 PM
@limited-rainbow-51650 Just do your own logic and if the condition isn't satisfied do:
pulumi.log.error("error message")
💯 2
I use the
pulumi.log
stuff a lot. There is
.error
,
.warn
,
.info
,
.debug
. For example, the
debug
is really useful. They don't show unless you run
pulumi up
with the
-d
flag. Then you get all your debug outputs. Its super helpful when developing because you can get outputs that you don't normally want. I just put the
pulumi.log.error("test")
at the very first line of something I'm working on now and it errored the moment it hit it and didn't go any further and it took me right to the screenshot I posted. Should work perfect for what you need.