Skip to content

Instantly share code, notes, and snippets.

@akutz
Last active July 17, 2019 00:18
Show Gist options
  • Save akutz/7610d84874db6d0987c36ce5d16984b1 to your computer and use it in GitHub Desktop.
Save akutz/7610d84874db6d0987c36ce5d16984b1 to your computer and use it in GitHub Desktop.
Building CAPI inside a container with Bazel

Building CAPI inside a container with Bazel

Building CAPI requires Bazel+Golang. The following instructions illustrate how to build the CAPI manager binary using a Docker container that includes both Bazel and Golang 1.12.6.

Build the docker image

The Docker image built from Dockerfile is pushed to akutz/bazel-go, but it may also be built locally using the following command:

docker build -t bazel-go .

Build the CAPI manager binary

The CAPI manager binary may now be built inside of a container using the following command:

docker run -it --rm bazel-go \
  /bin/sh -c "git clone https://github.com/kubernetes-sigs/cluster-api.git . && \
  make vendor && \
  make generate && \
  make manager"

The above command builds the manager binary outside of the GOPATH in the /build directory. Please note this only works with CAPI v1alpha2. Builds for the release-1 branch must occur from inside $GOPATH/src/sigs.k8s.io/cluster-api.

# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM golang:1.12.6
LABEL "maintainer" "Andrew Kutz <akutz@vmware.com>"
# Install dependencies
RUN apt-get --assume-no update && \
apt-get -y install apt-transport-https \
ca-certificates \
curl \
g++ \
patch \
pkg-config \
python3 \
unzip \
zip \
zlib1g-dev
# Install bazel
RUN echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | \
tee /etc/apt/sources.list.d/bazel.list && \
curl https://bazel.build/bazel-release.pub.gpg | apt-key add -
RUN apt-get --assume-no update && \
apt-get -y install bazel
WORKDIR /build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment