Reputation: 81
i'm looking for a way to use the docker buildkit with az acr build. I know that its possible with azure pipeline but how to use it with the azure cli?
Regards, Jürgen
Upvotes: 7
Views: 996
Reputation: 66
To clarify a bit on what 0gis0 said, and to confirm that it is indeed a working solution, the steps to use buildkit with az acr
cli are as follows. At the time of posting, you cannot do it via ac acr build
, but instead must use az acr run
:
Create a Dockerfile
, using some feature only available in buildkit. For example, cache mounting:
# syntax = docker/dockerfile:1.2
# See https://vsupalov.com/buildkit-cache-mount-dockerfile/ for details
FROM ghcr.io/linuxcontainers/debian-slim:latest
RUN rm -f /etc/apt/apt.conf.d/docker-clean
RUN --mount=type=cache,target=/var/cache/apt \
apt-get update && \
apt-get install -yqq --no-install-recommends \
cowsay && rm -rf /var/lib/apt/lists/*
CMD [ "cowsay", "moo" ]
Create an acr task file, setting DOCKER_BUILDKIT=1
in the environment of the acr build step. Make sure you specify a push step if you want to push, and make good use of dynamic task variables. Call this file something like acr-task.yml
:
version: v1.1.0
steps:
- build: -t $Registry/{{.Values.image}} .
env:
- DOCKER_BUILDKIT=1
- push:
- "$Registry/{{.Values.image}}"
Run the file on acr, making sure to set the variable(s) you need for the acr task file:
az acr run -f acr-task.yml --registry <YOUR_REGISTRY> --set image="<REPO>:<TAG>" .
Upvotes: 0
Reputation: 39
You can use multi-step tasks in ACR in order to set DOCKER_BUILD=1 like this:
version: v1.1.0
steps:
- build: -t $Registry/backstage:$ID -f packages/backend/Dockerfile .
env:
- DOCKER_BUILDKIT=1
- push:
- "$Registry/backstage:$ID"
I wrote an article about this (But It's in Spanish ☺️): https://www.returngis.net/2024/05/como-construir-una-imagen-en-azure-container-registry-usando-buildkit/
Hope it helps!
Upvotes: 0