# builder
FROM golang:1.21.3-alpine3.18 AS builder
RUN apk update && apk add gcc musl-dev
ARG VERSION=notset-dockerfile
WORKDIR /usr/src/app
COPY go.mod go.sum ./
RUN go mod download && go mod verify
COPY cmd/ ./cmd
COPY internal/ ./internal
RUN --mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=1 GOOS=linux go build -ldflags=-X=main.version=${VERSION} -v -o /felu ./cmd/felu/main.go
# tester
FROM builder AS tester
RUN --mount=type=cache,target=/root/.cache/go-build go test -v ./...
# release
FROM alpine:3.18 AS release
COPY --from=builder /felu /felu
ADD ./static /static
RUN mkdir /var/felu
ENTRYPOINT ["/felu"]