ARG QEMU_IMAGE=calico/go-build:latest
FROM ${QEMU_IMAGE} as qemu

FROM calico/bpftool:v5.0-arm64 as bpftool

FROM arm64v8/alpine:3.8 as base
MAINTAINER Shaun Crampton <shaun@tigera.io>

# Binary to execute as "felix". This allows us to swap out
# alternative builds for the tests.
# TODO: We should just mount this in from the host.
ARG FV_BINARY=bin/calico-felix-arm64

# Enable non-native builds of this image on an amd64 hosts.
# This must be the first RUN command in this file!
# we only need this for the intermediate "base" image, so we can run all the apk and other commands
# when running on a kernel >= 4.8, this will become less relevant
COPY --from=qemu /usr/bin/qemu-aarch64-static /usr/bin/

# Install our dependencies.
RUN apk --no-cache add ip6tables tini ipset iputils iproute2 conntrack-tools file

ADD felix.cfg /etc/calico/felix.cfg
ADD calico-felix-wrapper /usr/bin

# Put our binary in /code rather than directly in /usr/bin.  This allows the downstream builds
# to more easily extract the Felix build artefacts from the container.
ADD $FV_BINARY /code/calico-felix
RUN ln -s /code/calico-felix /usr/bin
COPY --from=bpftool /bpftool /usr/bin
WORKDIR /code

# Since our binary isn't designed to run as PID 1, run it via the tini init daemon.
ENTRYPOINT ["/sbin/tini", "--"]
# Run felix (via the wrapper script) by default
CMD ["calico-felix-wrapper"]
