https://pulumi.com logo
Title
r

refined-pilot-45584

01/23/2023, 1:12 PM
Hey all! Using the GCP provider to launch cloud run services. I am combining it with Docker build. Using obviously the Docker provider. I see the image builds successfully and it even get pushed. However the Cloud Run service update with the new image name and tag doesn’t wait for the push command to complete before the Cloud Run service update occurs. Naturally I receive an error telling me the image can’t be found.. Am I missing something or is there a simple way to ensure the cloud run service update only occurs after the Docker push is complete? I have tried Standard “depends on” and references between the resources. If it helps/makes a difference I am using Go. Cheers in advance.
r

rich-motorcycle-3089

01/23/2023, 6:37 PM
We are also using Cloud Run with a Docker build in Go, so I figured I should chime in here. I should qualify that I didn’t actually write the code that I’m reading while answering this question, my colleague did. First we either use the supplied docker image and tag (if already built and pushed to artifacts registry)
docker.NewImage(ctx, getName(ctx), &docker.ImageArgs{
	ImageName: pulumi.String(imageName),
	Build:     &docker.DockerBuildArgs{
        Context: pulumi.String(dockerCtx),
    },
	// Empty registry args to use auto gcloud credentials
	Registry: docker.ImageRegistryArgs{},
})
This image is then used to obtain an image name and is fed into a ServiceTemplateArgs object to fulfill the Template argument of the service. (Image attached) At this point, we use a
pulumi.DependsOn(ctx.DockerImage)
object like you’ve mentioned when constructing the
cloudrunv2.NewService
object. (Image attached)
It would appear this seems to work in our case. It sounds like it included all the same steps you took. If you need specific details or lines of code, I’m willing to help. Just let me know where it might be fuzzy for you.
@bitter-train-58221
b

bitter-train-58221

01/23/2023, 7:00 PM
Hi, Tim. According to pulumi’s doc, the depends parameter is the key to have cloud run service to hold on updating until the image is pushed. Try log the dockerImage variable you passed in and make sure it’s not null. Brian has shown most of the details how we did it. LMK if you still need more help
r

refined-pilot-45584

01/23/2023, 7:06 PM
Hey @rich-motorcycle-3089 and @bitter-train-58221 appreciate the insights. I’ll review the code you have shared and explore my implementation. If you don’t mind I might hit you both up if I can’t work it out and see if you can give me any additional insights. Thanks so much for your help!
r

rich-motorcycle-3089

01/23/2023, 7:14 PM
Yep, feel free
r

refined-pilot-45584

01/23/2023, 7:15 PM
Cheers Gents
Yeah; So I went back and tried this. I have put the dependency in; I am certain it is there. I am not sure what is going on. But the Cloud Run objects still don’t seem to wait for the Build AND push of the image ti complete. It’s really strange. I will include some screenshots.
This is the Build object
The Cloud Run service references this image:
with the dependency defined as follows:
Pulumi Up; Builds the Images on preview.
apply
It doesn’t wait..
image.png
image.png
Okay; So after Smashing my head against the wall for some hours… There is a subtle but important difference between “ImageName” and “BaseImageName” I was referencing BaseImageName and this isn’t correct. I needed to reference the ImageName in my CloudRunService.
b

bitter-train-58221

01/24/2023, 10:19 PM
by looking at the error, It seems more like the image is not found tho, and the cloudrun deployment indeed ran after the docker image is pushed 1. Are you sure the image is in that registry? 2. Can you try only deploying the cloudrun with certain existing image name and see if that works?
r

rich-motorcycle-3089

01/25/2023, 1:29 AM
Sorry Tim, apparently my Slack notifications are off for the Pulumi workspace haha. It sounds like you may have discovered the underlying issue. Is your environment running now? I’m not sure what
BaseImageName
is referencing, but perhaps Pulumi was concluding the image that it points to did in fact exist and the dependency was met so it didn’t need to wait any further.
Based on the docs, it reads to me that it might be the image name minus any tagging or sha annotations. Therefore, dependsOn may have been checking for any version of the image to exist in the registry. https://www.pulumi.com/registry/packages/docker/api-docs/image/#outputs
I turned on notification for threads as well. Maybe that’s why I didn’t see this. If I go dark feel free to DM me to get my attention
r

refined-pilot-45584

01/25/2023, 7:37 AM
Heys all; No problems about the notifications. Its also a battle of the timezones. It was driving me crazy but you are right it is now solved. ImageName” vs “BaseImageName” was the underlying issue. To clarify further. The Image was 100% in the Repository by the end of all things. However in the original configuration when using BaseImageName was not working for dependency. So I could see it pushing the image after all my CloudRun services had updated. Having switched to ImageName all was resolved immediately. The dependancy graph worked exactly as you would expect it too and with the correct Tags also. Which would have been the next sticking point.