forked from openclarity/openclarity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.cli
35 lines (26 loc) · 952 Bytes
/
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
# syntax=docker/dockerfile:1.2
FROM golang:1.20.7-alpine AS builder
RUN apk add --update --no-cache gcc g++ git ca-certificates build-base
# Copy API code
WORKDIR /build
COPY api ./api
# Copy shared code
WORKDIR /build/shared
COPY shared .
# Copy CLI code
WORKDIR /build/cli
COPY cli .
# Build CLI code
# NOTE(sambetts) Declare ARGs where they are used to prevent Docker rerunning
# all the previous steps when they change, and use buildkit inline cache to
# keep go mod cache and compilation cache between docker runs.
ARG COMMIT_HASH
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 go build -ldflags="-s -w \
-X 'github.com/openclarity/kubeclarity/cli/pkg.GitRevision=${COMMIT_HASH}'" -o cli ./main.go
FROM alpine:3.18
WORKDIR /app
COPY --from=builder /build/cli/cli ./cli
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
ENTRYPOINT ["/app/cli"]