Files
docker-agent/Dockerfile
T
2025-09-25 19:11:58 +02:00

54 lines
2.1 KiB
Docker

# syntax=docker/dockerfile:1
# xx is a helper for cross-compilation
FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.7.0 AS xx
FROM --platform=$BUILDPLATFORM golang:1.25.1-alpine3.22 AS builder-base
COPY --from=xx / /
WORKDIR /src
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=bind,source=go.mod,target=go.mod \
--mount=type=bind,source=go.sum,target=go.sum \
go mod download
FROM builder-base AS builder
COPY . ./
ARG GIT_TAG
ARG GIT_COMMIT
ARG BUILD_DATE
ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
RUN --mount=type=cache,target=/root/.cache,id=docker-ai-$TARGETPLATFORM \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=secret,id=telemetry_api_key,env=TELEMETRY_API_KEY \
--mount=type=secret,id=telemetry_endpoint,env=TELEMETRY_ENDPOINT \
--mount=type=secret,id=telemetry_header,env=TELEMETRY_HEADER <<EOT
set -ex
xx-go build -trimpath -ldflags "-s -w -X 'github.com/docker/cagent/pkg/version.Version=$GIT_TAG' -X 'github.com/docker/cagent/pkg/version.Commit=$GIT_COMMIT' -X 'github.com/docker/cagent/pkg/telemetry.TelemetryEndpoint=$TELEMETRY_ENDPOINT' -X 'github.com/docker/cagent/pkg/telemetry.TelemetryAPIKey=$TELEMETRY_API_KEY' -X 'github.com/docker/cagent/pkg/telemetry.TelemetryHeader=$TELEMETRY_HEADER'" -o /binaries/cagent-$TARGETOS-$TARGETARCH .
xx-verify --static /binaries/cagent-$TARGETOS-$TARGETARCH
if [ "$TARGETOS" = "windows" ]; then
mv /binaries/cagent-$TARGETOS-$TARGETARCH /binaries/cagent-$TARGETOS-$TARGETARCH.exe
fi
EOT
FROM scratch AS local
ARG TARGETOS TARGETARCH
COPY --from=builder /binaries/cagent-$TARGETOS-$TARGETARCH cagent
FROM scratch AS cross
COPY --from=builder /binaries .
FROM alpine
RUN apk add --no-cache ca-certificates docker-cli
RUN addgroup -S cagent && adduser -S -G cagent cagent
ARG TARGETOS TARGETARCH
ENV DOCKER_MCP_IN_CONTAINER=1
ENV TERM=xterm-256color
RUN mkdir /data /work && chmod 777 /data /work
COPY --from=docker/mcp-gateway:v2 /docker-mcp /usr/local/lib/docker/cli-plugins/
COPY --from=builder /binaries/cagent-$TARGETOS-$TARGETARCH /cagent
USER cagent
WORKDIR /work
ENTRYPOINT ["/cagent"]