FROM golang:1.25-alpine AS build

ARG LOCALSEND_CLI_REF=54702513990eeb763e1615f274d5365442e3e393

RUN apk add --no-cache git patch
WORKDIR /src
RUN git clone https://github.com/0w0mewo/localsend-cli.git . \
    && git checkout "$LOCALSEND_CLI_REF"
COPY patches/localsend-cli-doris.patch /tmp/localsend-cli-doris.patch
RUN git apply /tmp/localsend-cli-doris.patch \
    && CGO_ENABLED=0 go build -trimpath -ldflags='-s -w' -o /out/localsend .

FROM alpine:3.22
RUN apk add --no-cache ca-certificates tzdata \
    && adduser -D -u 1000 doris
WORKDIR /app
COPY --from=build /out/localsend /usr/local/bin/localsend
USER doris
ENTRYPOINT ["/usr/local/bin/localsend"]
