From de038007c724f4dddaf16aad89b5f012e48ec4c7 Mon Sep 17 00:00:00 2001 From: Jianyong Date: Thu, 19 Jul 2018 13:13:30 +0800 Subject: [PATCH] add arm support for sonobuoy Signed-off-by: Bin Lu --- Dockerfile | 7 +++-- Makefile | 87 +++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 81 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index b77a57f30..166a31686 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,11 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM golang:1.10-alpine +FROM BASEIMAGE MAINTAINER Timothy St. Clair "tstclair@heptio.com" -RUN apk add --no-cache ca-certificates bash -ADD sonobuoy /sonobuoy +CMD1 + +ADD BINARY /sonobuoy ADD scripts/run_master.sh /run_master.sh ADD scripts/run_single_node_worker.sh /run_single_node_worker.sh WORKDIR / diff --git a/Makefile b/Makefile index 25742f3f3..0f8b58c5b 100644 --- a/Makefile +++ b/Makefile @@ -12,13 +12,20 @@ # See the License for the specific language governing permissions and # limitations under the License. # +EMPTY := +SPACE := $(EMPTY) $(EMPTY) +COMMA := $(EMPTY),$(EMPTY) +BINARY = sonobuoy TARGET = sonobuoy GOTARGET = github.com/heptio/$(TARGET) REGISTRY ?= gcr.io/heptio-images IMAGE = $(REGISTRY)/$(TARGET) DIR := ${CURDIR} DOCKER ?= docker +LINUX_ARCH := amd64 arm64 +DOCKERFILE := +PLATFORMS := $(subst $(SPACE),$(COMMA),$(foreach arch,$(LINUX_ARCH),linux/$(arch))) GIT_VERSION ?= $(shell git describe --always --dirty) IMAGE_VERSION ?= $(shell git describe --always --dirty) @@ -30,8 +37,6 @@ VERBOSE_FLAG = -v endif BUILDMNT = /go/src/$(GOTARGET) BUILD_IMAGE ?= golang:1.10-alpine -BUILDCMD = CGO_ENABLED=0 go build -o $(TARGET) $(VERBOSE_FLAG) -ldflags "-X github.com/heptio/sonobuoy/pkg/buildinfo.Version=$(GIT_VERSION)" -BUILD = $(BUILDCMD) $(GOTARGET) TESTARGS ?= $(VERBOSE_FLAG) -timeout 60s TEST_PKGS ?= $(GOTARGET)/cmd/... $(GOTARGET)/pkg/... @@ -50,6 +55,11 @@ LINT = golint $(GOLINT_FLAGS) $(TEST_PKGS) WORKDIR ?= /sonobuoy DOCKER_BUILD ?= $(DOCKER) run --rm -v $(DIR):$(BUILDMNT) -w $(BUILDMNT) $(BUILD_IMAGE) /bin/sh -c +#manifest-tool +MANIFEST_TOOL_DIR := $(shell mktemp -d) +export PATH := $(MANIFEST_TOOL_DIR):$(PATH) +MANIFEST_TOOL_VERSION := v0.7.0 + .PHONY: all container push clean test local-test local generate plugins int all: container @@ -71,17 +81,49 @@ lint: vet: $(DOCKER_BUILD) '$(VET)' -container: sonobuoy +pre: + curl -sSL https://github.com/estesp/manifest-tool/releases/download/$(MANIFEST_TOOL_VERSION)/manifest-tool-linux-amd64 > $(MANIFEST_TOOL_DIR)/manifest-tool + chmod +x $(MANIFEST_TOOL_DIR)/manifest-tool + +build_container: $(DOCKER) build \ - -t $(REGISTRY)/$(TARGET):$(IMAGE_VERSION) \ - -t $(REGISTRY)/$(TARGET):$(IMAGE_BRANCH) \ - -t $(REGISTRY)/$(TARGET):$(GIT_REF) \ + -t $(REGISTRY)/$(TARGET):$(IMAGE_VERSION) \ + -t $(REGISTRY)/$(TARGET):$(IMAGE_BRANCH) \ + -t $(REGISTRY)/$(TARGET):$(GIT_REF) \ + -f $(DOCKERFILE) \ . -sonobuoy: - $(DOCKER_BUILD) '$(BUILD)' +container: sonobuoy + for arch in $(LINUX_ARCH); do \ + if [ $$arch = amd64 ]; then \ + sed -e 's|BASEIMAGE|alpine:3.7|g' \ + -e 's|CMD1|RUN apk add --no-cache ca-certificates bash|g' \ + -e 's|BINARY|build/linux/amd64/sonobuoy|g' Dockerfile > Dockerfile-$$arch; \ + $(MAKE) build_container DOCKERFILE=Dockerfile-$$arch; \ + $(MAKE) build_container DOCKERFILE="Dockerfile-$$arch" TARGET="sonobuoy-$$arch"; \ + elif [ $$arch = arm64 ]; then \ + sed -e 's|BASEIMAGE|arm64v8/ubuntu:16.04|g' \ + -e 's|CMD1||g' \ + -e 's|BINARY|build/linux/arm64/sonobuoy|g' Dockerfile > Dockerfile-$$arch; \ + $(MAKE) build_container DOCKERFILE="Dockerfile-$$arch" TARGET="sonobuoy-$$arch"; \ + else \ + echo "ARCH unknown"; \ + fi \ + done + +build_sonobuoy: + $(DOCKER_BUILD) 'CGO_ENABLED=0 $(SYSTEM) go build -o $(BINARY) $(VERBOSE_FLAG) -ldflags="-s -w -X github.com/heptio/sonobuoy/pkg/buildinfo.Version=$(GIT_VERSION)" $(GOTARGET)' -push: +sonobuoy: + for arch in $(LINUX_ARCH); do \ + mkdir -p build/linux/$$arch; \ + echo Building: linux/$$arch; \ + $(MAKE) build_sonobuoy SYSTEM="GOOS=linux GOARCH=$$arch" BINARY="build/linux/$$arch/sonobuoy"; \ + done + @echo Building: host + make build_sonobuoy + +push_images: $(DOCKER) push $(REGISTRY)/$(TARGET):$(IMAGE_BRANCH) $(DOCKER) push $(REGISTRY)/$(TARGET):$(GIT_REF) if git describe --tags --exact-match >/dev/null 2>&1; \ @@ -91,6 +133,31 @@ push: $(DOCKER) push $(REGISTRY)/$(TARGET):latest; \ fi +push_manifest: + manifest-tool push from-args --platforms $(PLATFORMS) --template $(REGISTRY)/$(TARGET)-ARCH:$(VERSION) --target $(REGISTRY)/$(TARGET):$(VERSION) + +push: pre container + for arch in $(LINUX_ARCH); do \ + $(MAKE) push_images TARGET="sonobuoy-$$arch"; \ + done + + $(MAKE) push_manifest VERSION=$(IMAGE_BRANCH) TARGET="sonobuoy" + $(MAKE) push_manifest VERSION=$(GIT_REF) TARGET="sonobuoy" + + if git describe --tags --exact-match >/dev/null 2>&1; \ + then \ + $(MAKE) push_manifest VERSION=$(IMAGE_VERSION) TARGET="sonobuoy"; \ + $(MAKE) push_manifest VERSION=latest TARGET="sonobuoy"; \ + fi + +clean_image: + $(DOCKER) rmi -f `$(DOCKER) images $(REGISTRY)/$(TARGET) -a -q` || true + clean: rm -f $(TARGET) - $(DOCKER) rmi $(REGISTRY)/$(TARGET) || true + rm -f Dockerfile-* + rm -rf build* + + for arch in $(LINUX_ARCH); do \ + $(MAKE) clean_image TARGET=$(TARGET)-$$arch; \ + done