### Go get dependecies and build ###
FROM golang:1.27 AS builder
ENV PLATFORM=docker
WORKDIR /go/src/app
COPY go.mod go.sum ./

# Download dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download
COPY . .

RUN VERSION=$(git describe --always --tags) && \
    CGO_ENABLED=0 GOOS=linux go build \
    -mod=readonly \
    -ldflags "-s -w -X github.com/oasdiff/oasdiff/build.Version=${VERSION}"

### Create image ###
FROM alpine:3

RUN apk add --no-cache git
# oasdiff runs git for the rev:path syntax. A repo mounted from the host is
# owned by a different uid, which git refuses to read, so trust any repo.
RUN git config --system --add safe.directory '*'
WORKDIR /usr/bin
COPY --from=builder /go/src/app/oasdiff .

ENTRYPOINT ["/usr/bin/oasdiff"]
