generated from rode/new-collector-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
41 lines (31 loc) · 1.31 KB
/
Dockerfile
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
# syntax = docker/dockerfile:experimental
# Build the manager binary
FROM golang:1.17-alpine as builder
ENV GRPC_HEALTH_PROBE_VERSION="v0.3.6"
RUN wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
chmod +x /bin/grpc_health_probe
WORKDIR /workspace
RUN apk add --no-cache git
# Copy the Go Modules manifests
COPY go.mod go.sum /workspace/
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
# Copy the go source
COPY main.go main.go
COPY config config
COPY server server
COPY scanner scanner
COPY proto proto
# Build
RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o collector
FROM ghcr.io/aquasecurity/trivy:0.19.2 as trivy
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot as runner
LABEL org.opencontainers.image.source=https://github.com/rode/collector-image-scanner
WORKDIR /
COPY --from=trivy /usr/local/bin/trivy /bin/
COPY --from=builder /workspace/collector /bin/
COPY --from=builder /bin/grpc_health_probe .
USER nonroot:nonroot
ENTRYPOINT ["collector"]