-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
46 lines (36 loc) · 1.19 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
42
43
44
45
46
FROM golang:1.22 AS builder
ARG GOOS
ARG GOARCH
ARG APP_NAME
WORKDIR /app
RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,source=go.sum,target=go.sum \
--mount=type=bind,source=go.mod,target=go.mod \
go mod download
# Lint
FROM builder AS lint-internal
COPY --from=golangci/golangci-lint:v1.60 /usr/bin/golangci-lint /usr/bin/golangci-lint
RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,target=. \
golangci-lint run
## Export the lint results only
FROM scratch AS lint
COPY --from=lint-internal /app /
# Test
FROM builder AS test-internal
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,target=. \
go test -v ./...
## Export the test results only
FROM scratch AS test
COPY --from=test-internal /app /
# Build the binary
FROM builder AS build
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,target=. \
CGO_ENABLED=0 GOOS=${GOOS:-linux} GOARCH=${GOARCH:-amd64} go build -a -o /${APP_NAME:-kaptest} ./internal/main.go
FROM scratch AS export-binary
ARG APP_NAME
COPY --from=build /${APP_NAME:-kaptest} /