github.com/jonaz/heapster@v1.3.0-beta.0.0.20170208112634-cd3c15ca3d29/influxdb/Makefile (about)

     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  # Build the influxdb image for amd64, arm, arm64, ppc64le and s390x
    16  #
    17  # Usage:
    18  # 	[PREFIX=gcr.io/google_containers] [ARCH=amd64] make (build|push)
    19  
    20  all: build
    21  
    22  VERSION?=v1.1.1
    23  PREFIX?=gcr.io/google_containers
    24  ARCH?=amd64
    25  GOLANG_VERSION=1.7
    26  TEMP_DIR:=$(shell mktemp -d)
    27  
    28  ALL_ARCHITECTURES=amd64 arm arm64 ppc64le s390x
    29  ML_PLATFORMS=linux/amd64,linux/arm,linux/arm64,linux/ppc64le,linux/s390x
    30  
    31  # Set default base image dynamically for each arch
    32  ifeq ($(ARCH),amd64)
    33  	BASEIMAGE?=busybox
    34  endif
    35  ifeq ($(ARCH),arm)
    36  	BASEIMAGE?=armhf/busybox
    37  endif
    38  ifeq ($(ARCH),arm64)
    39  	BASEIMAGE?=aarch64/busybox
    40  endif
    41  ifeq ($(ARCH),ppc64le)
    42  	BASEIMAGE?=ppc64le/busybox
    43  endif
    44  ifeq ($(ARCH),s390x)
    45  	BASEIMAGE?=s390x/busybox
    46  endif
    47  
    48  build:
    49  	# Copy the whole directory to a temporary dir and set the base image
    50  	cp -r ./* $(TEMP_DIR)
    51  
    52  	cd $(TEMP_DIR) && sed -i "s|BASEIMAGE|$(BASEIMAGE)|g" Dockerfile
    53  
    54  	# Compile the binary inside a container for reliable builds
    55  	docker run --rm -it -v $(TEMP_DIR):/build -w /go/src/github.com/influxdb/influxdb golang:$(GOLANG_VERSION) /bin/bash -c "\
    56  		curl -sSL https://github.com/influxdata/influxdb/archive/$(VERSION).tar.gz | tar -xz --strip-components=1 \
    57  		&& go get github.com/sparrc/gdm \
    58  		&& gdm restore \
    59  		&& ln -s /go/src/github.com/influxdb/influxdb /go/src/github.com/influxdata/ \
    60  		&& GOARCH=$(ARCH) CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags=\"-s\" -o /build/influxd ./cmd/influxd"
    61  
    62  	docker build --pull -t $(PREFIX)/heapster-influxdb-$(ARCH):$(VERSION) $(TEMP_DIR)
    63  
    64  	rm -rf $(TEMP_DIR)
    65  
    66  push: ./manifest-tool gcr-login $(addprefix sub-push-,$(ALL_ARCHITECTURES))
    67  	./manifest-tool push from-args --platforms $(ML_PLATFORMS) --template $(PREFIX)/heapster-influxdb-ARCH:$(VERSION) --target $(PREFIX)/heapster-influxdb:$(VERSION)
    68  
    69  sub-push-%:
    70  	$(MAKE) ARCH=$* PREFIX=$(PREFIX) VERSION=$(VERSION) build
    71  	docker push $(PREFIX)/heapster-influxdb-$*:$(VERSION)
    72  
    73  gcr-login:
    74  ifeq ($(findstring gcr.io,$(PREFIX)),gcr.io)
    75  	@echo "If you are pushing to a gcr.io registry, you have to be logged in via 'docker login'; 'gcloud docker push' can't push manifest lists yet."
    76  	@echo "This script is automatically logging you in now."
    77  	docker login -u oauth2accesstoken -p "$(shell gcloud auth print-access-token)" https://gcr.io
    78  endif
    79  
    80  ./manifest-tool:
    81  	curl -sSL https://github.com/luxas/manifest-tool/releases/download/v0.3.0/manifest-tool > manifest-tool
    82  	chmod +x manifest-tool