# Copyright 2019 Tigera, Inc
#
# 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 GIT_VERSION=unknown
ARG UBI_IMAGE

FROM ${UBI_IMAGE} as ubi

# Add in top-level license file
RUN mkdir /licenses
COPY LICENSE /licenses

# Make sure the status file is owned by our user.
RUN mkdir /status
RUN touch /status/status.json && chown 999 /status/status.json

FROM scratch
LABEL name="Calico Flannel migration controller" \
      vendor="Project Calico" \
      version=$GIT_VERSION \
      release="1" \
      summary="Calico Flannel migration controller updates a flannel cluster to Calico" \
      description="Calico Flannel migration controller updates a flannel cluster to Calico" \
      maintainer="Song Jiang <song@tigera.io>"

COPY --from=ubi /licenses /licenses
COPY --from=ubi /status /status
COPY --from=ubi /usr/include /usr/include
COPY --from=ubi /lib64/libpthread.so.0 /lib64/libpthread.so.0
COPY --from=ubi /lib64/libc.so.6 /lib64/libc.so.6
COPY --from=ubi /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2

# Copy hostname configuration files from UBI so glibc hostname lookups work.
COPY --from=ubi /etc/host.conf /etc/host.conf
COPY --from=ubi /etc/nsswitch.conf /etc/nsswitch.conf

ARG BIN_DIR
ADD ${BIN_DIR}/kubectl-amd64 /usr/bin/kubectl
ADD ${BIN_DIR}/kube-controllers-linux-amd64 /usr/bin/kube-controllers
ADD ${BIN_DIR}/check-status-linux-amd64 /usr/bin/check-status
USER 999
ENTRYPOINT ["/usr/bin/kube-controllers"]
