| 1 |
# syntax=docker/dockerfile:1 |
| 2 |
|
| 3 |
ARG GO_VERSION=1.23 |
| 4 |
ARG XX_VERSION=1.6.1 |
| 5 |
ARG GOLANGCI_LINT_VERSION=1.61.0 |
| 6 |
ARG GOPLS_VERSION=v0.26.0 |
| 7 |
# GOPLS_ANALYZERS defines gopls analyzers to be run. disabled by default: deprecated unusedvariable simplifyrange |
| 8 |
ARG GOPLS_ANALYZERS="embeddirective fillreturns infertypeargs nonewvars norangeoverfunc noresultvalues simplifycompositelit simplifyslice undeclaredname unusedparams useany" |
| 9 |
|
| 10 |
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx |
| 11 |
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS golang-base |
| 12 |
RUN apk add --no-cache git gcc musl-dev |
| 13 |
ENV GOFLAGS="-buildvcs=false" |
| 14 |
ARG GOLANGCI_LINT_VERSION |
| 15 |
RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v${GOLANGCI_LINT_VERSION} |
| 16 |
COPY --link --from=xx / / |
| 17 |
WORKDIR /go/src/github.com/tonistiigi/fsutil |
| 18 |
|
| 19 |
FROM golang-base AS gopls |
| 20 |
ARG GOPLS_VERSION |
| 21 |
WORKDIR /src |
| 22 |
RUN git clone https://github.com/golang/tools.git && \ |
| 23 |
cd tools && git checkout ${GOPLS_VERSION} |
| 24 |
WORKDIR tools/gopls |
| 25 |
ARG GOPLS_ANALYZERS |
| 26 |
RUN <<'EOF' |
| 27 |
set -ex |
| 28 |
mkdir -p /out |
| 29 |
for analyzer in ${GOPLS_ANALYZERS}; do |
| 30 |
mkdir -p internal/cmd/$analyzer |
| 31 |
cat <<eot > internal/cmd/$analyzer/main.go |
| 32 |
package main |
| 33 |
|
| 34 |
import ( |
| 35 |
"golang.org/x/tools/go/analysis/singlechecker" |
| 36 |
analyzer "golang.org/x/tools/gopls/internal/analysis/$analyzer" |
| 37 |
) |
| 38 |
|
| 39 |
func main() { singlechecker.Main(analyzer.Analyzer) } |
| 40 |
eot |
| 41 |
echo "Analyzing with ${analyzer}..." |
| 42 |
go build -o /out/$analyzer ./internal/cmd/$analyzer |
| 43 |
done |
| 44 |
EOF |
| 45 |
|
| 46 |
FROM golang-base AS gopls-analyze |
| 47 |
COPY --link --from=xx / / |
| 48 |
ARG GOPLS_ANALYZERS |
| 49 |
ARG TARGETNAME |
| 50 |
ARG TARGETPLATFORM |
| 51 |
RUN --mount=target=. \ |
| 52 |
--mount=target=/root/.cache,type=cache,id=lint-cache-${TARGETNAME}-${TARGETPLATFORM} \ |
| 53 |
--mount=target=/gopls-analyzers,from=gopls,source=/out <<EOF |
| 54 |
set -ex |
| 55 |
xx-go --wrap |
| 56 |
for analyzer in ${GOPLS_ANALYZERS}; do |
| 57 |
go vet -vettool=/gopls-analyzers/$analyzer ./... |
| 58 |
done |
| 59 |
EOF |
| 60 |
|
| 61 |
|
| 62 |
FROM golang-base AS lint |
| 63 |
ARG TARGETPLATFORM |
| 64 |
RUN --mount=target=. \ |
| 65 |
--mount=target=/root/.cache,type=cache,id=lint-cache-$TARGETPLATFORM \ |
| 66 |
--mount=target=/go/pkg/mod,type=cache \ |
| 67 |
xx-go --wrap && \ |
| 68 |
golangci-lint run |