-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
128 lines (105 loc) · 5.67 KB
/
Copy pathDockerfile
File metadata and controls
128 lines (105 loc) · 5.67 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# syntax = docker/dockerfile-upstream:1.17.1-labs
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2025-07-23T09:49:31Z by kres 4c6b4c0.
ARG TOOLCHAIN
# cleaned up specs and compiled versions
FROM scratch AS generate
FROM ghcr.io/siderolabs/ca-certificates:v1.10.0 AS image-ca-certificates
FROM ghcr.io/siderolabs/fhs:v1.10.0 AS image-fhs
# runs markdownlint
FROM docker.io/oven/bun:1.2.18-alpine AS lint-markdown
WORKDIR /src
RUN bun i markdownlint-cli@0.45.0 sentences-per-line@0.3.0
COPY .markdownlint.json .
COPY ./README.md ./README.md
RUN bunx markdownlint --ignore "CHANGELOG.md" --ignore "**/node_modules/**" --ignore '**/hack/chglog/**' --rules sentences-per-line .
# base toolchain image
FROM --platform=${BUILDPLATFORM} ${TOOLCHAIN} AS toolchain
RUN apk --update --no-cache add bash curl build-base protoc protobuf-dev
# build tools
FROM --platform=${BUILDPLATFORM} toolchain AS tools
ENV GO111MODULE=on
ARG CGO_ENABLED
ENV CGO_ENABLED=${CGO_ENABLED}
ARG GOTOOLCHAIN
ENV GOTOOLCHAIN=${GOTOOLCHAIN}
ARG GOEXPERIMENT
ENV GOEXPERIMENT=${GOEXPERIMENT}
ENV GOPATH=/go
ARG DEEPCOPY_VERSION
RUN --mount=type=cache,target=/root/.cache/go-build,id=example-workload/root/.cache/go-build --mount=type=cache,target=/go/pkg,id=example-workload/go/pkg go install github.com/siderolabs/deep-copy@${DEEPCOPY_VERSION} \
&& mv /go/bin/deep-copy /bin/deep-copy
ARG GOLANGCILINT_VERSION
RUN --mount=type=cache,target=/root/.cache/go-build,id=example-workload/root/.cache/go-build --mount=type=cache,target=/go/pkg,id=example-workload/go/pkg go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${GOLANGCILINT_VERSION} \
&& mv /go/bin/golangci-lint /bin/golangci-lint
RUN --mount=type=cache,target=/root/.cache/go-build,id=example-workload/root/.cache/go-build --mount=type=cache,target=/go/pkg,id=example-workload/go/pkg go install golang.org/x/vuln/cmd/govulncheck@latest \
&& mv /go/bin/govulncheck /bin/govulncheck
ARG GOFUMPT_VERSION
RUN go install mvdan.cc/gofumpt@${GOFUMPT_VERSION} \
&& mv /go/bin/gofumpt /bin/gofumpt
# tools and sources
FROM tools AS base
WORKDIR /src
COPY go.mod go.mod
COPY go.sum go.sum
RUN cd .
RUN --mount=type=cache,target=/go/pkg,id=example-workload/go/pkg go mod download
RUN --mount=type=cache,target=/go/pkg,id=example-workload/go/pkg go mod verify
COPY ./cmd ./cmd
COPY ./internal ./internal
RUN --mount=type=cache,target=/go/pkg,id=example-workload/go/pkg go list -mod=readonly all >/dev/null
# builds example-workload-linux-amd64
FROM base AS example-workload-linux-amd64-build
COPY --from=generate / /
WORKDIR /src/cmd/example-workload
ARG GO_BUILDFLAGS
ARG GO_LDFLAGS
RUN --mount=type=cache,target=/root/.cache/go-build,id=example-workload/root/.cache/go-build --mount=type=cache,target=/go/pkg,id=example-workload/go/pkg GOARCH=amd64 GOOS=linux go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS}" -o /example-workload-linux-amd64
# builds example-workload-linux-arm64
FROM base AS example-workload-linux-arm64-build
COPY --from=generate / /
WORKDIR /src/cmd/example-workload
ARG GO_BUILDFLAGS
ARG GO_LDFLAGS
RUN --mount=type=cache,target=/root/.cache/go-build,id=example-workload/root/.cache/go-build --mount=type=cache,target=/go/pkg,id=example-workload/go/pkg GOARCH=arm64 GOOS=linux go build ${GO_BUILDFLAGS} -ldflags "${GO_LDFLAGS}" -o /example-workload-linux-arm64
# runs gofumpt
FROM base AS lint-gofumpt
RUN FILES="$(gofumpt -l .)" && test -z "${FILES}" || (echo -e "Source code is not formatted with 'gofumpt -w .':\n${FILES}"; exit 1)
# runs golangci-lint
FROM base AS lint-golangci-lint
WORKDIR /src
COPY .golangci.yml .
ENV GOGC=50
RUN --mount=type=cache,target=/root/.cache/go-build,id=example-workload/root/.cache/go-build --mount=type=cache,target=/root/.cache/golangci-lint,id=example-workload/root/.cache/golangci-lint,sharing=locked --mount=type=cache,target=/go/pkg,id=example-workload/go/pkg golangci-lint run --config .golangci.yml
# runs govulncheck
FROM base AS lint-govulncheck
WORKDIR /src
RUN --mount=type=cache,target=/root/.cache/go-build,id=example-workload/root/.cache/go-build --mount=type=cache,target=/go/pkg,id=example-workload/go/pkg govulncheck ./...
# runs unit-tests with race detector
FROM base AS unit-tests-race
WORKDIR /src
ARG TESTPKGS
RUN --mount=type=cache,target=/root/.cache/go-build,id=example-workload/root/.cache/go-build --mount=type=cache,target=/go/pkg,id=example-workload/go/pkg --mount=type=cache,target=/tmp,id=example-workload/tmp CGO_ENABLED=1 go test -race ${TESTPKGS}
# runs unit-tests
FROM base AS unit-tests-run
WORKDIR /src
ARG TESTPKGS
RUN --mount=type=cache,target=/root/.cache/go-build,id=example-workload/root/.cache/go-build --mount=type=cache,target=/go/pkg,id=example-workload/go/pkg --mount=type=cache,target=/tmp,id=example-workload/tmp go test -covermode=atomic -coverprofile=coverage.txt -coverpkg=${TESTPKGS} ${TESTPKGS}
FROM scratch AS example-workload-linux-amd64
COPY --from=example-workload-linux-amd64-build /example-workload-linux-amd64 /example-workload-linux-amd64
FROM scratch AS example-workload-linux-arm64
COPY --from=example-workload-linux-arm64-build /example-workload-linux-arm64 /example-workload-linux-arm64
FROM scratch AS unit-tests
COPY --from=unit-tests-run /src/coverage.txt /coverage-unit-tests.txt
FROM example-workload-linux-${TARGETARCH} AS example-workload
FROM scratch AS example-workload-all
COPY --from=example-workload-linux-amd64 / /
COPY --from=example-workload-linux-arm64 / /
FROM scratch AS image-example-workload
ARG TARGETARCH
COPY --from=example-workload example-workload-linux-${TARGETARCH} /example-workload
COPY --from=image-fhs / /
COPY --from=image-ca-certificates / /
LABEL org.opencontainers.image.source=https://github.com/siderolabs/example-workload
ENTRYPOINT ["/example-workload"]