github.com/galamsiva2020/kubernetes-heapster-monitoring@v0.0.0-20210823134957-3c1baa7c1e70/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=staging-k8s.gcr.io] [ARCH=amd64] make (build|push) 19 20 all: build 21 22 VERSION?=v5.0.4 23 DEB_VERSION?=5.0.4 24 25 PREFIX?=staging-k8s.gcr.io 26 ARCH?=amd64 27 TEMP_DIR:=$(shell mktemp -d) 28 LDFLAGS=-w -X main.version=$(VERSION) -X main.commit=unknown-dev -X main.timestamp=0 -extldflags '-static' 29 KUBE_CROSS_IMAGE=k8s.gcr.io/kube-cross:v1.9.3-2 30 31 ALL_ARCHITECTURES=amd64 arm arm64 ppc64le s390x 32 ML_PLATFORMS=linux/amd64,linux/arm,linux/arm64,linux/ppc64le,linux/s390x 33 34 # Set default base image dynamically for each arch 35 ifeq ($(ARCH),amd64) 36 BASEIMAGE?=busybox:glibc 37 CC=gcc 38 endif 39 ifeq ($(ARCH),arm) 40 BASEIMAGE?=armhf/busybox:glibc 41 CC=arm-linux-gnueabihf-gcc 42 endif 43 ifeq ($(ARCH),arm64) 44 BASEIMAGE?=aarch64/busybox:glibc 45 CC=aarch64-linux-gnu-gcc 46 endif 47 ifeq ($(ARCH),ppc64le) 48 BASEIMAGE?=ppc64le/busybox:glibc 49 CC=powerpc64le-linux-gnu-gcc 50 endif 51 ifeq ($(ARCH),s390x) 52 BASEIMAGE?=s390x/busybox:glibc 53 CC=s390x-linux-gnu-gcc 54 endif 55 56 build: 57 # Copy the whole directory to a temporary dir and set the base image 58 cp -r ./* $(TEMP_DIR) 59 60 cd $(TEMP_DIR) && sed -i -e "s|BASEIMAGE|$(BASEIMAGE)|g" Dockerfile 61 62 # This script downloads the official grafana deb package, compiles grafana for the right architecture which replaces the built-in, dynamically linked binaries 63 # Then the rootfs will be compressed into a tarball again, in order to be ADDed in the Dockerfile. 64 # Lastly, it compiles the go helper 65 docker run --rm -it -v $(TEMP_DIR):/build -w /go/src/github.com/grafana/grafana $(KUBE_CROSS_IMAGE) /bin/bash -c "\ 66 curl -sSL https://github.com/grafana/grafana/archive/$(VERSION).tar.gz | tar -xz --strip-components=1 \ 67 && curl -sSL https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_$(DEB_VERSION)_amd64.deb > /tmp/grafana.deb \ 68 && mkdir /tmp/grafanarootfs && dpkg -x /tmp/grafana.deb /tmp/grafanarootfs \ 69 && cp /tmp/grafanarootfs/usr/share/grafana/conf/sample.ini /tmp/grafanarootfs/etc/grafana/grafana.ini \ 70 && cp /tmp/grafanarootfs/usr/share/grafana/conf/ldap.toml /tmp/grafanarootfs/etc/grafana/ldap.toml \ 71 && CGO_ENABLED=1 GOARCH=$(ARCH) CC=$(CC) go build --ldflags=\"$(LDFLAGS)\" -o /tmp/grafanarootfs/usr/sbin/grafana-server ./pkg/cmd/grafana-server \ 72 && CGO_ENABLED=1 GOARCH=$(ARCH) CC=$(CC) go build --ldflags=\"$(LDFLAGS)\" -o /tmp/grafanarootfs/usr/sbin/grafana-cli ./pkg/cmd/grafana-cli \ 73 && cd /tmp/grafanarootfs && tar -cf /build/grafana.tar . \ 74 && cd /build && CGO_ENABLED=0 GOARCH=$(ARCH) go build -o setup_grafana setup_grafana.go" 75 76 docker build --pull -t $(PREFIX)/heapster-grafana-$(ARCH):$(VERSION) $(TEMP_DIR) 77 78 rm -rf $(TEMP_DIR) 79 80 # Should depend on target: ./manifest-tool 81 push: gcr-login $(addprefix sub-push-,$(ALL_ARCHITECTURES)) 82 # ./manifest-tool push from-args --platforms $(ML_PLATFORMS) --template $(PREFIX)/heapster-grafana-ARCH:$(VERSION) --target $(PREFIX)/heapster-grafana:$(VERSION) 83 84 sub-push-%: 85 $(MAKE) ARCH=$* PREFIX=$(PREFIX) VERSION=$(VERSION) build 86 docker push $(PREFIX)/heapster-grafana-$*:$(VERSION) 87 88 # TODO(luxas): As soon as it's working to push fat manifests to gcr.io, reenable this code 89 #./manifest-tool: 90 # curl -sSL https://github.com/luxas/manifest-tool/releases/download/v0.3.0/manifest-tool > manifest-tool 91 # chmod +x manifest-tool 92 93 gcr-login: 94 ifeq ($(findstring gcr.io,$(PREFIX)),gcr.io) 95 @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." 96 @echo "This script is automatically logging you in now." 97 gcloud docker -a 98 endif