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+
1722ARG LICENSE_HOLDER="actions-toolkit authors"
1823ARG LICENSE_TYPE="apache"
1924ARG 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
2629RUN 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
2849FROM base AS set
2950ARG LICENSE_HOLDER
3051ARG LICENSE_TYPE
3152ARG LICENSE_FILES
3253RUN --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
4364ARG LICENSE_TYPE
4465ARG LICENSE_FILES
4566RUN --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