Any tips on speeding up this node docker build &am...
# general
r
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
Is that because locally you have a bunch of cached layers and remotely you're pulling / building everything?
r
Yes, it could be. How can i cache it locally? while also uploading the image to remote gcr
c
Well both node_modules and docker layers will cache automatically
r
well, that shouldn't be a problem then? or am i missing something
c
You're saying its fast locally and slower when building remotely? Or which case are you trying to solve?
r
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
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
its a install in windows WSL2, natively there though.
c
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
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
yep - but set cacheFrom to your own
imageName
r
c
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
right. the first build took only a minute, but updating it is still extremely slow. now at two minutes building and still going
c
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
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?