Skip to content
This repository was archived by the owner on Apr 17, 2019. It is now read-only.

Commit 6422b9e

Browse files
authored
Merge pull request #1156 from luxas/ingress_multiarch
Cross-compile 404-server
2 parents 4192c7c + 093aa46 commit 6422b9e

File tree

3 files changed

+92
-8
lines changed

3 files changed

+92
-8
lines changed

404-server/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM busybox
15+
FROM BASEIMAGE
1616
MAINTAINER Prashanth B <[email protected]>
17-
ADD server server
17+
COPY server /
1818
ENTRYPOINT ["/server"]

404-server/Makefile

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,69 @@
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+
121
all: push
222

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
642

743
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
945

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)
1257

1358
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)
1465
gcloud docker push $(PREFIX):$(TAG)
66+
endif
1567

1668
clean:
1769
rm -f server

404-server/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# 404-server (default backend)
2+
3+
404-server is a simple webserver that satisfies the ingress, which means it have to do two things:
4+
1. It should serve a 404 page at /
5+
2. It should serve 200 on a /healthz endpoint
6+
7+
## How to release:
8+
9+
The `404-server` Makefile supports multiple architecures, which means it may cross-compile and build an docker image easily.
10+
If you are releasing a new version, please bump the `TAG` value in the `Makefile` before building the images.
11+
12+
How to build and push all images:
13+
```
14+
# Build for linux/amd64 (default)
15+
$ make push
16+
$ make push ARCH=amd64
17+
# ---> gcr.io/google_containers/defaultbackend-amd64:TAG
18+
19+
$ make push-legacy ARCH=amd64
20+
# ---> gcr.io/google_containers/defaultbackend:TAG (image with backwards compatible naming)
21+
22+
$ make push ARCH=arm
23+
# ---> gcr.io/google_containers/defaultbackend-arm:TAG
24+
25+
$ make push ARCH=arm64
26+
# ---> gcr.io/google_containers/defaultbackend-arm64:TAG
27+
28+
$ make push ARCH=ppc64le
29+
# ---> gcr.io/google_containers/defaultbackend-ppc64le:TAG
30+
```
31+
32+
Of course, if you don't want to push the images, just run `make container`

0 commit comments

Comments
 (0)