forked from openclarity/openclarity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.backend
55 lines (41 loc) · 1.47 KB
/
Dockerfile.backend
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.2
FROM node:20-slim AS site-build
WORKDIR /app/ui-build
COPY ui .
RUN npm i
RUN npm run build
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/api
COPY api .
# Copy runtime_scan code including runtime_scan/api code
WORKDIR /build/runtime_scan
COPY runtime_scan .
# Copy runtime_k8s_scanner code
WORKDIR /build/runtime_k8s_scanner
COPY runtime_k8s_scanner .
# Copy shared code
WORKDIR /build/shared
COPY shared .
# Copy backend code
WORKDIR /build/backend
COPY backend .
# Build backend 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 VERSION
ARG BUILD_TIMESTAMP
ARG COMMIT_HASH
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go build -ldflags="-s -w \
-X 'github.com/openclarity/kubeclarity/backend/pkg/version.Version=${VERSION}' \
-X 'github.com/openclarity/kubeclarity/backend/pkg/version.CommitHash=${COMMIT_HASH}' \
-X 'github.com/openclarity/kubeclarity/backend/pkg/version.BuildTimestamp=${BUILD_TIMESTAMP}'" -o backend ./cmd/backend/main.go
FROM alpine:3.18
WORKDIR /app
COPY --from=builder ["/build/backend/backend", "./backend"]
COPY --from=site-build ["/app/ui-build/build", "site"]
ENTRYPOINT ["/app/backend"]