# XDC Full Node Dockerfile
# Maintains complete blockchain state - recommended for validators/masternodes
# Expected disk usage: 500GB+

FROM golang:1.24-alpine AS builder

RUN apk add --no-cache make gcc musl-dev linux-headers git bash

WORKDIR /build
COPY . /build

RUN make geth && chmod +x /build/build/bin/geth && ln -s /build/build/bin/geth /build/build/bin/XDC

# Runtime stage
FROM alpine:3.19

LABEL maintainer="anil@xinfin.org"
LABEL description="XDC Full Node - Complete blockchain state"
LABEL version="1.0.0"

RUN apk add --no-cache ca-certificates bash curl jq

WORKDIR /xdc

# Copy binary
COPY --from=builder /build/build/bin/geth /usr/local/bin/geth
RUN ln -s /usr/local/bin/geth /usr/local/bin/XDC

# Copy genesis files and entrypoint
COPY docker/XDPoSChain/entrypoint.sh ./entrypoint.sh
COPY genesis/ ./genesis/

RUN chmod +x /usr/local/bin/geth ./entrypoint.sh

# Environment defaults for full node
ENV IDENTITY=''
ENV PASSWORD=''
ENV PRIVATE_KEY=''
ENV BOOTNODES=''
ENV EXTIP=''
ENV VERBOSITY=3
ENV MAXPEERS=50
ENV SYNC_MODE='full'
ENV NETWORK_ID='50'
ENV WS_SECRET=''
ENV NETSTATS_HOST='netstats-server'
ENV NETSTATS_PORT='3000'
ENV GCMODE='archive'
ENV NODE_TYPE='full'

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
  CMD curl -sf http://localhost:8545 -X POST -H "Content-Type: application/json" \
      -d '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' || exit 1

EXPOSE 8545 8546 30303 30303/udp

VOLUME ["/xdc/data"]

ENTRYPOINT ["./entrypoint.sh"]
