forked from openclarity/vmclarity
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile.cli
55 lines (39 loc) · 1.8 KB
/
Dockerfile.cli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# syntax=docker/dockerfile:1@sha256:dbbd5e059e8a07ff7ea6233b213b36aa516b4c53c645f1817a4dd18b83cbea56
ARG VMCLARITY_TOOLS_BASE=ghcr.io/openclarity/vmclarity-tools-base:v0.6.0@sha256:dc9779be25bdbd3a8725e768764a223b8ba5fd906fc5afc67b417886086806d8
# xx is a helper for cross-compilation
FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.4.0@sha256:0cd3f05c72d6c9b038eb135f91376ee1169ef3a330d34e418e65e2a5c2e9c0d4 AS xx
FROM --platform=$BUILDPLATFORM golang:1.22.2-bullseye@sha256:3b55bf3986b2651a515f48ddf758b80a7d78d8be18706fd98aa74241992dac96 AS builder
COPY --link --from=xx / /
ARG TARGETPLATFORM
RUN --mount=type=cache,id=${TARGETPLATFORM}-apt,target=/var/cache/apt,sharing=locked \
apt-get update \
&& xx-apt-get install -y --no-install-recommends \
gcc \
libc6-dev
WORKDIR /build/cli
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=bind,source=.,target=/build,ro \
xx-go mod download -x
ARG VERSION
ARG BUILD_TIMESTAMP
ARG COMMIT_HASH
ARG BUILD_OPTS
ENV CGO_ENABLED=1
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=bind,source=.,target=/build,ro \
xx-go build ${BUILD_OPTS} -ldflags="-s -w -extldflags -static \
-X 'github.com/openclarity/vmclarity/core/version.Version=${VERSION}' \
-X 'github.com/openclarity/vmclarity/core/version.CommitHash=${COMMIT_HASH}' \
-X 'github.com/openclarity/vmclarity/core/version.BuildTimestamp=${BUILD_TIMESTAMP}'" \
-o /bin/vmclarity-cli cmd/main.go
FROM ${VMCLARITY_TOOLS_BASE}
RUN apk upgrade --quiet --no-cache
RUN apk add --update --no-cache \
util-linux \
ca-certificates \
libc6-compat
COPY --from=builder /bin/vmclarity-cli /bin/vmclarity-cli
ENTRYPOINT ["/bin/vmclarity-cli"]
CMD ["--help"]