From c4e6f3307f6a21ad78352b18312f301ed6683a3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20K=C3=A4ldstr=C3=B6m?= Date: Mon, 26 Jun 2017 20:11:15 +0300 Subject: [PATCH] Update Makefile to release and build for multiple platforms --- Makefile | 54 +++++++++++++++++++++++++++++++++++++++-------- deploy/Dockerfile | 6 +----- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 4af6147d..7dbfdce7 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,49 @@ -all: build +REGISTRY?=directxman12 +IMAGE?=k8s-prometheus-adapter +TEMP_DIR:=$(shell mktemp -d) +ARCH?=amd64 +ALL_ARCH=amd64 arm arm64 ppc64le s390x +ML_PLATFORMS=linux/amd64,linux/arm,linux/arm64,linux/ppc64le,linux/s390x +VERSION?=latest + +ifeq ($(ARCH),amd64) + BASEIMAGE?=busybox +endif +ifeq ($(ARCH),arm) + BASEIMAGE?=armhf/busybox +endif +ifeq ($(ARCH),arm64) + BASEIMAGE?=aarch64/busybox +endif +ifeq ($(ARCH),ppc64le) + BASEIMAGE?=ppc64le/busybox +endif +ifeq ($(ARCH),s390x) + BASEIMAGE?=s390x/busybox +endif + +all: docker-build build: - go build cmd/adapter.go -.PHONY: build + CGO_ENABLED=0 GOARCH=$(ARCH) go build -a -tags netgo -o /build/adapter github.com/directxman12/k8s-prometheus-adapter/cmd -docker-build: adapter - docker build -t cm-adapter -f deploy/Dockerfile . -.PHONY: docker-build +docker-build: + cp deploy/Dockerfile $(TEMP_DIR) + cd $(TEMP_DIR) && sed -i "s|BASEIMAGE|$(BASEIMAGE)|g" Dockerfile -clean: - rm adapter -.PHONY: clean + docker run -it -v $(TEMP_DIR):/build -v $(shell pwd):/go/src/github.com/directxman12/k8s-prometheus-adapter -e GOARCH=$(ARCH) golang:1.8 /bin/bash -c "\ + CGO_ENABLED=0 go build -a -tags netgo -o /build/adapter github.com/directxman12/k8s-prometheus-adapter/cmd" + + docker build -t $(REGISTRY)/$(IMAGE)-$(ARCH):$(VERSION) $(TEMP_DIR) + sudo rm -r $(TEMP_DIR) + +push-%: + $(MAKE) ARCH=$* docker-build + docker push $(REGISTRY)/$(IMAGE)-$*:$(VERSION) + +push: ./manifest-tool $(addprefix push-,$(ALL_ARCH)) + ./manifest-tool push from-args --platforms $(ML_PLATFORMS) --template $(REGISTRY)/$(IMAGE)-ARCH:$(VERSION) --target $(REGISTRY)/$(IMAGE):$(VERSION) + +./manifest-tool: + curl -sSL https://github.com/estesp/manifest-tool/releases/download/v0.5.0/manifest-tool-linux-amd64 > manifest-tool + chmod +x manifest-tool diff --git a/deploy/Dockerfile b/deploy/Dockerfile index 595c6e22..c1ce01c8 100644 --- a/deploy/Dockerfile +++ b/deploy/Dockerfile @@ -1,8 +1,4 @@ -FROM scratch - +FROM BASEIMAGE COPY adapter / - USER 1001:1001 - ENTRYPOINT ["/adapter"] -