Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Use buildkit with Bitbucket Pipelines runners

‘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:

Define a custom ‘dind’

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:

Enable buildkit with DOCKER_BUILDKIT env var

pipelines:
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:

Screen Shot 2021-10-01 at 11.35.45 am.png

 

Interact with BuildKit through docker buildx commands

Unfortunately, Bitbucket Pipelines default build image doesn’t have the buildx plugin installed. So this process is a bit more involved:

Setup custom build image

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.

Config Step to use custom build image

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:

Screen Shot 2021-10-01 at 11.57.46 am.png

0 comments

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events