#
# A simple example of how to build a docker container for n3n-edge
#
# Build with the command:
# podman build \
#   --device=/dev/net/tun \
#   --cap-add=NET_ADMIN \
#   -t=n3n \
#   -f docs/Containerfile.example \
#   .
#
# Note that podman must be run in rootful mode for the build tests to pass.
# To build in rootless mode:
# podman build \
#   --build-arg SKIP_TESTS=1 \
#   -t=n3n \
#   -f docs/Containerfile.example \
#   .
#
# Start a n3n session with:
# podman run \
#   --rm \
#   -it \
#   --name=n3n \
#   --device=/dev/net/tun \
#   --cap-add=NET_ADMIN \
#   -v "$PWD"/n3n:/etc/n3n/ \
#   n3n start -vvvv
#
# Start an n3n supernode with the following, where 1234 is the port
# configured in your supernode config file:
# podman run
#   --rm \
#   -it \
#   --name=n3n-supernode \
#   -p1234:1234/udp \
#   --device=/dev/net/tun \
#   --cap-add=NET_ADMIN \
#   -v "$PWD"/n3n:/etc/n3n/ \
#   --entrypoint=/n3n-supernode \
#   n3n start -vvvv

FROM docker.io/library/debian:12 AS builder

RUN apt-get update
RUN apt-get install -y build-essential autoconf git python3 jq sudo

WORKDIR /n3n

COPY . .

RUN \
    ./autogen.sh && \
    ./configure && \
    make clean all

ARG SKIP_TESTS=0

RUN if [ 0 -eq "$SKIP_TESTS" ]; then make test; fi


FROM docker.io/library/debian:12

COPY --from=builder /n3n/apps/n3n-edge /n3n-edge
COPY --from=builder /n3n/apps/n3n-supernode /n3n-supernode

VOLUME [ "/etc/n3n" ]
ENTRYPOINT ["/n3n-edge"]
CMD ["start"]
