FROM gcr.io/pingcap-public/pingcap/alpine-glibc:alpine-3.14.6

ARG HELM_VERSION=v3.19.0
ARG HELM_DIFF_VERSION=v3.9.14

# Set Helm home dirs to world-readable locations so uid 65534 (non-root) can use them at runtime.
# HELM_CACHE_HOME and HELM_CONFIG_HOME are set to /tmp paths which are writable at runtime.
ENV HELM_DATA_HOME=/usr/local/share/helm \
    HELM_PLUGINS=/usr/local/share/helm/plugins \
    HELM_CACHE_HOME=/tmp/.helm/cache \
    HELM_CONFIG_HOME=/tmp/.helm/config

RUN apk add --no-cache ca-certificates curl git tar gzip && \
    curl -fsSL "https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz" -o /tmp/helm.tgz && \
    tar -xzf /tmp/helm.tgz -C /tmp && \
    mv /tmp/linux-amd64/helm /usr/local/bin/helm && \
    chmod +x /usr/local/bin/helm && \
    mkdir -p "${HELM_PLUGINS}" && \
    helm plugin install https://github.com/databus23/helm-diff --version "${HELM_DIFF_VERSION}" && \
    chmod -R 755 "${HELM_DATA_HOME}" && \
    rm -rf /tmp/helm.tgz /tmp/linux-amd64 /root/.cache

COPY observability-ops-server /usr/local/bin/observability-ops-server
ENTRYPOINT ["/usr/local/bin/observability-ops-server"]
