FROM golang:1.21-bullseye AS builder
# Build using Go modules to modernize and simplify dependency handling
ENV GOPATH=/go
ENV GO111MODULE=on
ENV CGO_ENABLED=0
WORKDIR /go/src/github.com/gocircuit/circuit
# Copy source code
COPY . .
# Initialize a module if none exists and tidy dependencies
RUN if [ ! -f go.mod ]; then echo "module github.com/gocircuit/circuit" > go.mod; fi
RUN go mod tidy
# Build the project using the provided Makefile nix target
RUN make nix
FROM debian:bullseye-slim
RUN apt-get update -qq && apt-get install -y --no-install-recommends ca-certificates
# Copy the built binary from builder stage
COPY --from=builder /go/bin/circuit /usr/local/bin/circuit
RUN chmod +x /usr/local/bin/circuit
CMD ["circuit","start","-if","eth0"]