Skip to content

Commit

Permalink
Add missing cross-compile elements
Browse files Browse the repository at this point in the history
  • Loading branch information
deitch committed Apr 16, 2018
1 parent b3ceec0 commit 16acdd9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ help:
all: calico/typha bin/typha-client-$(ARCH)
test: ut

# Targets used when cross building.
.PHONY: register
# Enable binfmt adding support for miscellaneous binary formats.
# This is only needed when running non-native binaries.
register:
ifneq ($(BUILDARCH),$(ARCH))
docker run --rm --privileged multiarch/qemu-user-static:register || true
endif


# Figure out version information. To support builds from release tarballs, we default to
# <unknown> if this isn't a git checkout.
GIT_COMMIT:=$(shell git rev-parse HEAD || echo '<unknown>')
Expand Down Expand Up @@ -133,6 +143,7 @@ DOCKER_GO_BUILD := mkdir -p .go-pkg-cache && \
--net=host \
$(EXTRA_DOCKER_ARGS) \
-e LOCAL_USER_ID=$(MY_UID) \
-e GOARCH=$(ARCH) \
-v $${PWD}:/go/src/github.com/projectcalico/typha:rw \
-v $${PWD}/.go-pkg-cache:/go/pkg:rw \
-w /go/src/github.com/projectcalico/typha \
Expand Down Expand Up @@ -171,7 +182,7 @@ LDFLAGS:=-ldflags "\
.PHONY: build
build: bin/calico-typha
bin/calico-typha: bin/calico-typha-$(ARCH)
bin/calico-typha-$(ARCH): $(TYPHA_GO_FILES) vendor/.up-to-date
bin/calico-typha-$(ARCH): $(TYPHA_GO_FILES) register vendor/.up-to-date
@echo Building typha...
mkdir -p bin
$(DOCKER_GO_BUILD) \
Expand Down
18 changes: 14 additions & 4 deletions docker-image/Dockerfile.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,27 @@ RUN chmod +x /usr/bin/qemu-*
FROM arm64v8/alpine:3.6 as base
MAINTAINER Shaun Crampton <shaun@tigera.io>

# Enable non-native builds of this image on an amd64 hosts.
# This must before any RUN command in this image!
# we only need this for the intermediate "base" image, so we can run all the apk and other commands
# and this is only because of using older kernels
COPY --from=qemu /usr/bin/qemu-*-static /usr/bin/

# Since our binary isn't designed to run as PID 1, run it via the tini init daemon.
RUN apk add --update tini
ENTRYPOINT ["/sbin/tini", "--"]

ADD typha.cfg /etc/calico/typha.cfg
FROM scratch
COPY --from=base /sbin/tini /sbin/tini
COPY --from=base /lib/ld-musl-aarch64.so.1 /lib/libc.musl-aarch64.so.1 /lib/

# Put out binary in /code rather than directly in /usr/bin. This allows the downstream builds
# Put our binary in /code rather than directly in /usr/bin. This allows the downstream builds
# to more easily extract the build artefacts from the container.
RUN mkdir /code
ADD bin/calico-typha-arm64 /code/calico-typha
ADD typha.cfg /etc/calico/typha.cfg

WORKDIR /code
ENV PATH "$PATH:/code"

# Run Typha by default
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["calico-typha"]
18 changes: 14 additions & 4 deletions docker-image/Dockerfile.ppc64le
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,27 @@ RUN chmod +x /usr/bin/qemu-*
FROM ppc64le/alpine:3.6 as base
MAINTAINER Shaun Crampton <shaun@tigera.io>

# Enable non-native builds of this image on an amd64 hosts.
# This must before any RUN command in this image!
# we only need this for the intermediate "base" image, so we can run all the apk and other commands
# and this is only because of using older kernels
COPY --from=qemu /usr/bin/qemu-*-static /usr/bin/

# Since our binary isn't designed to run as PID 1, run it via the tini init daemon.
RUN apk add --update tini
ENTRYPOINT ["/sbin/tini", "--"]

ADD typha.cfg /etc/calico/typha.cfg
FROM scratch
COPY --from=base /sbin/tini /sbin/tini
COPY --from=base /lib/ld-musl-powerpc64le.so.1 /lib/libc.musl-ppc64le.so.1 /lib/

# Put out binary in /code rather than directly in /usr/bin. This allows the downstream builds
# Put our binary in /code rather than directly in /usr/bin. This allows the downstream builds
# to more easily extract the build artefacts from the container.
RUN mkdir /code
ADD bin/calico-typha-ppc64le /code/calico-typha
ADD typha.cfg /etc/calico/typha.cfg

WORKDIR /code
ENV PATH "$PATH:/code"

# Run Typha by default
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["calico-typha"]

0 comments on commit 16acdd9

Please sign in to comment.