# BASE_DISTRIBUTION is used to switch between the old base distribution and distroless base images
ARG BASE_DISTRIBUTION=debug

# Version is the base image version from the TLD Makefile
ARG BASE_VERSION=latest
ARG ISTIO_BASE_REGISTRY=gcr.io/istio-release

# The following section is used as base image if BASE_DISTRIBUTION=debug
FROM ${ISTIO_BASE_REGISTRY}/base:${BASE_VERSION} AS debug

# The following section is used as base image if BASE_DISTRIBUTION=distroless
FROM ${ISTIO_BASE_REGISTRY}/iptables:${BASE_VERSION} AS distroless

# This will build the final image based on either debug or distroless from above
# hadolint ignore=DL3006
FROM ${BASE_DISTRIBUTION:-debug}

WORKDIR /

ARG istio_version

# Install ztunnel.
ARG TARGETARCH
COPY ${TARGETARCH:-amd64}/ztunnel /usr/local/bin/ztunnel

# Environment variable indicating the exact build, for debugging
ENV ISTIO_META_ISTIO_VERSION=$istio_version

ENTRYPOINT ["/usr/local/bin/ztunnel"]
