Skip to content

Commit

Permalink
Merge pull request kubernetes#31241 from m1093782566/m109-cross-build…
Browse files Browse the repository at this point in the history
…-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(kubernetes#26863)

**Which issue this PR fixes** : 

fixes kubernetes#31238 

@luxas @spxtr
  • Loading branch information
Kubernetes Submit Queue authored Sep 12, 2016
2 parents a29ab08 + be889f8 commit 520cd7e
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 20 deletions.
3 changes: 1 addition & 2 deletions test/images/serve_hostname/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM busybox
FROM BASEIMAGE
MAINTAINER Tim Hockin <[email protected]>
ADD serve_hostname /serve_hostname
ADD serve_hostname.go /serve_hostname.go
EXPOSE 9376
ENTRYPOINT ["/serve_hostname"]
93 changes: 78 additions & 15 deletions test/images/serve_hostname/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,89 @@
# See the License for the specific language governing permissions and
# limitations under the License.

all: serve_hostname
# Cross-build the serve_hostname image
#
# Usage:
# [TAG=v1.5] [PREFIX=gcr.io/google_containers] [TEST_REGISTRY=b.gcr.io/k8s_authenticated_test] [ARCH=amd64] [BASEIMAGE=busybox] make all

.PHONY: all push container clean

TAG ?= v1.5

REGISTRY ?= gcr.io/google_containers
TEST_REGISTRY ?= b.gcr.io/k8s_authenticated_test

# Architectures supported: amd64, arm, arm64 and ppc64le
ARCH ?= amd64

ALL_ARCH = amd64 arm arm64 ppc64le

GOARM=6
TEMP_DIR := $(shell mktemp -d)
GOLANG_VERSION = 1.6.3

BIN = serve_hostname
SRCS = serve_hostname.go

IMAGE = $(REGISTRY)/$(BIN)-$(ARCH)
TEST_IMAGE = $(TEST_REGISTRY)/$(BIN)-$(ARCH)

TAG = v1.4
PREFIX = gcr.io/google_containers
TEST_PREFIX = b.gcr.io/k8s_authenticated_test
# Set default base image dynamically for each arch
ifeq ($(ARCH),amd64)
BASEIMAGE?=busybox
endif
ifeq ($(ARCH),arm)
BASEIMAGE?=armel/busybox
endif
ifeq ($(ARCH),arm64)
BASEIMAGE?=aarch64/busybox
endif
ifeq ($(ARCH),ppc64le)
BASEIMAGE?=ppc64le/busybox
endif

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

container: serve_hostname
docker build -t $(PREFIX)/serve_hostname:$(TAG) .
if [ -n "$(TEST_PREFIX)" ]; then \
docker tag -f $(PREFIX)/serve_hostname:$(TAG) $(TEST_PREFIX)/serve_hostname:$(TAG); \
sub-container-%:
$(MAKE) ARCH=$* container

sub-push-%:
$(MAKE) ARCH=$* push

all-container: $(addprefix sub-container-,$(ALL_ARCH))

all-push: $(addprefix sub-push-,$(ALL_ARCH))

build: bin/$(BIN)-$(ARCH)

bin/$(BIN)-$(ARCH): $(SRCS)
# Copy the content in this dir to the temp dir
cp ./* $(TEMP_DIR)

docker run -it -v $(TEMP_DIR):/build \
golang:$(GOLANG_VERSION) \
/bin/bash -c "\
cd /build && \
CGO_ENABLED=0 GOARM=$(GOARM) GOARCH=$(ARCH) go build -a -installsuffix cgo --ldflags '-w' -o $(BIN) ./$(SRCS)"

container: .container-$(ARCH)
.container-$(ARCH): bin/$(BIN)-$(ARCH)
# Set the base image
cd $(TEMP_DIR) && sed -i.bak 's|BASEIMAGE|$(BASEIMAGE)|g' Dockerfile

docker build -t $(IMAGE):$(TAG) $(TEMP_DIR)
if [ -n "$(TEST_REGISTRY)" ]; then \
docker tag $(IMAGE):$(TAG) $(TEST_IMAGE):$(TAG) ;\
fi

push:
gcloud docker push $(PREFIX)/serve_hostname:$(TAG)
if [ -n "$(TEST_PREFIX)" ]; then \
gcloud docker push $(TEST_PREFIX)/serve_hostname:$(TAG); \
push: .push-$(ARCH)
.push-$(ARCH): .container-$(ARCH)
gcloud docker push $(IMAGE):$(TAG)
if [ -n "$(TEST_REGISTRY)" ]; then \
gcloud docker push $(TEST_IMAGE):$(TAG) ;\
fi

clean:
rm -f serve_hostname
rm -rf $(BIN)

32 changes: 29 additions & 3 deletions test/images/serve_hostname/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
serve_hostname
==============
## serve_hostname

Util app to serve your hostname on TCP and/or UDP. Useful for testing.
This is a small util app to serve your hostname on TCP and/or UDP. Useful for testing.

The `serve_hostname` Makefile supports multiple architectures, which means it may cross-compile and build an docker image easily.
Arch-specific busybox images serve as base images.

If you are releasing a new version, please bump the `TAG` value in the `Makefile` before building the images.

## How to release:

```
# Build cross-platform binaries
$ make all-push
# Build for linux/amd64 (default)
$ make push ARCH=amd64
# ---> gcr.io/google_containers/serve_hostname-amd64:TAG
$ make push ARCH=arm
# ---> gcr.io/google_containers/serve_hostname-arm:TAG
$ make push ARCH=arm64
# ---> gcr.io/google_containers/serve_hostname-arm64:TAG
$ make push ARCH=ppc64le
# ---> gcr.io/google_containers/serve_hostname-ppc64le:TAG
```

Of course, if you don't want to push the images, run `make all-container` or `make container ARCH={target_arch}` instead.


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

0 comments on commit 520cd7e

Please sign in to comment.