|
| 1 | +# Copyright 2016 The Kubernetes Authors. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# This file creates a standard build environment for building cross |
| 16 | +# platform go binary for the architecture kubernetes cares about. |
| 17 | + |
| 18 | +FROM golang:1.13.8 |
| 19 | + |
| 20 | +ENV GOARM 7 |
| 21 | +ENV KUBE_DYNAMIC_CROSSPLATFORMS \ |
| 22 | + armhf \ |
| 23 | + arm64 \ |
| 24 | + s390x \ |
| 25 | + ppc64el |
| 26 | + |
| 27 | +ENV KUBE_CROSSPLATFORMS \ |
| 28 | + linux/386 \ |
| 29 | + linux/arm linux/arm64 \ |
| 30 | + linux/ppc64le \ |
| 31 | + linux/s390x \ |
| 32 | + darwin/amd64 darwin/386 \ |
| 33 | + windows/amd64 windows/386 |
| 34 | + |
| 35 | +# Pre-compile the standard go library when cross-compiling. This is much easier now when we have go1.5+ |
| 36 | +RUN for platform in ${KUBE_CROSSPLATFORMS}; do GOOS=${platform%/*} GOARCH=${platform##*/} go install std; done \ |
| 37 | + && go clean -cache |
| 38 | + |
| 39 | +# Install g++, then download and install protoc for generating protobuf output |
| 40 | +RUN apt-get update \ |
| 41 | + && apt-get install -y rsync jq apt-utils file patch unzip \ |
| 42 | + && apt-get clean && rm -rf /var/lib/apt/lists/* |
| 43 | + |
| 44 | +# Use dynamic cgo linking for architectures other than amd64 for the server platforms |
| 45 | +# To install crossbuild essential for other architectures add the following repository. |
| 46 | +RUN echo "deb http://archive.ubuntu.com/ubuntu xenial main universe" > /etc/apt/sources.list.d/cgocrosscompiling.list \ |
| 47 | + && apt-key adv --no-tty --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5 3B4FE6ACC0B21F32 \ |
| 48 | + && apt-get update \ |
| 49 | + && apt-get install -y build-essential \ |
| 50 | + && for platform in ${KUBE_DYNAMIC_CROSSPLATFORMS}; do apt-get install -y crossbuild-essential-${platform}; done \ |
| 51 | + && apt-get clean && rm -rf /var/lib/apt/lists/* |
| 52 | + |
| 53 | +RUN PROTOBUF_VERSION=3.0.2; ZIPNAME="protoc-${PROTOBUF_VERSION}-linux-x86_64.zip"; \ |
| 54 | + mkdir /tmp/protoc && cd /tmp/protoc \ |
| 55 | + && wget "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VERSION}/${ZIPNAME}" \ |
| 56 | + && unzip "${ZIPNAME}" \ |
| 57 | + && chmod -R +rX /tmp/protoc \ |
| 58 | + && cp -pr bin /usr/local \ |
| 59 | + && cp -pr include /usr/local \ |
| 60 | + && rm -rf /tmp/protoc \ |
| 61 | + && protoc --version |
| 62 | + |
| 63 | +# work around 64MB tmpfs size in Docker 1.6 |
| 64 | +ENV TMPDIR /tmp.k8s |
| 65 | +RUN mkdir $TMPDIR \ |
| 66 | + && chmod a+rwx $TMPDIR \ |
| 67 | + && chmod o+t $TMPDIR |
| 68 | + |
| 69 | +# Get the code coverage tool and goimports |
| 70 | +RUN go get golang.org/x/tools/cmd/cover \ |
| 71 | + golang.org/x/tools/cmd/goimports \ |
| 72 | + && go clean -cache |
| 73 | + |
| 74 | +# Download and symlink etcd. We need this for our integration tests. |
| 75 | +RUN export ETCD_VERSION=v3.2.24; \ |
| 76 | + mkdir -p /usr/local/src/etcd \ |
| 77 | + && cd /usr/local/src/etcd \ |
| 78 | + && curl -fsSL https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-amd64.tar.gz | tar -xz \ |
| 79 | + && ln -s ../src/etcd/etcd-${ETCD_VERSION}-linux-amd64/etcd /usr/local/bin/ |
0 commit comments