github.com/munnerz/test-infra@v0.0.0-20190108210205-ce3d181dc989/gcsweb/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 # The binary to build (just the basename). 16 BIN := gcsweb 17 18 # This repo's root import path (under GOPATH). 19 PKG := k8s.io/test-infra/gcsweb 20 21 # Where to push the docker image. 22 REGISTRY ?= staging-k8s.gcr.io 23 24 # Which architecture to build - see $(ALL_ARCH) for options. 25 ARCH ?= amd64 26 27 # The version string. 28 VERSION := v1.0.6 29 30 ### 31 ### These variables should not need tweaking. 32 ### 33 34 SRC_DIRS := cmd pkg # directories which hold app source (not vendored) 35 36 # Other architectures are not supported because I don't know how to get CA 37 # certs for busybox. 38 # arm arm64 ppc64le 39 ALL_ARCH := amd64 40 41 # Set default base image dynamically for each arch 42 ifeq ($(ARCH),amd64) 43 BASEIMAGE?=alpine 44 endif 45 ifeq ($(ARCH),arm) 46 BASEIMAGE?=armel/busybox 47 endif 48 ifeq ($(ARCH),arm64) 49 BASEIMAGE?=aarch64/busybox 50 endif 51 ifeq ($(ARCH),ppc64le) 52 BASEIMAGE?=ppc64le/busybox 53 endif 54 55 IMAGE := $(REGISTRY)/$(BIN)-$(ARCH) 56 57 BUILD_IMAGE ?= golang:1.9.3-alpine 58 59 # If you want to build all binaries, see the 'all-build' rule. 60 # If you want to build all containers, see the 'all-container' rule. 61 # If you want to build AND push all containers, see the 'all-push' rule. 62 all: build 63 64 build-%: 65 @$(MAKE) --no-print-directory ARCH=$* build 66 67 container-%: 68 @$(MAKE) --no-print-directory ARCH=$* container 69 70 push-%: 71 @$(MAKE) --no-print-directory ARCH=$* push 72 73 all-build: $(addprefix build-, $(ALL_ARCH)) 74 75 all-container: $(addprefix container-, $(ALL_ARCH)) 76 77 all-push: $(addprefix push-, $(ALL_ARCH)) 78 79 build: bin/$(ARCH)/$(BIN) 80 81 bin/$(ARCH)/$(BIN): build-dirs 82 @echo "building: $@" 83 @docker run \ 84 -ti \ 85 -u $$(id -u):$$(id -g) \ 86 -v $$(pwd)/.go:/go \ 87 -v $$(pwd):/go/src/$(PKG) \ 88 -v $$(pwd)/bin/$(ARCH):/go/bin \ 89 -v $$(pwd)/bin/$(ARCH):/go/bin/$$(go env GOOS)_$(ARCH) \ 90 -v $$(pwd)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static \ 91 -w /go/src/$(PKG) \ 92 $(BUILD_IMAGE) \ 93 /bin/sh -c " \ 94 ARCH=$(ARCH) \ 95 VERSION=$(VERSION) \ 96 PKG=$(PKG) \ 97 ./build/build.sh \ 98 " 99 100 DOTFILE_IMAGE = $(subst /,_,$(IMAGE))-$(VERSION) 101 102 container: .container-$(DOTFILE_IMAGE) container-name 103 .container-$(DOTFILE_IMAGE): bin/$(ARCH)/$(BIN) Dockerfile.in 104 @sed \ 105 -e 's|ARG_BIN|$(BIN)|g' \ 106 -e 's|ARG_ARCH|$(ARCH)|g' \ 107 -e 's|ARG_FROM|$(BASEIMAGE)|g' \ 108 Dockerfile.in > .dockerfile-$(ARCH) 109 @docker build -t $(IMAGE):$(VERSION) -f .dockerfile-$(ARCH) . 110 @docker images -q $(IMAGE):$(VERSION) > $@ 111 112 container-name: 113 @echo "container: $(IMAGE):$(VERSION)" 114 115 push: .push-$(DOTFILE_IMAGE) push-name 116 .push-$(DOTFILE_IMAGE): .container-$(DOTFILE_IMAGE) 117 @docker push $(IMAGE):$(VERSION) 118 @docker images -q $(IMAGE):$(VERSION) > $@ 119 120 push-name: 121 @echo "pushed: $(IMAGE):$(VERSION)" 122 123 version: 124 @echo $(VERSION) 125 126 test: build-dirs 127 @docker run \ 128 -ti \ 129 -u $$(id -u):$$(id -g) \ 130 -v $$(pwd)/.go:/go \ 131 -v $$(pwd):/go/src/$(PKG) \ 132 -v $$(pwd)/bin/$(ARCH):/go/bin \ 133 -v $$(pwd)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static \ 134 -w /go/src/$(PKG) \ 135 $(BUILD_IMAGE) \ 136 /bin/sh -c " \ 137 ./build/test.sh $(SRC_DIRS) \ 138 " 139 140 build-dirs: 141 @mkdir -p bin/$(ARCH) 142 @mkdir -p .go/src/$(PKG) .go/pkg .go/bin .go/std/$(ARCH) 143 144 clean: container-clean bin-clean 145 146 container-clean: 147 rm -rf .container-* .dockerfile-* .push-* 148 149 bin-clean: 150 rm -rf .go bin