FROM golang:1.22-alpine AS builder

ARG TELEBIT_REF=master

RUN apk add --no-cache git

WORKDIR /src
RUN git clone --depth 1 --branch "${TELEBIT_REF}" https://github.com/therootcompany/telebit.git .

RUN go generate -mod=vendor ./...
RUN CGO_ENABLED=0 go build -mod=vendor -ldflags="-s -w" -o /out/telebit-relay ./cmd/telebit
RUN CGO_ENABLED=0 go build -mod=vendor -ldflags="-s -w" -o /out/telebit-mgmt ./cmd/mgmt

FROM alpine:3.20

RUN apk add --no-cache ca-certificates

COPY --from=builder /out/telebit-relay /usr/local/bin/telebit-relay
COPY --from=builder /out/telebit-mgmt /usr/local/bin/telebit-mgmt

WORKDIR /var/lib/telebit
