-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
64 lines (53 loc) · 1.81 KB
/
Dockerfile
File metadata and controls
64 lines (53 loc) · 1.81 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
FROM golang:1.24 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.64 /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 ./...
# Test examples
FROM builder AS test-examples
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,target=. \
go run internal/main.go run ./examples/**/*/kaptest.yaml
## 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} /
FROM builder AS credits
ARG GOCREDITS_VERSION
RUN set -x && \
go install github.com/Songmu/gocredits/cmd/gocredits@${GOCREDITS_VERSION}
RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,source=go.sum,target=go.sum \
set -x && \
ls -alh /go/pkg/mod/github.com && \
gocredits -skip-missing . >/CREDITS
FROM scratch AS export-credits
COPY --from=credits /CREDITS /