github.com/jonaz/heapster@v1.3.0-beta.0.0.20170208112634-cd3c15ca3d29/grafana/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?=v4.0.2
    23  PREFIX?=gcr.io/google_containers
    24  ARCH?=amd64
    25  TEMP_DIR:=$(shell mktemp -d)
    26  LDFLAGS=-w -X main.version=$(VERSION) -X main.commit=unknown-dev -X main.timestamp=0 -extldflags '-static'
    27  DEB_BUILD=4.0.2-1481203731
    28  KUBE_CROSS_IMAGE=gcr.io/google_containers/kube-cross:v1.7.3-0
    29  
    30  ALL_ARCHITECTURES=amd64 arm arm64 ppc64le s390x
    31  ML_PLATFORMS=linux/amd64,linux/arm,linux/arm64,linux/ppc64le,linux/s390x
    32  
    33  # Set default base image dynamically for each arch
    34  ifeq ($(ARCH),amd64)
    35  	BASEIMAGE?=busybox
    36  	CC=gcc
    37  endif
    38  ifeq ($(ARCH),arm)
    39  	BASEIMAGE?=armhf/busybox
    40  	CC=arm-linux-gnueabi-gcc
    41  endif
    42  ifeq ($(ARCH),arm64)
    43  	BASEIMAGE?=aarch64/busybox
    44  	CC=aarch64-linux-gnu-gcc
    45  endif
    46  ifeq ($(ARCH),ppc64le)
    47  	BASEIMAGE?=ppc64le/busybox
    48  	CC=powerpc64le-linux-gnu-gcc
    49  endif
    50  ifeq ($(ARCH),s390x)
    51  	BASEIMAGE?=s390x/busybox
    52  	CC=s390x-linux-gnu-gcc
    53  endif
    54  
    55  build:
    56  	# Copy the whole directory to a temporary dir and set the base image
    57  	cp -r ./* $(TEMP_DIR)
    58  
    59  	cd $(TEMP_DIR) && sed -i "s|BASEIMAGE|$(BASEIMAGE)|g" Dockerfile
    60  
    61  	# This script downloads the official grafana deb package, compiles grafana for the right architecture which replaces the built-in, dynamically linked binaries
    62  	# Then the rootfs will be compressed into a tarball again, in order to be ADDed in the Dockerfile.
    63  	# Lastly, it compiles the go helper
    64  	docker run --rm -it -v $(TEMP_DIR):/build -w /go/src/github.com/grafana/grafana $(KUBE_CROSS_IMAGE) /bin/bash -c "\
    65  		curl -sSL https://github.com/grafana/grafana/archive/$(VERSION).tar.gz | tar -xz --strip-components=1 \
    66  		&& curl -sSL https://grafanarel.s3.amazonaws.com/builds/grafana_$(DEB_BUILD)_amd64.deb > /tmp/grafana.deb \
    67  		&& mkdir /tmp/grafanarootfs && dpkg -x /tmp/grafana.deb /tmp/grafanarootfs \
    68  		&& CGO_ENABLED=1 GOARCH=$(ARCH) CC=$(CC) go build --ldflags=\"$(LDFLAGS)\" -o /tmp/grafanarootfs/usr/sbin/grafana-server ./pkg/cmd/grafana-server \
    69  		&& CGO_ENABLED=1 GOARCH=$(ARCH) CC=$(CC) go build --ldflags=\"$(LDFLAGS)\" -o /tmp/grafanarootfs/usr/sbin/grafana-cli ./pkg/cmd/grafana-cli \
    70  		&& cd /tmp/grafanarootfs && tar -cf /build/grafana.tar . \
    71  		&& cd /build && CGO_ENABLED=0 GOARCH=$(ARCH) go build -o setup_grafana setup_grafana.go"
    72  
    73  	docker build --pull -t $(PREFIX)/heapster-grafana-$(ARCH):$(VERSION) $(TEMP_DIR)
    74  
    75  	rm -rf $(TEMP_DIR)
    76  
    77  push: ./manifest-tool gcr-login $(addprefix sub-push-,$(ALL_ARCHITECTURES))
    78  	./manifest-tool push from-args --platforms $(ML_PLATFORMS) --template $(PREFIX)/heapster-grafana-ARCH:$(VERSION) --target $(PREFIX)/heapster-grafana:$(VERSION)
    79  
    80  sub-push-%:
    81  	$(MAKE) ARCH=$* PREFIX=$(PREFIX) VERSION=$(VERSION) build
    82  	docker push $(PREFIX)/heapster-grafana-$*:$(VERSION)
    83  
    84  ./manifest-tool:
    85  	curl -sSL https://github.com/luxas/manifest-tool/releases/download/v0.3.0/manifest-tool > manifest-tool
    86  	chmod +x manifest-tool
    87  
    88  gcr-login:
    89  ifeq ($(findstring gcr.io,$(PREFIX)),gcr.io)
    90  	@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."
    91  	@echo "This script is automatically logging you in now."
    92  	docker login -u oauth2accesstoken -p "$(shell gcloud auth print-access-token)" https://gcr.io
    93  endif