# eom.dev CI tools image (DevOps/software-infrastructure#49, G1).
# Everything a lint/validate job needs, at pinned versions, so jobs start
# without installing anything. Bump VERSION when anything here changes.

# Node is only here so JavaScript actions (actions/checkout etc.) can run
# inside a job that uses this image as its container.
FROM node:24.22.3-trixie-slim AS node

FROM python:3.13.18-slim-trixie

ARG HELM_VERSION=3.22.1
ARG HELM_SHA256=896cf63684a42a723d61c980369d6e588330927deb13676ca0d85006dd6da0ea
ARG KUBECONFORM_VERSION=0.8.0
ARG KUBECONFORM_SHA256=9bc2bffbf71f261128533edaf912153948b7ff238f9a531ae6d34466ec287883
ARG ACTIONLINT_VERSION=1.7.12
ARG ACTIONLINT_SHA256=8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8
ARG HADOLINT_VERSION=2.15.1
ARG HADOLINT_SHA256=c7187db94eeeeca956519a6af171adc31453941a1e777961f6e680f697c8c507
ARG GITLEAKS_VERSION=8.30.1
ARG GITLEAKS_SHA256=551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# hadolint ignore=DL3008
RUN apt-get update \
 && apt-get install -y --no-install-recommends \
      ca-certificates curl git openssh-client jq rsync \
 && rm -rf /var/lib/apt/lists/*

COPY --from=node /usr/local/bin/node /usr/local/bin/node

WORKDIR /tmp/tools
RUN fetch() { curl -fsSL --retry 3 -o "$2" "$1" && echo "$3  $2" | sha256sum -c -; } \
 && fetch "https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz" helm.tgz "${HELM_SHA256}" \
 && tar -xzf helm.tgz --strip-components=1 linux-amd64/helm \
 && fetch "https://github.com/yannh/kubeconform/releases/download/v${KUBECONFORM_VERSION}/kubeconform-linux-amd64.tar.gz" kubeconform.tgz "${KUBECONFORM_SHA256}" \
 && tar -xzf kubeconform.tgz kubeconform \
 && fetch "https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz" actionlint.tgz "${ACTIONLINT_SHA256}" \
 && tar -xzf actionlint.tgz actionlint \
 && fetch "https://github.com/hadolint/hadolint/releases/download/v${HADOLINT_VERSION}/hadolint-linux-x86_64" hadolint "${HADOLINT_SHA256}" \
 && fetch "https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" gitleaks.tgz "${GITLEAKS_SHA256}" \
 && tar -xzf gitleaks.tgz gitleaks \
 && install -m 0755 helm kubeconform actionlint hadolint gitleaks /usr/local/bin/ \
 && rm -rf /tmp/tools

COPY requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir -r /tmp/requirements.txt \
 && rm /tmp/requirements.txt

COPY VERSION /etc/eom-ci-tools-version
COPY versions.sh /usr/local/bin/ci-tools-versions

# Jobs run as root in act_runner job containers; keep the default user so
# actions/checkout can write the workspace.
WORKDIR /workspace
ENV ANSIBLE_FORCE_COLOR=1 PIP_DISABLE_PIP_VERSION_CHECK=1
CMD ["ci-tools-versions"]
