Skip to content

Commit

Permalink
Add support for arm64 to kube-cross image
Browse files Browse the repository at this point in the history
We should be able to compile for say linux/arm64 using this image on
arm64. We'll not be able to cross-compile on non-amd64 platforms.

Signed-off-by: Davanum Srinivas <[email protected]>
  • Loading branch information
dims committed Jan 15, 2021
1 parent ce5ecf2 commit 36a1f59
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 22 deletions.
48 changes: 35 additions & 13 deletions images/build/cross/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ FROM golang:${GO_VERSION}

##------------------------------------------------------------
# global ARGs & ENVs

ARG TARGETPLATFORM
ARG DEBIAN_FRONTEND=noninteractive

ENV GOARM 7
Expand All @@ -41,8 +41,11 @@ ENV KUBE_CROSSPLATFORMS \
##------------------------------------------------------------

# Pre-compile the standard go library when cross-compiling. This is much easier now when we have go1.5+
RUN for platform in ${KUBE_CROSSPLATFORMS}; do GOOS=${platform%/*} GOARCH=${platform##*/} go install std; done \
&& go clean -cache
RUN targetArch=$(echo $TARGETPLATFORM | cut -f2 -d '/') \
&& if [ ${targetArch} = "amd64" ]; then \
for platform in ${KUBE_CROSSPLATFORMS}; do GOOS=${platform%/*} GOARCH=${platform##*/} go install std; done \
&& go clean -cache; \
fi

# Install packages
RUN apt-get -q update \
Expand All @@ -56,15 +59,33 @@ RUN apt-get -q update \

# Use dynamic cgo linking for architectures other than amd64 for the server platforms
# To install crossbuild essential for other architectures add the following repository.
RUN echo "deb http://archive.ubuntu.com/ubuntu xenial main universe" > /etc/apt/sources.list.d/cgocrosscompiling.list \
&& apt-key adv --no-tty --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5 3B4FE6ACC0B21F32 \
&& apt-get update \
&& apt-get install -y build-essential \
&& for platform in ${KUBE_DYNAMIC_CROSSPLATFORMS}; do apt-get install -y crossbuild-essential-${platform}; done
RUN targetArch=$(echo $TARGETPLATFORM | cut -f2 -d '/') \
&& if [ ${targetArch} = "amd64" ]; then \
echo "deb http://archive.ubuntu.com/ubuntu xenial main universe" > /etc/apt/sources.list.d/cgocrosscompiling.list \
&& apt-key adv --no-tty --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5 3B4FE6ACC0B21F32 \
&& apt-get update \
&& apt-get install -y build-essential \
&& for platform in ${KUBE_DYNAMIC_CROSSPLATFORMS}; do apt-get install -y crossbuild-essential-${platform}; done \
fi

RUN targetArch=$(echo $TARGETPLATFORM | cut -f2 -d '/') \
&& if [ ${targetArch} = "arm64" ] || [ ${targetArch} = "ppc64le" ]; then \
echo "deb http://ports.ubuntu.com/ubuntu-ports/ xenial main" > /etc/apt/sources.list.d/ports.list \
&& apt-key adv --no-tty --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5 3B4FE6ACC0B21F32 \
&& apt-get update \
&& apt-get install -y build-essential; \
fi

ARG PROTOBUF_VERSION
ENV ZIPNAME="protoc-${PROTOBUF_VERSION}-linux-x86_64.zip"
RUN mkdir /tmp/protoc && cd /tmp/protoc \
RUN targetArch=$(echo $TARGETPLATFORM | cut -f2 -d '/') \
&& if [ ${targetArch} = "amd64" ]; then \
ZIPNAME="protoc-${PROTOBUF_VERSION}-linux-x86_64.zip"; \
elif [ ${targetArch} = "arm64" ]; then \
ZIPNAME="protoc-${PROTOBUF_VERSION}-linux-aarch_64.zip"; \
elif [ ${targetArch} = "ppc64le" ]; then \
ZIPNAME="protoc-${PROTOBUF_VERSION}-linux-ppcle_64.zip"; \
fi \
&& mkdir /tmp/protoc && cd /tmp/protoc \
&& wget "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VERSION}/${ZIPNAME}" \
&& unzip "${ZIPNAME}" \
&& chmod -R +rX /tmp/protoc \
Expand All @@ -86,11 +107,12 @@ RUN go get golang.org/x/tools/cmd/cover \

# Download and symlink etcd. We need this for our integration tests.
ARG ETCD_VERSION
RUN mkdir -p /usr/local/src/etcd \
RUN targetArch=$(echo $TARGETPLATFORM | cut -f2 -d '/') \
&& mkdir -p /usr/local/src/etcd \
&& cd /usr/local/src/etcd \
&& curl -fsSL https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-amd64.tar.gz | tar -xz \
&& curl -fsSL https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-${targetArch}.tar.gz | tar -xz \
&& chown -R $(id -u):$(id -g) /usr/local/src/etcd \
&& ln -s ../src/etcd/etcd-${ETCD_VERSION}-linux-amd64/etcd /usr/local/bin/
&& ln -s ../src/etcd/etcd-${ETCD_VERSION}-linux-${targetArch}/etcd /usr/local/bin/

# Cleanup a bit
RUN apt-get -qqy remove \
Expand Down
12 changes: 5 additions & 7 deletions images/build/cross/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ CONFIG ?= go1.15

# Build args
GO_VERSION?=1.15.5
PROTOBUF_VERSION?=3.0.2
PROTOBUF_VERSION?=3.7.0
ETCD_VERSION?=v3.4.13

# TODO: Support multi-arch kube-cross images
# ref:
# - https://github.com/kubernetes/release/pull/1140/commits/e96924f58d9ce2bb73045fbba13f259b4345c0d9#r395056830
# - https://github.com/kubernetes/kubernetes/issues/78964
# - https://github.com/kubernetes/kubernetes/issues/75114
PLATFORMS ?= linux/amd64 #linux/arm linux/arm64 linux/ppc64le linux/s390x
# TODO: Support multi-arch kube-cross images for linux/arm linux/s390x
# Currently some of the components references in the Dockerfile are
# not supported in specific architectures (example etcd does not support s390x)
PLATFORMS ?= linux/amd64 linux/arm64 linux/ppc64le #linux/arm linux/s390x

BUILD_ARGS = --build-arg=GO_VERSION=$(GO_VERSION) \
--build-arg=PROTOBUF_VERSION=$(PROTOBUF_VERSION) \
Expand Down
4 changes: 2 additions & 2 deletions images/build/cross/variants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ variants:
CONFIG: 'canary'
GO_VERSION: '1.15.5'
IMAGE_VERSION: 'v1.15.5-canary-1'
PROTOBUF_VERSION: '3.0.2'
PROTOBUF_VERSION: '3.7.0'
ETCD_VERSION: 'v3.4.13'
go1.15:
CONFIG: 'go1.15'
GO_VERSION: '1.15.5'
IMAGE_VERSION: 'v1.15.5-1'
PROTOBUF_VERSION: '3.0.2'
PROTOBUF_VERSION: '3.7.0'
ETCD_VERSION: 'v3.4.13'

2 comments on commit 36a1f59

@listx
Copy link

@listx listx commented on 36a1f59 Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the protobuf upgrade here for the same reason as in the commit message, or for something else?

@dims
Copy link
Member Author

@dims dims commented on 36a1f59 Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@listx same reason yes. 3.0.2 did not have a arm release. 3.7.0 was the first one that did.

Please sign in to comment.