@@ -17,14 +17,34 @@ RUN --mount=type=cache,target=/go/pkg/mod \
1717 --mount=type=bind,source=go.sum,target=go.sum \
1818 go mod download
1919
20+ FROM builder-base AS go-licenses
21+ ARG TARGETPLATFORM
22+ RUN --mount=target=/root/.cache,type=cache \
23+ --mount=type=cache,target=/go/pkg/mod <<EOT
24+ set -ex
25+ xx-go install github.com/google/go-licenses@latest
26+ mkdir /out
27+ if ! xx-info is-cross; then
28+ mv /go/bin/go-licenses /out
29+ else
30+ mv /go/bin/*/go-licenses* /out
31+ fi
32+ EOT
33+
34+ FROM builder-base AS licenses-validate
35+ RUN --mount=type=bind,target=. \
36+ --mount=type=cache,target=/go/pkg/mod \
37+ --mount=from=go-licenses,source=/out/go-licenses,target=/usr/bin/go-licenses \
38+ go-licenses check . --allowed_licenses=Apache-2.0,MIT,BSD-3-Clause,BSD-2-Clause --ignore modernc.org/mathutil
39+
2040FROM builder-base AS lint
2141RUN apk add --no-cache gcc musl-dev
2242WORKDIR /
2343ARG GOLANGCI_LINT_VERSION
2444RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s ${GOLANGCI_LINT_VERSION}
2545WORKDIR /src
2646ARG TARGETPLATFORM
27- RUN --mount=target=/src \
47+ RUN --mount=type=bind, target=. \
2848 --mount=type=cache,target=/go/pkg/mod \
2949 --mount=target=/root/.cache,type=cache,id=lint-$TARGETPLATFORM \
3050 xx-go --wrap && \
@@ -43,7 +63,7 @@ FROM scratch AS test-coverage
4363COPY --from=test /tmp/coverage.txt /coverage.txt
4464
4565FROM builder-base AS version
46- RUN --mount=target=. <<'EOT'
66+ RUN --mount=type=bind, target=. <<'EOT'
4767 git rev-parse HEAD 2>/dev/null || {
4868 echo >&2 "Failed to get git revision, make sure --build-arg BUILDKIT_CONTEXT_KEEP_GIT_DIR=1 is set when building from Git directly"
4969 exit 1
@@ -55,18 +75,18 @@ RUN --mount=target=. <<'EOT'
5575EOT
5676
5777FROM builder-base AS builder
58- COPY . ./
5978ARG TARGETPLATFORM
6079ARG TARGETOS
61- RUN --mount=type=cache,target=/root/.cache,id=docker-ai-$TARGETPLATFORM \
80+ RUN --mount=type=bind,target=. \
81+ --mount=type=cache,target=/root/.cache,id=docker-ai-$TARGETPLATFORM \
6282 --mount=source=/tmp/.ldflags,target=/tmp/.ldflags,from=version \
6383 --mount=type=cache,target=/go/pkg/mod <<EOT
64- set -ex
65- xx-go build -trimpath -ldflags "-s -w $(cat /tmp/.ldflags)" -o /binaries/cagent .
66- xx-verify --static /binaries/cagent
67- if [ "$TARGETOS" = "windows" ]; then
68- mv /binaries/cagent /binaries/cagent.exe
69- fi
84+ set -ex
85+ xx-go build -trimpath -ldflags "-s -w $(cat /tmp/.ldflags)" -o /binaries/cagent .
86+ xx-verify --static /binaries/cagent
87+ if [ "$TARGETOS" = "windows" ]; then
88+ mv /binaries/cagent /binaries/cagent.exe
89+ fi
7090EOT
7191
7292FROM scratch AS binaries
0 commit comments