Skip to content

Commit b6c6689

Browse files
authored
Merge pull request #64 from crazy-max/add-license-go-install
dockerfile: use go install for addlicense and update to v1.1.1
2 parents 69dd493 + 44c80f1 commit b6c6689

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

Dockerfile

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,36 @@
1515
# limitations under the License.
1616

1717
ARG GO_VERSION="1.23"
18+
ARG XX_VERSION="1.6.1"
1819
ARG GOLANGCI_LINT_VERSION="v1.62"
19-
ARG ADDLICENSE_VERSION="v1.0.0"
20+
ARG ADDLICENSE_VERSION="v1.1.1"
2021

2122
ARG LICENSE_ARGS="-c cli-docs-tool -l apache"
2223
ARG LICENSE_FILES=".*\(Dockerfile\|\.go\|\.hcl\|\.sh\)"
2324

2425
FROM 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
2829
RUN apk add --no-cache cpio findutils git linux-headers
2930
ENV CGO_ENABLED=0
3031
WORKDIR /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

3249
FROM base AS vendored
3350
RUN --mount=type=bind,target=.,rw \
@@ -40,15 +57,15 @@ COPY --from=vendored /out /
4057

4158
FROM vendored AS vendor-validate
4259
RUN --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
5269
EOT
5370

5471
FROM base AS lint
@@ -61,7 +78,7 @@ FROM base AS license-set
6178
ARG LICENSE_ARGS
6279
ARG LICENSE_FILES
6380
RUN --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
7390
ARG LICENSE_ARGS
7491
ARG LICENSE_FILES
7592
RUN --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

7996
FROM vendored AS test

0 commit comments

Comments
 (0)