FROM golang:1.24.1-alpine AS build

RUN apk add --no-cache gcc musl-dev sqlite-dev

WORKDIR /app

ENV GOFLAGS=-mod=mod

COPY go.mod ./
# go.sum may be generated later
RUN go mod download

COPY . .

RUN go mod tidy

RUN CGO_ENABLED=1 go build -o /bin/ipfstr ./cmd/ipfstr

FROM alpine:3.20

RUN apk add --no-cache ca-certificates sqlite-libs

WORKDIR /app

COPY --from=build /bin/ipfstr /app/ipfstr
COPY --from=build /app/public /app/public

ENV PORT=3334
EXPOSE 3334

CMD ["/app/ipfstr"]
