Skip to content

Commit cc12dc0

Browse files
authored
Merge pull request #552 from crazy-max/addlicense-install
dockerfile: use go install for addlicense and update to v1.1.1
2 parents 54bdcf6 + 13bd9c8 commit cc12dc0

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

hack/dockerfiles/license.Dockerfile

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,44 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
ARG ADDLICENSE_VERSION="v1.1.1"
18+
ARG ALPINE_VERSION="3.21"
19+
ARG GO_VERSION="1.23"
20+
ARG XX_VERSION="1.6.1"
21+
1722
ARG LICENSE_HOLDER="actions-toolkit authors"
1823
ARG LICENSE_TYPE="apache"
1924
ARG LICENSE_FILES=".*\(Dockerfile\|Makefile\|\.js\|\.ts\|\.hcl\|\.sh|\.ps1\)"
20-
ARG ADDLICENSE_VERSION="v1.0.0"
2125

22-
FROM ghcr.io/google/addlicense:${ADDLICENSE_VERSION} AS addlicense
26+
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
2327

24-
FROM alpine:3.17 AS base
25-
WORKDIR /src
28+
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
2629
RUN apk add --no-cache cpio findutils git
30+
ENV CGO_ENABLED=0
31+
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
2748

2849
FROM base AS set
2950
ARG LICENSE_HOLDER
3051
ARG LICENSE_TYPE
3152
ARG LICENSE_FILES
3253
RUN --mount=type=bind,target=.,rw \
33-
--mount=from=addlicense,source=/app/addlicense,target=/usr/bin/addlicense \
54+
--mount=from=addlicense,source=/out/addlicense,target=/usr/bin/addlicense \
3455
find . -regex "${LICENSE_FILES}" -not -path "./.yarn/*" -not -path "./node_modules/*" | xargs addlicense -c "$LICENSE_HOLDER" -l "$LICENSE_TYPE" && \
3556
mkdir /out && \
3657
find . -regex "${LICENSE_FILES}" -not -path "./.yarn/*" -not -path "./node_modules/*" | cpio -pdm /out
@@ -43,5 +64,5 @@ ARG LICENSE_HOLDER
4364
ARG LICENSE_TYPE
4465
ARG LICENSE_FILES
4566
RUN --mount=type=bind,target=. \
46-
--mount=from=addlicense,source=/app/addlicense,target=/usr/bin/addlicense \
67+
--mount=from=addlicense,source=/out/addlicense,target=/usr/bin/addlicense \
4768
find . -regex "${LICENSE_FILES}" -not -path "./.yarn/*" -not -path "./node_modules/*" | xargs addlicense -check -c "$LICENSE_HOLDER" -l "$LICENSE_TYPE"

0 commit comments

Comments
 (0)