# dockerfiles/Dockerfile.monerod
# syntax=docker/dockerfile:1.6
FROM debian:bookworm-slim

ARG MONERO_VERSION=v0.18.4.1
ARG TARGETARCH
ARG MONERO_SHA256=""

RUN set -eux; \
    apt-get update; \
    apt-get install -y --no-install-recommends ca-certificates curl bzip2 xz-utils; \
    update-ca-certificates; \
    case "${TARGETARCH:-arm64}" in \
      amd64)  F="monero-linux-x64" ;; \
      arm64)  F="monero-linux-armv8" ;; \
      arm)    F="monero-linux-armv7" ;; \
      *) echo "Unsupported TARGETARCH=${TARGETARCH}"; exit 1 ;; \
    esac; \
    URL="https://downloads.getmonero.org/cli/${F}-${MONERO_VERSION}.tar.bz2"; \
    echo "Downloading $URL"; \
    curl -fL "$URL" -o /tmp/monero.tar.bz2; \
    if [ -n "$MONERO_SHA256" ]; then echo "${MONERO_SHA256}  /tmp/monero.tar.bz2" | sha256sum -c -; fi; \
    mkdir -p /opt/monero; \
    tar -xjf /tmp/monero.tar.bz2 -C /opt/monero --strip-components=1; \
    rm -f /tmp/monero.tar.bz2; \
    groupadd --system monero; \
    useradd --system --uid 1000 --gid monero --home-dir /nonexistent --shell /usr/sbin/nologin monero; \
    mkdir -p /data; \
    chown monero:monero /data; \
    chmod 0770 /data

ENV LD_LIBRARY_PATH=/opt/monero:/opt/monero/lib \
    PATH="/opt/monero:${PATH}"

USER monero
CMD ["/opt/monero/monerod", "--version"]
