Skip to content

BUILDKIT_INLINE_CACHE not added to docker buildx build command for Image-Based builds #1134

@ross-p-smith

Description

@ross-p-smith

When you define a devcontainer with the following devcontainer.json

{
  "build": {
    "dockerfile": "Dockerfile"
  }
}

Then when you run devcontainer build this will translate to

docker buildx build --push --build-arg BUILDKIT_INLINE_CACHE=1 . . .

However, if your devcontainer is defined as (example)

{
  "image": "mcr.microsoft.com/devcontainers/python:3.12",
}

Then the BUILDKIT_INLINE_CACHE=1 is not added to the build.

Additionally, I was unaware of this quirk and I had

  - name: Build and push devcontainer cache
    run: |
      devcontainer build \
        --workspace-folder . \
        --image-name ghcr.io/azure-samples/xxxxt:latest \
        --cache-from ghcr.io/azure-samples/xxxxx:latest \
        --cache-to type=inline \
        --push

When I switched over to the Dockerfile mechanism, you will then get a conflict where --cache-to type=inline and 'BUILDKIT_INLINE_CACHE=1' conflict with each other.

I would suggest that BUILDKIT_INLINE_CACHE=1 is added always when Buildkit is enabled. This would mean adding it to containerFeatures.ts - it is already added for singleContainer.ts and dockerCompose.ts to make everything consistent.

Then if someone adds --cache-to type=inline - this doesnt get added to prevent duplication. If they use other types, then this should be added to the command

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions