-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
44 lines (31 loc) · 1.14 KB
/
Dockerfile
File metadata and controls
44 lines (31 loc) · 1.14 KB
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
# Copyright The Linux Foundation and each contributor to LFX.
# SPDX-License-Identifier: MIT
# Build stage
FROM cgr.dev/chainguard/go:latest@sha256:06aa40c98b7ffbed72dd010470c2f6fa9b44f2e8d249eb3d53b8893b9d1a8ee7 AS builder
ARG TARGETARCH
ENV CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH
WORKDIR /build
# Copy go mod files
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
# Build the application with version info
ARG VERSION=dev
ARG BUILD_TIME=unknown
ARG GIT_COMMIT=unknown
RUN go build -o /go/bin/survey-api -trimpath \
-ldflags="-w -s -X main.Version=${VERSION} -X main.BuildTime=${BUILD_TIME} -X main.GitCommit=${GIT_COMMIT}" \
github.com/linuxfoundation/lfx-v2-survey-service/cmd/survey-api
# Final stage
FROM cgr.dev/chainguard/static:latest@sha256:d6a97eb401cbc7c6d48be76ad81d7899b94303580859d396b52b67bc84ea7345
# Use non-root user
USER nonroot
# Copy binary from builder
COPY --from=builder /go/bin/survey-api /cmd/survey-api
# Expose port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD ["/cmd/survey-api", "-health-check"]
ENTRYPOINT ["/cmd/survey-api"]