From c9aac9e5304d4549692ea9b6bbc652c18e12f810 Mon Sep 17 00:00:00 2001 From: jackgr Date: Wed, 2 Mar 2016 18:09:06 -0800 Subject: [PATCH] Simplify makefiles in rootfs folders --- rootfs/expandybird/Makefile | 22 +++--------- rootfs/include.mk | 69 ++++++++++++++++++++++++++++++++++++ rootfs/manager/Makefile | 23 +++--------- rootfs/resourcifier/Makefile | 28 +++++---------- 4 files changed, 86 insertions(+), 56 deletions(-) create mode 100644 rootfs/include.mk diff --git a/rootfs/expandybird/Makefile b/rootfs/expandybird/Makefile index d6b662500..c87a43ac0 100644 --- a/rootfs/expandybird/Makefile +++ b/rootfs/expandybird/Makefile @@ -12,27 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -DOCKER_REGISTRY := gcr.io -PREFIX := $(DOCKER_REGISTRY)/$(PROJECT) IMAGE ?= expandybird -TAG ?= git-$(shell git rev-parse --short HEAD) -FULL_IMAGE := $(PREFIX)/$(IMAGE) -.PHONY: container -container: binary expansion - docker build -t $(FULL_IMAGE):latest -f Dockerfile . - docker tag $(FULL_IMAGE):latest $(FULL_IMAGE):$(TAG) +include ../include.mk -.PHONY: push -push: container -ifeq ($(DOCKER_REGISTRY),gcr.io) - gcloud docker push $(PREFIX)/$(IMAGE):$(TAG) -else - docker push $(PREFIX)/$(IMAGE):$(TAG) -endif +.PHONY: extras +extras: expansion +.PHONY: expansion expansion: cp -R ../../expansion ./opt - -binary: - cp ../../bin/linux-amd64/expandybird ./bin diff --git a/rootfs/include.mk b/rootfs/include.mk new file mode 100644 index 000000000..43d779adb --- /dev/null +++ b/rootfs/include.mk @@ -0,0 +1,69 @@ +# Copyright 2015 The Kubernetes Authors All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# If you update this image please check the tag value before pushing. + +DOCKER_REGISTRY ?= gcr.io +PREFIX := $(DOCKER_REGISTRY)/$(PROJECT) +FULL_IMAGE := $(PREFIX)/$(IMAGE) + +TAG ?= git-$(shell git rev-parse --short HEAD) + +DEFAULT_PLATFORM := $(shell uname | tr '[:upper:]' '[:lower:]') +PLATFORM ?= $(DEFAULT_PLATFORM) + +DEFAULT_ARCH := $(shell uname -m) +ARCH ?= $(DEFAULT_ARCH) + +.PHONY: info +info: + @echo "Build tag: ${TAG}" + @echo "Registry: ${DOCKER_REGISTRY}" + @echo "Project: ${PROJECT}" + @echo "Image: ${IMAGE}" + @echo "Platform: ${PLATFORM}" + @echo "Arch: ${ARCH}" + +.PHONY : .project + +.PHONY: push +push: container +ifeq ($(DOCKER_REGISTRY),gcr.io) + gcloud docker push $(FULL_IMAGE):$(TAG) +else + docker push $(FULL_IMAGE):$(TAG) +endif + +.PHONY: container +container: .project .docker binary extras + docker build -t $(FULL_IMAGE):latest -f Dockerfile . + docker tag -f $(FULL_IMAGE):latest $(FULL_IMAGE):$(TAG) + +.project: + @if [[ -z "${PROJECT}" ]]; then echo "PROJECT variable must be set"; exit 1; fi + +.docker: + @if [[ -z `which docker` ]] || ! docker version &> /dev/null; then echo "docker is not installed correctly"; exit 1; fi + +CROSS_IMAGE := $(PLATFORM)-$(ARCH)/$(IMAGE)/$(IMAGE) + +.PHONY: binary +binary: + @if [[ -z $(CROSS_IMAGE) ]]; then \ + echo cp ../../bin/$(CROSS_IMAGE) ./bin ; \ + cp ../../bin/$(CROSS_IMAGE) ./bin ; \ + else \ + echo cp ../../bin/$(IMAGE) ./bin ; \ + cp ../../bin/$(IMAGE) ./bin ; \ + fi diff --git a/rootfs/manager/Makefile b/rootfs/manager/Makefile index f8276efa7..4c38b8e40 100644 --- a/rootfs/manager/Makefile +++ b/rootfs/manager/Makefile @@ -12,30 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -DOCKER_REGISTRY := gcr.io -PREFIX := $(DOCKER_REGISTRY)/$(PROJECT) IMAGE ?= manager -TAG ?= git-$(shell git rev-parse --short HEAD) -FULL_IMAGE := $(PREFIX)/$(IMAGE) - KUBE_VERSION ?= v1.1.7 -.PHONY: container -container: binary kubectl - docker build -t $(FULL_IMAGE):latest -f Dockerfile . - docker tag $(FULL_IMAGE):latest $(FULL_IMAGE):$(TAG) - -.PHONY: push -push: container -ifeq ($(DOCKER_REGISTRY),gcr.io) - gcloud docker push $(PREFIX)/$(IMAGE):$(TAG) -else - docker push $(PREFIX)/$(IMAGE):$(TAG) -endif +include ../include.mk -binary: - cp ../../bin/linux-amd64/manager ./bin +.PHONY: extras +extras: kubectl +.PHONY: kubectl kubectl: curl -fsSL -o bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${KUBE_VERSION}/bin/linux/amd64/kubectl chmod +x bin/kubectl diff --git a/rootfs/resourcifier/Makefile b/rootfs/resourcifier/Makefile index a02d14728..7925b04e1 100644 --- a/rootfs/resourcifier/Makefile +++ b/rootfs/resourcifier/Makefile @@ -12,30 +12,20 @@ # See the License for the specific language governing permissions and # limitations under the License. -DOCKER_REGISTRY := gcr.io -PREFIX := $(DOCKER_REGISTRY)/$(PROJECT) IMAGE ?= resourcifier -TAG ?= git-$(shell git rev-parse --short HEAD) -FULL_IMAGE := $(PREFIX)/$(IMAGE) + KUBE_VERSION ?= v1.1.7 -KUBE_VERSION ?= v1.1.7 +include ../include.mk -.PHONY: container -container: binary kubectl - docker build -t $(FULL_IMAGE):latest -f Dockerfile . - docker tag $(FULL_IMAGE):latest $(FULL_IMAGE):$(TAG) +.PHONY: extras +extras: expansion kubectl -.PHONY: push -push: container -ifeq ($(DOCKER_REGISTRY),gcr.io) - gcloud docker push $(PREFIX)/$(IMAGE):$(TAG) -else - docker push $(PREFIX)/$(IMAGE):$(TAG) -endif - -binary: - cp ../../bin/linux-amd64/resourcifier ./bin +.PHONY: expansion +expansion: + cp -R ../../expansion ./opt +.PHONY: kubectl kubectl: curl -fsSL -o bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${KUBE_VERSION}/bin/linux/amd64/kubectl chmod +x bin/kubectl + \ No newline at end of file