forked from openclarity/vmclarity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.apiserver
40 lines (26 loc) · 1.19 KB
/
Dockerfile.apiserver
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
# syntax=docker/dockerfile:1.2
# xx is a helper for cross-compilation
FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.2.1@sha256:8879a398dedf0aadaacfbd332b29ff2f84bc39ae6d4e9c0a1109db27ac5ba012 AS xx
FROM --platform=$BUILDPLATFORM golang:1.20.7-bullseye AS builder
COPY --from=xx / /
ARG TARGETPLATFORM
RUN apt-get update && xx-apt-get install -y --no-install-recommends gcc libc6-dev
RUN xx-go --wrap
# Copy vmclarity code to /build and move to that directory
COPY . /build
WORKDIR /build
ARG VERSION
ARG BUILD_TIMESTAMP
ARG COMMIT_HASH
ENV CGO_ENABLED=1
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go build -ldflags="-s -w -extldflags -static \
-X 'github.com/openclarity/vmclarity/pkg/version.Version=${VERSION}' \
-X 'github.com/openclarity/vmclarity/pkg/version.CommitHash=${COMMIT_HASH}' \
-X 'github.com/openclarity/vmclarity/pkg/version.BuildTimestamp=${BUILD_TIMESTAMP}'" -o bin/vmclarity-apiserver ./cmd/vmclarity-apiserver/main.go
RUN xx-verify bin/vmclarity-apiserver
FROM alpine:3.18
WORKDIR /app
COPY --from=builder ["/build/bin/vmclarity-apiserver", "./vmclarity-apiserver"]
ENTRYPOINT ["/app/vmclarity-apiserver"]