FROM rust:1.81-alpine AS builder

RUN apk add --no-cache musl-dev sqlite-dev build-base bash perl protobuf

WORKDIR /build
COPY . .

# Build the relay
RUN cargo build --release

FROM alpine:latest
RUN apk --no-cache add ca-certificates sqlite wget
WORKDIR /app
COPY --from=builder /build/target/release/nostr-rs-relay /app/
RUN mkdir -p /data

EXPOSE 8080
ENV RUST_LOG=info

HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
  CMD wget --quiet --tries=1 --spider http://localhost:8080 || exit 1

CMD ["/app/nostr-rs-relay"]
