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

rich-alligator-53421

09/13/2023, 10:24 AM
Any tips on speeding up this node docker build & deployment. it takes often > 5 minutes, while locally building is around 10-20seconds. I'll post my code into thread
const registry = new gcp.container.Registry("image-registry", {}, { retainOnDelete: true }); const registryUrl = registry.id.apply(_ => gcp.container.getRegistryRepository().then(reg => reg.repositoryUrl)); const imageName = registryUrl.apply(url =>
${url}/cloud-run-test-image
); const image = new docker.Image("cloud-run-test-image", { build: { context: "cloud-run-test/", dockerfile: "cloud-run-test/Dockerfile", }, imageName, }, { retainOnDelete: true });
"dependencies": { "@pulumi/docker": "^4.3.1", "@pulumi/gcp": "^6.0.0", "@pulumi/pulumi": "^3.0.0" }
c

cuddly-computer-18851

09/13/2023, 10:35 AM
Is that because locally you have a bunch of cached layers and remotely you're pulling / building everything?
r

rich-alligator-53421

09/13/2023, 10:35 AM
Yes, it could be. How can i cache it locally? while also uploading the image to remote gcr
c

cuddly-computer-18851

09/13/2023, 10:36 AM
Well both node_modules and docker layers will cache automatically
r

rich-alligator-53421

09/13/2023, 10:36 AM
well, that shouldn't be a problem then? or am i missing something
c

cuddly-computer-18851

09/13/2023, 10:37 AM
You're saying its fast locally and slower when building remotely? Or which case are you trying to solve?
r

rich-alligator-53421

09/13/2023, 10:38 AM
Yes, so normal docker build command locally is fast as it supposed to be. however pulumi up is slow, "dockerindexImage cloud-run-test-image updated (595s) [diff: ~build]; 1 message". the message mentioned is about not specifying build platform
and the building image part of the update is the slowest. uploading seems to be fast.
c

cuddly-computer-18851

09/13/2023, 10:40 AM
Are you running pulumi via a native install or from within a docker run command? My guess is whatever context pulumi is building is is not re-using the docker layer cache
r

rich-alligator-53421

09/13/2023, 10:41 AM
its a install in windows WSL2, natively there though.
c

cuddly-computer-18851

09/13/2023, 10:43 AM
can you try adding these to your Image() parameters?
``` args: {
"BUILDKIT_INLINE_CACHE": "1"
},
builderVersion: "BuilderBuildKit", // can also be set to `BuilderV1````
and possibly
``` cacheFrom: {
images: ["docker.io/pulumibot/demo-image:cache-base"]
},```
with
images
set to your registry+image
r

rich-alligator-53421

09/13/2023, 10:46 AM
Sure, into the build json? like this: const image = new docker.Image("cloud-run-test-image", { build: { context: "cloud-run-test/", dockerfile: "cloud-run-test/Dockerfile", args: { "BUILDKIT_INLINE_CACHE": "1" }, builderVersion: "BuilderBuildKit", cacheFrom: { images: ["docker.io/pulumibot/demo-image:cache-base"] }, }, imageName, }, { retainOnDelete: true }); export const endpoint = registryUrl
c

cuddly-computer-18851

09/13/2023, 10:48 AM
yep - but set cacheFrom to your own
imageName
r

rich-alligator-53421

09/13/2023, 10:49 AM
c

cuddly-computer-18851

09/13/2023, 10:50 AM
Copy code
const image = new docker.Image("cloud-run-test-image", {
    build: {
        context: "cloud-run-test/",
        dockerfile: "cloud-run-test/Dockerfile",
        args: {
            "BUILDKIT_INLINE_CACHE": "1"
        },
        builderVersion: "BuilderBuildKit",
        cacheFrom: {
            images: [imageName]
        },
    },
    imageName,
}, { retainOnDelete: true });
r

rich-alligator-53421

09/13/2023, 11:00 AM
right. the first build took only a minute, but updating it is still extremely slow. now at two minutes building and still going
c

cuddly-computer-18851

09/13/2023, 11:08 AM
Hmm maybe from the debug pulumi output you can see the full list of arguments its passing to docker and isolate why its not caching. Also check you're not cross compiling arm64 <-> x86 or something. Is your Dockerfile doing a multi-stage build or anything complex?
r

rich-alligator-53421

09/13/2023, 11:11 AM
How do i get the debug output? Nope, the build is just a npm install and copies. I shouldn't be cross compiling, ill add the platform specification though
here are the arguments, https://pastebin.com/gTGWVG7K
Right, so it takes around 3mins now to build. What I think is missing, is that it might be picking a older image to use as cache, which results in more missing layers and therefore longer build. is it possible for pulumi to tag latest or somehow figure the latest image to use?
2 Views