# Replay judge image: Rust + pinned Agave platform tools (cargo build-sbf), the replayer, the Node job runner.
# Built remotely: fly deploy --remote-only. One machine, stopped by default, started per job.

FROM rust:1-bookworm AS replayer
WORKDIR /src
COPY replayer/Cargo.toml replayer/Cargo.lock replayer/
COPY replayer/src replayer/src
RUN cd replayer && cargo build --release --locked && cp target/release/replayer /replayer

FROM debian:bookworm-slim
ARG AGAVE_VERSION=3.1.10
ARG RUST_VERSION=1.89.0
ARG NODE_VERSION=24.11.0
RUN apt-get update && apt-get install -y --no-install-recommends \
      ca-certificates curl bzip2 xz-utils tar unzip git build-essential pkg-config libssl-dev libudev-dev \
    && rm -rf /var/lib/apt/lists/*
ENV RUSTUP_HOME=/opt/rustup CARGO_HOME=/opt/cargo HOME=/root
ENV PATH=/opt/cargo/bin:/opt/solana/bin:/opt/node/bin:$PATH
RUN curl -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain ${RUST_VERSION} --no-modify-path
RUN curl -fsSL https://github.com/anza-xyz/agave/releases/download/v${AGAVE_VERSION}/solana-release-x86_64-unknown-linux-gnu.tar.bz2 \
      | tar -xj -C /opt && mv /opt/solana-release /opt/solana && cargo-build-sbf --version
RUN curl -fsSL https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz | tar -xJ -C /opt \
      && mv /opt/node-v${NODE_VERSION}-linux-x64 /opt/node && node --version
# First build installs the platform tools and warms the crates.io cache with the usual dependencies.
COPY calibration /opt/calibration
RUN cd /opt/calibration/memo-correct && cargo build-sbf -- --locked && ls target/deploy && rm -rf target
COPY --from=replayer /replayer /usr/local/bin/replayer
WORKDIR /app
COPY runner/package.json ./
RUN npm install --omit=dev --no-audit --no-fund
COPY runner/ ./
CMD ["node", "/app/runner.mjs"]
