|
1 | 1 | # syntax=docker/dockerfile:1 |
2 | 2 |
|
3 | 3 | # xx is a helper for cross-compilation |
4 | | -FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.6.1 AS xx |
| 4 | +FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.7.0 AS xx |
5 | 5 |
|
6 | | -FROM golang:1.25.0-alpine@sha256:f18a072054848d87a8077455f0ac8a25886f2397f88bfdd222d6fafbb5bba440 AS build-agent |
7 | | -RUN apk add --no-cache build-base |
8 | | -WORKDIR /app |
9 | | -COPY . ./ |
10 | | -ARG GIT_TAG GIT_COMMIT BUILD_DATE |
11 | | -RUN --mount=type=cache,target=/root/.cache \ |
12 | | - --mount=type=cache,target=/go/pkg/mod \ |
13 | | - --mount=type=secret,id=telemetry_api_key \ |
14 | | - --mount=type=secret,id=telemetry_endpoint \ |
15 | | - --mount=type=secret,id=telemetry_header \ |
16 | | - sh -c 'TELEMETRY_API_KEY=$(cat /run/secrets/telemetry_api_key 2>/dev/null || echo "") && TELEMETRY_ENDPOINT=$(cat /run/secrets/telemetry_endpoint 2>/dev/null || echo "") && TELEMETRY_HEADER=$(cat /run/secrets/telemetry_header 2>/dev/null || echo "") && go build -trimpath -ldflags "-s -w -X '"'"'github.com/docker/cagent/cmd/root.Version=$GIT_TAG'"'"' -X '"'"'github.com/docker/cagent/cmd/root.Commit=$GIT_COMMIT'"'"' -X '"'"'github.com/docker/cagent/cmd/root.BuildTime=$BUILD_DATE'"'"' -X '"'"'github.com/docker/cagent/internal/telemetry.TelemetryEndpoint=$TELEMETRY_ENDPOINT'"'"' -X '"'"'github.com/docker/cagent/internal/telemetry.TelemetryAPIKey=$TELEMETRY_API_KEY'"'"' -X '"'"'github.com/docker/cagent/internal/telemetry.TelemetryHeader=$TELEMETRY_HEADER'"'"'" -o /agent .' |
17 | | - |
18 | | -FROM --platform=$BUILDPLATFORM golang:1.25.0-alpine3.22 AS builder-base |
19 | | -RUN apk add clang |
20 | | -WORKDIR /src |
| 6 | +FROM --platform=$BUILDPLATFORM golang:1.25.0-alpine3.22 AS base |
| 7 | +RUN apk add clang file |
21 | 8 | COPY --from=xx / / |
22 | 9 | ENV CGO_ENABLED=0 |
23 | | -ARG TARGETPLATFORM TARGETOS TARGETARCH |
24 | | -ARG GIT_TAG GIT_COMMIT BUILD_DATE |
| 10 | +WORKDIR /src |
| 11 | + |
| 12 | +FROM base AS builder-base |
| 13 | +RUN --mount=type=cache,target=/go/pkg/mod \ |
| 14 | + --mount=type=bind,source=go.mod,target=go.mod \ |
| 15 | + --mount=type=bind,source=go.sum,target=go.sum \ |
| 16 | + go mod download |
25 | 17 |
|
26 | 18 | FROM builder-base AS builder |
27 | 19 | COPY . ./ |
| 20 | +ARG GIT_TAG |
| 21 | +ARG GIT_COMMIT |
| 22 | +ARG BUILD_DATE |
| 23 | +ARG TARGETPLATFORM |
| 24 | +ARG TARGETOS |
| 25 | +ARG TARGETARCH |
28 | 26 | RUN --mount=type=cache,target=/root/.cache,id=docker-ai-$TARGETPLATFORM \ |
29 | 27 | --mount=type=cache,target=/go/pkg/mod \ |
30 | | - --mount=type=secret,id=telemetry_api_key \ |
31 | | - --mount=type=secret,id=telemetry_endpoint \ |
32 | | - --mount=type=secret,id=telemetry_header <<EOT |
33 | | - set -x |
34 | | - TELEMETRY_API_KEY=$(cat /run/secrets/telemetry_api_key 2>/dev/null || echo "") |
35 | | - TELEMETRY_ENDPOINT=$(cat /run/secrets/telemetry_endpoint 2>/dev/null || echo "") |
36 | | - TELEMETRY_HEADER=$(cat /run/secrets/telemetry_header 2>/dev/null || echo "") |
| 28 | + --mount=type=secret,id=telemetry_api_key,env=TELEMETRY_API_KEY \ |
| 29 | + --mount=type=secret,id=telemetry_endpoint,env=TELEMETRY_ENDPOINT \ |
| 30 | + --mount=type=secret,id=telemetry_header,env=TELEMETRY_HEADER <<EOT |
| 31 | + set -ex |
37 | 32 | xx-go build -trimpath -ldflags "-s -w -X 'github.com/docker/cagent/cmd/root.Version=$GIT_TAG' -X 'github.com/docker/cagent/cmd/root.Commit=$GIT_COMMIT' -X 'github.com/docker/cagent/cmd/root.BuildTime=$BUILD_DATE' -X 'github.com/docker/cagent/internal/telemetry.TelemetryEndpoint=$TELEMETRY_ENDPOINT' -X 'github.com/docker/cagent/internal/telemetry.TelemetryAPIKey=$TELEMETRY_API_KEY' -X 'github.com/docker/cagent/internal/telemetry.TelemetryHeader=$TELEMETRY_HEADER'" -o /binaries/cagent-$TARGETOS-$TARGETARCH . |
| 33 | + file /binaries/cagent-$TARGETos-$TARGETARCH |
38 | 34 | xx-verify --static /binaries/cagent-$TARGETOS-$TARGETARCH |
39 | 35 | if [ "$TARGETOS" = "windows" ]; then |
40 | 36 | mv /binaries/cagent-$TARGETOS-$TARGETARCH /binaries/cagent-$TARGETOS-$TARGETARCH.exe |
|
0 commit comments