ARG GO_VERSION=1.25
FROM golang:${GO_VERSION}-alpine

ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64

RUN apk add --no-cache git && \
    adduser -D -s /bin/sh builder

WORKDIR /build

USER builder

COPY go.mod go.sum ./
RUN go mod download

COPY cmd/ cmd/
COPY internal/ internal/
COPY pkg/ pkg/

ARG BINARY_NAME=reticulum-go
ARG BUILD_PATH=./cmd/reticulum-go

RUN mkdir -p /dist && \
    go build \
    -ldflags='-w -s -extldflags "-static"' \
    -a -installsuffix cgo \
    -o /dist/${BINARY_NAME} \
    ${BUILD_PATH}