Files
nilsandClaude Sonnet 5.5 0cfb59c469 Orderly shutdown on SIGHUP too, forced exit when stuck; version in the image
SIGINT, SIGTERM and SIGHUP all shut the node down in order (SIGTERM is what a
Kubernetes pod termination sends). A second signal, or 20 seconds (below the
30 s Kubernetes grants), stops the process at once, so a stuck shutdown cannot
hang.

The binary knows its version (allmende version, and the 'node running' log
line); the image is built with the commit as version and 'make image' pushes it
tagged with that commit, refusing a dirty tree.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
2026-11-18 13:08:14 +01:00

45 lines
2.1 KiB
Docker

# Allmende node. The web UI is already built and embedded (web/dist is
# committed), so only Go is needed here.
#
# docker build -t allmende .
# docker run --rm -it -v allmende-data:/data allmende init # once; shows the recovery phrase
# docker run -d --name allmende -v allmende-data:/data \
# -p 127.0.0.1:8080:8080 -p 4001:4001 -p 4001:4001/udp allmende # run
# docker logs allmende # the owner sign-in link; open it and choose your regions
#
# The node starts without a region: the owner picks one by place name in the
# browser ("My listings" > "Regions") and it applies at once. The choice is kept
# in the volume (/data/regions.json) and wins over --region from then on.
#
# The HTTP port also serves the owner API, which the admin token protects, so
# publish it on 127.0.0.1 only and put a TLS proxy in front for public use.
# Port 4001 (TCP and UDP/QUIC) is the libp2p port other nodes connect to.
# The node remembers its peers in /data/peers.json, so keep the volume.
ARG GO_VERSION=1.27
FROM golang:${GO_VERSION}-alpine AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
ARG VERSION=dev
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w -X main.version=${VERSION}" -o /out/allmende ./cmd/allmende
FROM alpine:3.22
RUN adduser -D -u 10001 allmende && mkdir /data && chown allmende /data
COPY --from=build /out/allmende /usr/local/bin/allmende
USER allmende
ENV ALLMENDE_DATA=/data
VOLUME /data
EXPOSE 8080 4001/tcp 4001/udp
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s \
CMD wget -qO- http://127.0.0.1:8080/api/v1/status >/dev/null || exit 1
ENTRYPOINT ["allmende"]
# Override the whole command to start with regions or add peers, e.g.
# docker run ... allmende run --http 0.0.0.0:8080 \
# --listen /ip4/0.0.0.0/tcp/4001 --listen /ip4/0.0.0.0/udp/4001/quic-v1 \
# --region u1j --region u1h --bootstrap /ip4/203.0.113.5/tcp/4001/p2p/<peer id>
# A bootstrap node adds --public (and needs a public address).
CMD ["run", "--http", "0.0.0.0:8080", "--listen", "/ip4/0.0.0.0/tcp/4001", "--listen", "/ip4/0.0.0.0/udp/4001/quic-v1"]