|
| 1 | +# Copyright 2016 The Kubernetes Authors All rights reserved. |
| 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 default backend binary or image for amd64, arm, arm64 and ppc64le |
| 16 | +# |
| 17 | +# Usage: |
| 18 | +# [PREFIX=gcr.io/google_containers/defaultbackend] [ARCH=amd64] [TAG=1.1] make (server|container|push) |
| 19 | + |
| 20 | + |
1 | 21 | all: push |
2 | 22 |
|
3 | | -# 0.0 shouldn't clobber any released builds |
4 | | -TAG = 0.0 |
5 | | -PREFIX = gcr.io/google_containers/defaultbackend |
| 23 | +TAG=1.1 |
| 24 | +PREFIX?=gcr.io/google_containers/defaultbackend |
| 25 | +ARCH?=amd64 |
| 26 | +GOLANG_VERSION=1.6 |
| 27 | +TEMP_DIR:=$(shell mktemp -d) |
| 28 | + |
| 29 | +# Set default base image dynamically for each arch |
| 30 | +ifeq ($(ARCH),amd64) |
| 31 | + BASEIMAGE?=busybox |
| 32 | +endif |
| 33 | +ifeq ($(ARCH),arm) |
| 34 | + BASEIMAGE?=armel/busybox |
| 35 | +endif |
| 36 | +ifeq ($(ARCH),arm64) |
| 37 | + BASEIMAGE?=aarch64/busybox |
| 38 | +endif |
| 39 | +ifeq ($(ARCH),ppc64le) |
| 40 | + BASEIMAGE?=ppc64le/busybox |
| 41 | +endif |
6 | 42 |
|
7 | 43 | server: server.go |
8 | | - CGO_ENABLED=0 GOOS=linux godep go build -a -installsuffix cgo -ldflags '-w' -o server ./server.go |
| 44 | + CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) GOARM=6 go build -a -installsuffix cgo -ldflags '-w' -o server ./server.go |
9 | 45 |
|
10 | | -container: server |
11 | | - docker build -t $(PREFIX):$(TAG) . |
| 46 | +container: |
| 47 | + # Copy the whole directory to a temporary dir and set the base image |
| 48 | + cp -r ./* $(TEMP_DIR) |
| 49 | + cd $(TEMP_DIR) && sed -i "s|BASEIMAGE|$(BASEIMAGE)|g" Dockerfile |
| 50 | + |
| 51 | + # Compile the binary inside a container for reliable builds |
| 52 | + docker run --rm -it -v $(TEMP_DIR):/build golang:$(GOLANG_VERSION) /bin/bash -c "make -C /build server ARCH=$(ARCH)" |
| 53 | + |
| 54 | + docker build -t $(PREFIX)-$(ARCH):$(TAG) $(TEMP_DIR) |
| 55 | + |
| 56 | + rm -rf $(TEMP_DIR) |
12 | 57 |
|
13 | 58 | push: container |
| 59 | + gcloud docker push $(PREFIX)-$(ARCH):$(TAG) |
| 60 | + |
| 61 | +push-legacy: container |
| 62 | +ifeq ($(ARCH),amd64) |
| 63 | + # Backward compatibility. TODO: deprecate this image tag |
| 64 | + docker tag -f $(PREFIX)-$(ARCH):$(TAG) $(PREFIX):$(TAG) |
14 | 65 | gcloud docker push $(PREFIX):$(TAG) |
| 66 | +endif |
15 | 67 |
|
16 | 68 | clean: |
17 | 69 | rm -f server |
0 commit comments