‘Support buildkit’ has been one of the most requested features in Bitbucket Pipelines for quite some time now (refer to this ticket from our public open issues). With Bitbucket Pipelines runners now released, you can specify your step to use a custom ‘dind’, which allows you to use the supported feature like ‘buildkit’ with Bitbucket Pipelines. Here’s how it works:
First, define a docker service with docker in the docker image (dind). Since the current docker:dind is already enabled in buildkit by default, you can just use it (as shown below):
definitions:
services:
docker:
image: docker:dind
Then in your Pipeline step, there are couple different ways to use buildkit:
DOCKER_BUILDKIT
env varpipelines:
default:
- step:
name: Step 1
runs-on: self.hosted
script:
- export DOCKER_BUILDKIT=1
- docker build .
services:
- docker
definitions:
services:
docker:
image: docker:dind
Here is the output:
docker buildx
commandsUnfortunately, Bitbucket Pipelines default build image doesn’t have the buildx
plugin installed. So this process is a bit more involved:
Install buildx
in the build image:
FROM atlassian/default-image:2
COPY --from=docker/buildx-bin /buildx /usr/libexec/docker/cli-plugins/docker-buildx
Then push it to a docker host so runners can use it.
pipelines:
default:
- step:
name: Step 1
image: dockerhub-user-name/test-build-image
runs-on: self.hosted
script:
- docker
- docker buildx version
- docker buildx build .
services:
- docker
definitions:
services:
docker:
image: docker:dind
Here is the output:
lliang2
0 comments