From 2fa4104829e3b93db474075e64084e68922f93a3 Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Mon, 19 Aug 2024 13:43:57 -0700 Subject: [PATCH] add dockerfile --- Dockerfile | 35 +++++++++++++++++++++++++++++++++++ cmd/clusterd/main.go | 10 +++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..731c94c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +FROM docker.io/library/golang:1.23 AS builder + +WORKDIR /app + +# get dependencies +COPY go.mod go.sum ./ +RUN go mod download + +# copy source +COPY . . +# codegen +RUN go generate ./... +# build +RUN CGO_ENABLED=1 go build -o bin/ -tags='netgo timetzdata' -trimpath -a -ldflags '-s -w -linkmode external -extldflags "-static"' ./cmd/clusterd + +FROM debian:bookworm-slim + +LABEL maintainer="The Sia Foundation " \ + org.opencontainers.image.description.vendor="The Sia Foundation" \ + org.opencontainers.image.description="A cluster container for testing a local Sia network" \ + org.opencontainers.image.source="https://github.com/SiaFoundation/hostd" \ + org.opencontainers.image.licenses=MIT + +ENV PUID=0 +ENV PGID=0 + +# copy binary and prepare data dir. +COPY --from=builder /app/bin/* /usr/bin/ +VOLUME [ "/data" ] + +EXPOSE 3000 + +USER ${PUID}:${PGID} + +ENTRYPOINT [ "clusterd" ] \ No newline at end of file diff --git a/cmd/clusterd/main.go b/cmd/clusterd/main.go index f469502..1f9da60 100644 --- a/cmd/clusterd/main.go +++ b/cmd/clusterd/main.go @@ -44,9 +44,9 @@ func main() { flag.StringVar(&network, "network", "v1", "network to use (v1 or v2)") flag.StringVar(&siafundAddr, "siafund", "", "address to send siafunds to") - flag.IntVar(&renterdCount, "renterd", 1, "number of renter daemons to run") - flag.IntVar(&hostdCount, "hostd", 1, "number of host daemons to run") - flag.IntVar(&walletdCount, "walletd", 1, "number of wallet daemons to run") + flag.IntVar(&renterdCount, "renterd", 0, "number of renter daemons to run") + flag.IntVar(&hostdCount, "hostd", 0, "number of host daemons to run") + flag.IntVar(&walletdCount, "walletd", 0, "number of wallet daemons to run") flag.Parse() cfg := zap.NewProductionEncoderConfig() @@ -79,6 +79,10 @@ func main() { zap.RedirectStdLog(log) + if hostdCount == 0 && renterdCount == 0 && walletdCount == 0 { + log.Panic("no nodes to run") + } + ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) defer cancel()