Rebuild Container Without Cache does not add --no-cache when image is used #9803
Labels
containers
Issue in vscode-remote containers
info-needed
Issue requires more information from poster
Steps to Reproduce:
Create a
devcontainer.json
that specifies an image, for example:Add some features and let VScode build the container
Run Rebuild Container Without Cache from command palette
When done, run Dev Containers Developer: Show All Logs from command palette and select remoteContainers logs
Notice how the
docker buildx build
command has no--no-cache
argumentExample:
This means that features will not be rebuilt, instead previous cached layers are use, i.e. features are not updated.
Workaround:
Use a Dockerfile, for example:
FROM mcr.microsoft.com/devcontainers/base:jammy
and replace image in
devcontainer.json
with"build": { "dockerfile": "Dockerfile" }
When issuing Rebuild Container Without Cache no cached layers are used, and the features are rebuilt (and updated)
Fix
Demonstrated on the distributed extension.
In
ms-vscode-remote.remote-containers-0.354.0/dist/spec-node/devContainersSpecCLI.js
there is a function calledHc
.It has other names in other versions. Search for
if(e.buildKitVersion)
and you'll find the function.After the
else
branch, ifbuildNoCache
is true, add the argument--no-cache
to the arguments array.async function Hc(e, A, t, i, r, n) { ... code removed ... if (e.buildKitVersion) { Q.push("buildx", "build"), e.buildxPlatform && (g.write("Setting BuildKit platform(s): " + e.buildxPlatform, 1), Q.push("--platform", e.buildxPlatform)), e.buildxPush ? Q.push("--push") : e.buildxOutput ? Q.push("--output", e.buildxOutput) : Q.push("--load"), e.buildxCacheTo && Q.push("--cache-to", e.buildxCacheTo); for (let h in u.buildKitContexts) Q.push("--build-context", `${h}=${u.buildKitContexts[h]}`) } else Q.push("build"); + e.buildNoCache && Q.push("--no-cache");
The text was updated successfully, but these errors were encountered: