Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebuild Container Without Cache does not add --no-cache when image is used #9803

Closed
HCanber opened this issue Apr 21, 2024 · 2 comments
Closed
Assignees
Labels
containers Issue in vscode-remote containers info-needed Issue requires more information from poster

Comments

@HCanber
Copy link

HCanber commented Apr 21, 2024

  • VSCode Version: 1.88.1
  • Local OS Version: Sonoma 14.3.1 (23D60)

Steps to Reproduce:

  1. Create a devcontainer.json that specifies an image, for example:

    "image": "mcr.microsoft.com/devcontainers/base:jammy"
  2. Add some features and let VScode build the container

  3. Run Rebuild Container Without Cache from command palette

  4. When done, run Dev Containers Developer: Show All Logs from command palette and select remoteContainers logs

  5. Notice how the docker buildx build command has no --no-cache argument

    Example:

    [2024-04-21T15:26:38.518Z] Start: Run: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /var/folders/pc/r4mvs4_912gb84xl9rlkgt2m0000gn/T/devcontainercli/container-features/0.58.0-1713713196385/Dockerfile-with-features -t vsc-obfuscated-99814da1d4b66eb8eda6e1e435524bd84c473f6812b34850622eec2ecbbce2d5 --target dev_containers_target_stage --build-context dev_containers_feature_content_source=/var/folders/pc/r4mvs4_912gb84xl9rlkgt2m0000gn/T/devcontainercli/container-features/0.58.0-1713713196385 --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp /Users/obfuscated/obfuscated/.devcontainer
    

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 called Hc.
It has other names in other versions. Search for if(e.buildKitVersion) and you'll find the function.

After the else branch, if buildNoCache 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");
@vscodenpa vscodenpa added the containers Issue in vscode-remote containers label Apr 21, 2024
@chrmarti
Copy link
Contributor

This should be fixed with devcontainers/cli#790. Could you give the latest Dev Containers pre-release (currently 0.363.0-pre-release) a try?

@chrmarti chrmarti added the info-needed Issue requires more information from poster label Apr 30, 2024
@HCanber
Copy link
Author

HCanber commented May 5, 2024

I tested v0.364.0 (pre-release), and just by looking at the logs it looks correct, i.e --no-cache was added to the buildx command.
Thank you!

@chrmarti chrmarti closed this as completed May 6, 2024
@microsoft microsoft locked and limited conversation to collaborators Jun 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
containers Issue in vscode-remote containers info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants