FROM --platform=$BUILDPLATFORM golang:alpine AS builderWORKDIR /appCOPY ../go.mod ../go.sum ./RUN go mod download# Copy source filesCOPY . ./RUN apk add --no-cache ca-certificates && update-ca-certificates# BuildARG TARGETOS TARGETARCH TARGETVARIANTRUN if [ "$TARGETARCH" = "arm" ] && [ -n "$TARGETVARIANT" ]; then \export GOARM="${TARGETVARIANT#v}"; \fi; \CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags "-w -s" -o /agent ./internal/cmd/agentRUN rm -rf /tmp/*# --------------------------# Final image: default scratch-based agent# --------------------------FROM scratchCOPY --from=builder /agent /agentCOPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/# this is so we don't need to create the /tmp directory in the scratch containerCOPY --from=builder /tmp /tmp# AMD GPU name lookup (used by agent on Linux when /usr/share/libdrm/amdgpu.ids is read)COPY --from=builder /app/agent/test-data/amdgpu.ids /usr/share/libdrm/amdgpu.ids# Ensure data persistence across container recreationsVOLUME ["/var/lib/beszel-agent"]ENTRYPOINT ["/agent"]