# Copyright (c) 2018-2020 Tigera, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

ARG QEMU_IMAGE=calico/go-build:latest

FROM ${QEMU_IMAGE} as qemu
FROM s390x/debian:9.8-slim as base
MAINTAINER LoZ Open Source Ecosystem (https://www.ibm.com/developerworks/community/groups/community/lozopensource)

# 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 apt-get and other commands
# and this is only because of using older kernels
# when running on a kernel >= 4.8, this will become less relevant
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.
ENV TINI_VERSION v0.18.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static-s390x /sbin/tini
RUN chmod +x /sbin/tini

FROM scratch
COPY --from=base /sbin/tini /sbin/tini

# 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.
ADD bin/calico-typha-s390x /code/calico-typha
ADD typha.cfg /etc/calico/typha.cfg

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

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