Skip to content

Instantly share code, notes, and snippets.

@toolmantim
Created February 17, 2017 06:23
Show Gist options
  • Select an option

  • Save toolmantim/16a39f8c689ee8a7f56f386c59b044a8 to your computer and use it in GitHub Desktop.

Select an option

Save toolmantim/16a39f8c689ee8a7f56f386c59b044a8 to your computer and use it in GitHub Desktop.
An example golang-based Buildkite Agent 2.x Docker image with custom pre-checkout hook for Go projects
FROM golang:1.8
RUN apt-get update && \
apt-get install -y apt-transport-https \
&& echo 'deb https://apt.buildkite.com/buildkite-agent stable main' > /etc/apt/sources.list.d/buildkite-agent.list \
&& apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 32A37959C2FA5C3C99EFBC32A79206696452D198 \
&& apt-get update \
&& apt-get install -y buildkite-agent
COPY pre-checkout.sh /etc/buildkite-agent/hooks/pre-checkout
CMD ["buildkite-agent", "start"]
#!/bin/bash
set -eu
if [[ ! -z "${BUILDKTE_GOLANG_IMPORT_PATH:-}" ]]; then
echo "--- :golang: Setting up Golang build environment"
export GOPATH="$BUILDKITE_BUILD_CHECKOUT_PATH"
export BUILDKITE_BUILD_CHECKOUT_PATH="$BUILDKITE_BUILD_CHECKOUT_PATH/src/$BUILDKTE_GOLANG_IMPORT_PATH"
fi
$ chmod +x pre-checkout.sh
...
$ docker build -t go-bk-agent .
...
$ docker run -e BUILDKITE_AGENT_TOKEN=xxx buildkite-agent start
...

If you're using Buildkite Agent 3+ you should just use the Golang Buildkite Agent Plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment