# protoc with the protobuf-es plugin (protoc-gen-es), for generate.sh. Versions are pinned; the protoc
# download is checked against its SHA-256 from the protobuf release.
FROM node:24.22.3-bookworm-slim

ARG PROTOC_VERSION=36.2
ARG PROTOC_SHA256_X86_64=121f6c7afe1d4d0e3ea6aab9432038599250134cbf4474cb1167d2c7decd4278
ARG PROTOC_SHA256_AARCH_64=8b8f18bd2b30346efbc698dd5a73dd7c805f3ef8380f6dfc95c768f3f1852f6a
# Keep it the same as @bufbuild/protobuf in package.json: the generated code needs that runtime version.
ARG PROTOC_GEN_ES_VERSION=2.17.0

RUN apt-get update \
 && apt-get install -y --no-install-recommends ca-certificates curl unzip \
 && rm -rf /var/lib/apt/lists/*

RUN set -eu; \
    case "$(uname -m)" in \
      x86_64)  arch=x86_64;   sum=$PROTOC_SHA256_X86_64 ;; \
      aarch64) arch=aarch_64; sum=$PROTOC_SHA256_AARCH_64 ;; \
      *) echo "no protoc build for $(uname -m)" >&2; exit 1 ;; \
    esac; \
    curl -fsSL -o /tmp/protoc.zip \
      "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-${arch}.zip"; \
    echo "${sum}  /tmp/protoc.zip" | sha256sum -c -; \
    unzip -q /tmp/protoc.zip -d /usr/local bin/protoc 'include/*'; \
    rm /tmp/protoc.zip; \
    protoc --version

RUN npm install -g "@bufbuild/protoc-gen-es@${PROTOC_GEN_ES_VERSION}" && npm cache clean --force

WORKDIR /work
ENTRYPOINT ["protoc"]
