FROM golang:1.19.3-bullseye AS cacher ENV GOPATH /go ENV DEBIAN_FRONTEND noninteractive RUN --mount=type=cache,target=/var/cache/apt \ apt update && apt install -y make zstd curl unzip RUN mkdir -p /build WORKDIR /build # install newer protoc RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v21.10/protoc-21.10-linux-aarch_64.zip && \ unzip *.zip -d /usr/local && rm -v *.zip && protoc --version RUN go install -v google.golang.org/protobuf/cmd/protoc-gen-go@v1.28.1 COPY ./go.mod . COPY ./go.sum . RUN --mount=type=cache,target=/go/pkg go mod download -x RUN go env ## build image FROM golang:1.19.3-bullseye AS builder COPY --from=cacher /usr/local /usr/local COPY --from=cacher /usr/bin /usr/bin COPY --from=cacher /go/bin /go/bin COPY --from=cacher /build /build WORKDIR /build COPY ./ ./ RUN --mount=type=cache,target=/go/pkg go mod download -x && go mod tidy && cd mfer && go generate . RUN --mount=type=cache,target=/go/pkg make mfer.cmd && go mod vendor RUN tar -c . | zstdmt -19 > /src.tzst ## lint image FROM golangci/golangci-lint:v1.50.1 AS linter COPY --from=cacher /build /build WORKDIR /build RUN golangci-lint run FROM scratch COPY --from=builder /src.tzst /src.tzst COPY --from=builder /build/mfer.cmd /mfer ENTRYPOINT ["/mfer"]