|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | | -.PHONY: build push |
| 15 | +.PHONY: all push push-legacy container clean |
16 | 16 |
|
17 | | -TAG=2.0 |
18 | | -REGISTRY?="gcr.io/google_containers" |
| 17 | +REGISTRY ?= gcr.io/google_containers |
| 18 | +IMAGE = $(REGISTRY)/pause-$(ARCH) |
| 19 | +LEGACY_AMD64_IMAGE = $(REGISTRY)/pause |
| 20 | + |
| 21 | +TAG = 3.0 |
19 | 22 |
|
20 | 23 | # Architectures supported: amd64, arm, arm64 and ppc64le |
21 | | -ARCH?=amd64 |
22 | | -GOLANG_VERSION=1.6 |
23 | | -TEMP_DIR:=$(shell mktemp -d) |
| 24 | +ARCH ?= amd64 |
| 25 | + |
| 26 | +ALL_ARCH = amd64 arm arm64 ppc64le |
| 27 | + |
| 28 | +CFLAGS = -Os -Wall -static |
| 29 | +KUBE_CROSS_IMAGE ?= gcr.io/google_containers/kube-cross |
| 30 | +KUBE_CROSS_VERSION ?= $(shell cat ../build-image/cross/VERSION) |
| 31 | + |
| 32 | +BIN = pause |
| 33 | +SRCS = pause.c |
24 | 34 |
|
25 | | -all: push-legacy-too |
| 35 | +ifeq ($(ARCH),amd64) |
| 36 | + TRIPLE ?= x86_64-linux-gnu |
| 37 | +endif |
26 | 38 |
|
27 | | -build: |
28 | | - cp pause.go Dockerfile $(TEMP_DIR) |
| 39 | +ifeq ($(ARCH),arm) |
| 40 | + TRIPLE ?= arm-linux-gnueabi |
| 41 | +endif |
29 | 42 |
|
30 | | - docker run -it -v $(TEMP_DIR):/build golang:$(GOLANG_VERSION) /bin/bash -c \ |
31 | | - "cd /build && CGO_ENABLED=0 GOARM=6 GOARCH=$(ARCH) go build -a -installsuffix cgo -ldflags '-w' ./pause.go" |
| 43 | +ifeq ($(ARCH),arm64) |
| 44 | + TRIPLE ?= aarch64-linux-gnu |
| 45 | +endif |
32 | 46 |
|
33 | | -ifeq ($(ARCH),$(filter $(ARCH),amd64 arm)) |
34 | | -# Run goupx for amd64 and arm. The condition above is equal to 'if [[ $ARCH == "amd64" || $ARCH == "arm" ]]' in bash |
35 | | - docker run -it -v $(TEMP_DIR):/build golang:$(GOLANG_VERSION) /bin/bash -c \ |
36 | | - "cd /build && apt-get update && apt-get install -y upx \ |
37 | | - && go get github.com/pwaller/goupx && goupx pause" |
| 47 | +ifeq ($(ARCH),ppc64le) |
| 48 | + TRIPLE ?= powerpc64le-linux-gnu |
38 | 49 | endif |
39 | 50 |
|
40 | | - # And build the image |
41 | | - docker build -t $(REGISTRY)/pause-$(ARCH):$(TAG) $(TEMP_DIR) |
| 51 | +# If you want to build AND push all containers, see the 'all-push' rule. |
| 52 | +all: all-container |
42 | 53 |
|
| 54 | +sub-container-%: |
| 55 | + $(MAKE) ARCH=$* container |
| 56 | + |
| 57 | +sub-push-%: |
| 58 | + $(MAKE) ARCH=$* push |
| 59 | + |
| 60 | +all-container: $(addprefix sub-container-,$(ALL_ARCH)) |
| 61 | + |
| 62 | +all-push: $(addprefix sub-push-,$(ALL_ARCH)) |
| 63 | + |
| 64 | +build: bin/$(BIN)-$(ARCH) |
| 65 | + |
| 66 | +bin/$(BIN)-$(ARCH): $(SRCS) |
| 67 | + mkdir -p bin |
| 68 | + docker run -u $$(id -u):$$(id -g) -v $$(pwd):/build \ |
| 69 | + $(KUBE_CROSS_IMAGE):$(KUBE_CROSS_VERSION) \ |
| 70 | + /bin/bash -c "\ |
| 71 | + cd /build && \ |
| 72 | + $(TRIPLE)-gcc $(CFLAGS) -o $@ $^ && \ |
| 73 | + $(TRIPLE)-strip $@" |
| 74 | + |
| 75 | +container: .container-$(ARCH) |
| 76 | +.container-$(ARCH): bin/$(BIN)-$(ARCH) |
| 77 | + docker build -t $(IMAGE):$(TAG) --build-arg ARCH=$(ARCH) . |
43 | 78 | ifeq ($(ARCH),amd64) |
44 | | - docker tag -f $(REGISTRY)/pause-$(ARCH):$(TAG) $(REGISTRY)/pause:$(TAG) |
| 79 | + docker tag -f $(IMAGE):$(TAG) $(LEGACY_AMD64_IMAGE):$(TAG) |
45 | 80 | endif |
| 81 | + touch $@ |
46 | 82 |
|
47 | | -push: build |
48 | | - gcloud docker --server=gcr.io push $(REGISTRY)/pause-$(ARCH):$(TAG) |
| 83 | +push: .push-$(ARCH) |
| 84 | +.push-$(ARCH): .container-$(ARCH) |
| 85 | + gcloud docker push $(IMAGE):$(TAG) |
| 86 | + touch $@ |
49 | 87 |
|
50 | | -push-legacy-too: push |
| 88 | +push-legacy: .push-legacy-$(ARCH) |
| 89 | +.push-legacy-$(ARCH): .container-$(ARCH) |
51 | 90 | ifeq ($(ARCH),amd64) |
52 | | - gcloud docker push $(REGISTRY)/pause:$(TAG) |
| 91 | + gcloud docker push $(LEGACY_AMD64_IMAGE):$(TAG) |
53 | 92 | endif |
| 93 | + touch $@ |
| 94 | + |
| 95 | +clean: |
| 96 | + rm -rf .container-* .push-* bin/ |
0 commit comments