From 6152571fe0fddbc27078870c55bfae640431cea2 Mon Sep 17 00:00:00 2001 From: Ilya Zuyev Date: Thu, 24 Jun 2021 23:01:03 -0700 Subject: [PATCH] build kvm-arm64 in docker --- Makefile | 27 +++++++++----- .../kvm/{Dockerfile => Dockerfile.amd64} | 0 installers/linux/kvm/Dockerfile.arm64 | 35 +++++++++++++++++++ 3 files changed, 54 insertions(+), 8 deletions(-) rename installers/linux/kvm/{Dockerfile => Dockerfile.amd64} (100%) create mode 100644 installers/linux/kvm/Dockerfile.arm64 diff --git a/Makefile b/Makefile index e6e1e8cd6f..881638ed1a 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,9 @@ HYPERKIT_BUILD_IMAGE ?= neilotoole/xcgo:go1.15 BUILD_IMAGE ?= us.gcr.io/k8s-artifacts-prod/build-image/kube-cross:v$(GO_VERSION)-1 ISO_BUILD_IMAGE ?= $(REGISTRY)/buildroot-image -KVM_BUILD_IMAGE ?= $(REGISTRY)/kvm-build-image:$(KVM_GO_VERSION) + +KVM_BUILD_IMAGE_AMD64 ?= $(REGISTRY)/kvm-build-image_amd64:$(KVM_GO_VERSION) +KVM_BUILD_IMAGE_ARM64 ?= $(REGISTRY)/kvm-build-image_arm64:$(KVM_GO_VERSION) ISO_BUCKET ?= minikube/iso @@ -827,26 +829,35 @@ out/docker-machine-driver-kvm2-$(RPM_VERSION)-0.%.rpm: out/docker-machine-driver @mv out/$*/docker-machine-driver-kvm2-$(RPM_VERSION)-0.$*.rpm out/ && rmdir out/$* rm -rf out/docker-machine-driver-kvm2-$(RPM_VERSION) -.PHONY: kvm-image -kvm-image: installers/linux/kvm/Dockerfile ## Convenient alias to build the docker container - docker build --build-arg "GO_VERSION=$(KVM_GO_VERSION)" -t $(KVM_BUILD_IMAGE) -f $< $(dir $<) +.PHONY: kvm-image-amd64 +kvm-image-amd64: installers/linux/kvm/Dockerfile.amd64 ## Convenient alias to build the docker container + docker build --build-arg "GO_VERSION=$(KVM_GO_VERSION)" -t $(KVM_BUILD_IMAGE_AMD64) -f $< $(dir $<) + @echo "" + @echo "$(@) successfully built" + +.PHONY: kvm-image-arm64 +kvm-image-arm64: installers/linux/kvm/Dockerfile.arm64 ## Convenient alias to build the docker container + docker build --build-arg "GO_VERSION=$(KVM_GO_VERSION)" -t $(KVM_BUILD_IMAGE_AMD64) -f $< $(dir $<) @echo "" @echo "$(@) successfully built" kvm_in_docker: - docker image inspect -f '{{.Id}} {{.RepoTags}}' $(KVM_BUILD_IMAGE) || $(MAKE) kvm-image + docker image inspect -f '{{.Id}} {{.RepoTags}}' $(KVM_BUILD_IMAGE_AMD64) || $(MAKE) kvm-image-amd64 rm -f out/docker-machine-driver-kvm2 - $(call DOCKER,$(KVM_BUILD_IMAGE),/usr/bin/make out/docker-machine-driver-kvm2 COMMIT=$(COMMIT)) + $(call DOCKER,$(KVM_BUILD_IMAGE_AMD64),/usr/bin/make out/docker-machine-driver-kvm2 COMMIT=$(COMMIT)) .PHONY: install-kvm-driver install-kvm-driver: out/docker-machine-driver-kvm2 ## Install KVM Driver mkdir -p $(GOBIN) cp out/docker-machine-driver-kvm2 $(GOBIN)/docker-machine-driver-kvm2 + +out/docker-machine-driver-kvm2-aarch64: kvm-image-arm64 + out/docker-machine-driver-kvm2-%: ifeq ($(MINIKUBE_BUILD_IN_DOCKER),y) - docker image inspect -f '{{.Id}} {{.RepoTags}}' $(KVM_BUILD_IMAGE) || $(MAKE) kvm-image - $(call DOCKER,$(KVM_BUILD_IMAGE),/usr/bin/make $@ COMMIT=$(COMMIT)) + docker image inspect -f '{{.Id}} {{.RepoTags}}' $(KVM_BUILD_IMAGE_AMD64) || $(MAKE) kvm-image-amd64 + $(call DOCKER,$(KVM_BUILD_IMAGE_AMD64),/usr/bin/make $@ COMMIT=$(COMMIT)) # make extra sure that we are linking with the older version of libvirt (1.3.1) test "`strings $@ | grep '^LIBVIRT_[0-9]' | sort | tail -n 1`" = "LIBVIRT_1.2.9" else diff --git a/installers/linux/kvm/Dockerfile b/installers/linux/kvm/Dockerfile.amd64 similarity index 100% rename from installers/linux/kvm/Dockerfile rename to installers/linux/kvm/Dockerfile.amd64 diff --git a/installers/linux/kvm/Dockerfile.arm64 b/installers/linux/kvm/Dockerfile.arm64 new file mode 100644 index 0000000000..036c748297 --- /dev/null +++ b/installers/linux/kvm/Dockerfile.arm64 @@ -0,0 +1,35 @@ +# Copyright 2019 The Kubernetes Authors All rights reserved. +# +# 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 ubuntu:21.04 + +RUN echo "deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports hirsute main universe restricted multiverse" >> /etc/apt/sources.list + +RUN apt update && apt install -y \ + gcc-aarch64-linux-gnu \ + make \ + pkg-config \ + curl + +RUN apt install -y libvirt-dev:arm64 + +ARG GO_VERSION +RUN curl -sSL https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz | tar -C /usr/local -xzf - + +ENV GOPATH /go + +# CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 make out/docker-machine-driver-kvm2-arm64 +ENV CC=aarch64-linux-gnu-gcc +ENV CGO_ENABLED=1 +ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin:/go/bin