latest
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is failing

This commit is contained in:
2022-12-06 02:59:08 +04:00
parent a9f23c79d2
commit ec3e7c23eb
20 changed files with 327 additions and 170 deletions

View File

@@ -1,47 +1,53 @@
FROM golang:1.19.3-bullseye AS cacher
################################################################################
#2345678911234567892123456789312345678941234567895123456789612345678971234567898
################################################################################
FROM golang:1.19.3-bullseye AS builder
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
apt update && \
apt install -y make zstd unzip && \
mkdir /build
WORKDIR /tmp
# 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
COPY ./builddeps/* ./
RUN unzip protoc-*-linux-$(uname -m).zip -d /usr/local && \
protoc --version && \
mkdir -p /go/pkg/mod && \
cd /go/pkg/mod && \
tar xvf /tmp/modcache.tar && \
cd / && \
go install -v google.golang.org/protobuf/cmd/protoc-gen-go@v1.28.1 && \
go install -v mvdan.cc/gofumpt@latest && \
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1 && \
rm -rf /tmp/*
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
COPY ./go.mod ./go.sum .
RUN \
go mod download -x
################################################################################
#### caching phase done
################################################################################
WORKDIR /build
RUN golangci-lint run
COPY ./Makefile ./.golangci.yml ./go.mod ./go.sum .
COPY ./internal ./internal
COPY ./bin/gitrev.sh ./bin/gitrev.sh
COPY ./mfer ./mfer
COPY ./cmd ./cmd
RUN find /build
ARG GITREV unknown
RUN \
cd mfer && go generate . && cd .. && \
GOPACKAGESDEBUG=true golangci-lint run ./... && \
make mfer.cmd
RUN go mod vendor && tar -c . | zstdmt -19 > /src.tzst
################################################################################
#2345678911234567892123456789312345678941234567895123456789612345678971234567898
################################################################################
## final image
################################################################################
FROM scratch
# we put all the source into the final image for posterity, it's small
COPY --from=builder /src.tzst /src.tzst
COPY --from=builder /build/mfer.cmd /mfer
ENTRYPOINT ["/mfer"]