Skip to content

Commit 520cd7e

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request #31241 from m1093782566/m109-cross-build-serve-hostname
Automatic merge from submit-queue Cross-build test/images/serve_hostname <!-- Thanks for sending a pull request! Here are some tips for you: 1. If this is your first time, read our contributor guidelines https://github.com/kubernetes/kubernetes/blob/master/CONTRIBUTING.md and developer guide https://github.com/kubernetes/kubernetes/blob/master/docs/devel/development.md 2. If you want *faster* PR reviews, read how: https://github.com/kubernetes/kubernetes/blob/master/docs/devel/faster_reviews.md 3. Follow the instructions for writing a release note: https://github.com/kubernetes/kubernetes/blob/master/docs/devel/pull-requests.md#release-notes --> **What this PR does / why we need it**: **cross build** `test/images/serve_hostname` https://github.com/kubernetes/kubernetes/tree/master/test/images/serve_hostname This PR is an effort to achieve multiarch Kubernetes(#26863) **Which issue this PR fixes** : fixes #31238 @luxas @spxtr
2 parents a29ab08 + be889f8 commit 520cd7e

File tree

3 files changed

+108
-20
lines changed

3 files changed

+108
-20
lines changed

test/images/serve_hostname/Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
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 Tim Hockin <[email protected]>
1717
ADD serve_hostname /serve_hostname
18-
ADD serve_hostname.go /serve_hostname.go
1918
EXPOSE 9376
2019
ENTRYPOINT ["/serve_hostname"]

test/images/serve_hostname/Makefile

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

15-
all: serve_hostname
15+
# Cross-build the serve_hostname image
16+
#
17+
# Usage:
18+
# [TAG=v1.5] [PREFIX=gcr.io/google_containers] [TEST_REGISTRY=b.gcr.io/k8s_authenticated_test] [ARCH=amd64] [BASEIMAGE=busybox] make all
19+
20+
.PHONY: all push container clean
21+
22+
TAG ?= v1.5
23+
24+
REGISTRY ?= gcr.io/google_containers
25+
TEST_REGISTRY ?= b.gcr.io/k8s_authenticated_test
26+
27+
# Architectures supported: amd64, arm, arm64 and ppc64le
28+
ARCH ?= amd64
29+
30+
ALL_ARCH = amd64 arm arm64 ppc64le
31+
32+
GOARM=6
33+
TEMP_DIR := $(shell mktemp -d)
34+
GOLANG_VERSION = 1.6.3
35+
36+
BIN = serve_hostname
37+
SRCS = serve_hostname.go
38+
39+
IMAGE = $(REGISTRY)/$(BIN)-$(ARCH)
40+
TEST_IMAGE = $(TEST_REGISTRY)/$(BIN)-$(ARCH)
1641

17-
TAG = v1.4
18-
PREFIX = gcr.io/google_containers
19-
TEST_PREFIX = b.gcr.io/k8s_authenticated_test
42+
# Set default base image dynamically for each arch
43+
ifeq ($(ARCH),amd64)
44+
BASEIMAGE?=busybox
45+
endif
46+
ifeq ($(ARCH),arm)
47+
BASEIMAGE?=armel/busybox
48+
endif
49+
ifeq ($(ARCH),arm64)
50+
BASEIMAGE?=aarch64/busybox
51+
endif
52+
ifeq ($(ARCH),ppc64le)
53+
BASEIMAGE?=ppc64le/busybox
54+
endif
2055

21-
serve_hostname: serve_hostname.go
22-
CGO_ENABLED=0 go build -a -installsuffix cgo --ldflags '-w' ./serve_hostname.go
56+
# If you want to build AND push all containers, see the 'all-push' rule.
57+
all: all-container
2358

