From e5ad4b88af465e4730353b80aa4f785f1bd68d24 Mon Sep 17 00:00:00 2001 From: David Karlsson <35727626+dvdksn@users.noreply.github.com> Date: Wed, 25 Oct 2023 11:30:42 +0200 Subject: [PATCH] build(hb): add buildkite example Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com> --- content/build/hydrobuild.md | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/content/build/hydrobuild.md b/content/build/hydrobuild.md index 207093939a..e1c3062883 100644 --- a/content/build/hydrobuild.md +++ b/content/build/hydrobuild.md @@ -354,6 +354,84 @@ workflows: - build_push ``` +{{< /tab >}} +{{< tab name="Buildkite" >}} + +The following example sets up a Buildkite pipeline using Hydrobuild. The +example assumes that the pipeline name is `build-push-docker` and that you +manage the Docker access token using environment hooks, but feel free to adapt +this to your needs. + +Add the following `environment` hook agent's hook directory: + +```bash +#!/bin/bash +set -euo pipefail + +if [[ "$BUILDKITE_PIPELINE_NAME" == "build-push-docker" ]]; then + export DOCKER_PAT="" +fi +``` + +Create a `pipeline.yml` that uses the `docker-login` plugin: + +```yaml +env: + DOCKER_ORG: + IMAGE_NAME: + +steps: + - command: ./build.sh + key: build-push + plugins: + - docker-login#v2.1.0: + username: + password-env: DOCKER_PAT # the variable name in the environment hook +``` + +Create the `build.sh` script: + +```bash +DOCKER_DIR=/usr/libexec/docker + +# Get download link for latest buildx binary. +# Set $ARCH to the CPU architecture (e.g. amd64, arm64) +UNAME_ARCH=`uname -m` +case $UNAME_ARCH in + aarch64) + ARCH="arm64"; + ;; + amd64) + ARCH="amd64"; + ;; + *) + ARCH="amd64"; + ;; +esac +BUILDX_URL=$(curl -s https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/buildx-lab-releases.json | jq -r ".latest.assets[] | select(endswith(\"linux-$ARCH\"))") + +# Download docker buildx with Hyrdobuild support +curl --silent -L --output $DOCKER_DIR/cli-plugins/docker-buildx $BUILDX_URL +chmod a+x ~/.docker/cli-plugins/docker-buildx + +# Connect to your builder and set it as the default builder +docker buildx create --use --driver cloud "$DOCKER_ORG/default" + +# Cache-only image build +docker buildx build \ + --platform linux/amd64,linux/arm64 \ + --tag "$IMAGE_NAME:$BUILDKITE_COMMIT" \ + --output type=cacheonly \ + . + +# Build, tag, and push a multi-arch docker image +docker buildx build \ + --platform linux/amd64,linux/arm64 \ + --push \ + --tag "$IMAGE_NAME:$BUILDKITE_COMMIT" \ + . +``` + {{< /tab >}} {{< tab name="Shell" >}}