1515# limitations under the License.
1616
1717ARG GO_VERSION="1.23"
18+ ARG XX_VERSION="1.6.1"
1819ARG GOLANGCI_LINT_VERSION="v1.62"
19- ARG ADDLICENSE_VERSION="v1.0.0 "
20+ ARG ADDLICENSE_VERSION="v1.1.1 "
2021
2122ARG LICENSE_ARGS="-c cli-docs-tool -l apache"
2223ARG LICENSE_FILES=".*\( Dockerfile\|\. go\|\. hcl\|\. sh\) "
2324
2425FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint
25- FROM ghcr.io/google/addlicense :${ADDLICENSE_VERSION } AS addlicense
26+ FROM --platform=$BUILDPLATFORM tonistiigi/xx :${XX_VERSION } AS xx
2627
27- FROM golang:${GO_VERSION}-alpine AS base
28+ FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS base
2829RUN apk add --no-cache cpio findutils git linux-headers
2930ENV CGO_ENABLED=0
3031WORKDIR /src
32+ COPY --link --from=xx / /
33+
34+ FROM base AS addlicense
35+ ARG ADDLICENSE_VERSION
36+ ARG TARGETPLATFORM
37+ RUN --mount=target=/root/.cache,type=cache \
38+ --mount=type=cache,target=/go/pkg/mod <<EOT
39+ set -ex
40+ xx-go install "github.com/google/addlicense@${ADDLICENSE_VERSION}"
41+ mkdir /out
42+ if ! xx-info is-cross; then
43+ mv /go/bin/addlicense /out
44+ else
45+ mv /go/bin/*/addlicense* /out
46+ fi
47+ EOT
3148
3249FROM base AS vendored
3350RUN --mount=type=bind,target=.,rw \
@@ -40,15 +57,15 @@ COPY --from=vendored /out /
4057
4158FROM vendored AS vendor-validate
4259RUN --mount=type=bind,target=.,rw <<EOT
43- set -e
44- git add -A
45- cp -rf /out/* .
46- diff=$(git status --porcelain -- go.mod go.sum)
47- if [ -n "$diff" ]; then
48- echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor"'
49- echo "$diff"
50- exit 1
51- fi
60+ set -e
61+ git add -A
62+ cp -rf /out/* .
63+ diff=$(git status --porcelain -- go.mod go.sum)
64+ if [ -n "$diff" ]; then
65+ echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor"'
66+ echo "$diff"
67+ exit 1
68+ fi
5269EOT
5370
5471FROM base AS lint
@@ -61,7 +78,7 @@ FROM base AS license-set
6178ARG LICENSE_ARGS
6279ARG LICENSE_FILES
6380RUN --mount=type=bind,target=.,rw \
64- --mount=from=addlicense,source=/app /addlicense,target=/usr/bin/addlicense \
81+ --mount=from=addlicense,source=/out /addlicense,target=/usr/bin/addlicense \
6582 find . -regex "${LICENSE_FILES}" | xargs addlicense ${LICENSE_ARGS} \
6683 && mkdir /out \
6784 && find . -regex "${LICENSE_FILES}" | cpio -pdm /out
@@ -73,7 +90,7 @@ FROM base AS license-validate
7390ARG LICENSE_ARGS
7491ARG LICENSE_FILES
7592RUN --mount=type=bind,target=. \
76- --mount=from=addlicense,source=/app /addlicense,target=/usr/bin/addlicense \
93+ --mount=from=addlicense,source=/out /addlicense,target=/usr/bin/addlicense \
7794 find . -regex "${LICENSE_FILES}" | xargs addlicense -check ${LICENSE_ARGS}
7895
7996FROM vendored AS test
0 commit comments