24-
container: serve_hostname
25-
docker build -t $(PREFIX)/serve_hostname:$(TAG) .
26-
if [ -n "$(TEST_PREFIX)" ]; then \
27-
docker tag -f $(PREFIX)/serve_hostname:$(TAG) $(TEST_PREFIX)/serve_hostname:$(TAG); \
59+
sub-container-%:
60+
$(MAKE) ARCH=$* container
61+
62+
sub-push-%:
63+
$(MAKE) ARCH=$* push
64+
65+
all-container: $(addprefix sub-container-,$(ALL_ARCH))
66+
67+
all-push: $(addprefix sub-push-,$(ALL_ARCH))
68+
69+
build: bin/$(BIN)-$(ARCH)
70+
71+
bin/$(BIN)-$(ARCH): $(SRCS)
72+
# Copy the content in this dir to the temp dir
73+
cp ./* $(TEMP_DIR)
74+
75+
docker run -it -v $(TEMP_DIR):/build \
76+
golang:$(GOLANG_VERSION) \
77+
/bin/bash -c "\
78+
cd /build && \
79+
CGO_ENABLED=0 GOARM=$(GOARM) GOARCH=$(ARCH) go build -a -installsuffix cgo --ldflags '-w' -o $(BIN) ./$(SRCS)"
80+
81+
container: .container-$(ARCH)
82+
.container-$(ARCH): bin/$(BIN)-$(ARCH)
83+
# Set the base image
84+
cd $(TEMP_DIR) && sed -i.bak 's|BASEIMAGE|$(BASEIMAGE)|g' Dockerfile
85+
86+
docker build -t $(IMAGE):$(TAG) $(TEMP_DIR)
87+
if [ -n "$(TEST_REGISTRY)" ]; then \
88+
docker tag $(IMAGE):$(TAG) $(TEST_IMAGE):$(TAG) ;\
2889
fi
2990

30-
push:
31-
gcloud docker push $(PREFIX)/serve_hostname:$(TAG)
32-
if [ -n "$(TEST_PREFIX)" ]; then \
33-
gcloud docker push $(TEST_PREFIX)/serve_hostname:$(TAG); \
91+
push: .push-$(ARCH)
92+
.push-$(ARCH): .container-$(ARCH)
93+
gcloud docker push $(IMAGE):$(TAG)
94+
if [ -n "$(TEST_REGISTRY)" ]; then \
95+
gcloud docker push $(TEST_IMAGE):$(TAG) ;\
3496
fi
3597

3698
clean:
37-
rm -f serve_hostname
99+
rm -rf $(BIN)
100+

test/images/serve_hostname/README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
1-
serve_hostname
2-
==============
1+
## serve_hostname
32

4-
Util app to serve your hostname on TCP and/or UDP. Useful for testing.
3+
This is a small util app to serve your hostname on TCP and/or UDP. Useful for testing.
4+
5+
The `serve_hostname` Makefile supports multiple architectures, which means it may cross-compile and build an docker image easily.
6+
Arch-specific busybox images serve as base images.
7+
8+
If you are releasing a new version, please bump the `TAG` value in the `Makefile` before building the images.
9+
10+
## How to release:
11+
12+
```
13+
# Build cross-platform binaries
14+
$ make all-push
15+
16+
# Build for linux/amd64 (default)
17+
$ make push ARCH=amd64
18+
# ---> gcr.io/google_containers/serve_hostname-amd64:TAG
19+
20+
$ make push ARCH=arm
21+
# ---> gcr.io/google_containers/serve_hostname-arm:TAG
22+
23+
$ make push ARCH=arm64
24+
# ---> gcr.io/google_containers/serve_hostname-arm64:TAG
25+
26+
$ make push ARCH=ppc64le
27+
# ---> gcr.io/google_containers/serve_hostname-ppc64le:TAG
28+
```
29+
30+
Of course, if you don't want to push the images, run `make all-container` or `make container ARCH={target_arch}` instead.
531

632

733
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/contrib/for-demos/serve_hostname/README.md?pixel)]()

0 commit comments

Comments
 (0)