forked from k3s-io/kine
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
98 lines (82 loc) · 2.84 KB
/
Dockerfile
File metadata and controls
98 lines (82 loc) · 2.84 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
FROM golang:1.24-alpine3.22 AS infra
ARG ARCH=amd64
RUN apk -U add bash coreutils git gcc musl-dev vim less curl wget ca-certificates
# go imports version gopls/v0.15.3
# https://github.com/golang/tools/releases/latest
RUN go install golang.org/x/tools/cmd/goimports@cd70d50baa6daa949efa12e295e10829f3a7bd46
RUN rm -rf /go/src /go/pkg
RUN if [ "${ARCH}" == "amd64" ]; then \
curl -sL https://raw.githubusercontent.com/golangci/golangci-lint/refs/tags/v1.64.8/install.sh | sh -s -- v1.64.8; \
fi
ENV SRC_DIR=/go/src/github.com/k3s-io/kine
WORKDIR ${SRC_DIR}/
# Validate needs everything in the project, so we separate it out for better caching
FROM infra AS validate
ARG SKIP_VALIDATE
ENV SKIP_VALIDATE=${SKIP_VALIDATE}
COPY . .
RUN --mount=type=cache,id=gomod,target=/go/pkg/mod \
--mount=type=cache,id=gobuild,target=/root/.cache/go-build \
--mount=type=cache,id=lint,target=/root/.cache/golangci-lint \
./scripts/validate
FROM infra AS build
ARG TAG
ARG DIRTY
ARG ARCH=amd64
ENV TAG=${TAG} DIRTY=${DIRTY} ARCH=${ARCH}
COPY ./scripts/build ./scripts/version ./scripts/
COPY ./go.mod ./go.sum ./main.go ./
COPY ./pkg ./pkg
COPY ./.git ./.git
COPY ./.golangci.json ./.golangci.json
RUN --mount=type=cache,id=gomod,target=/go/pkg/mod \
--mount=type=cache,id=gobuild,target=/root/.cache/go-build \
./scripts/build
FROM scratch AS binary
ENV SRC_DIR=/go/src/github.com/k3s-io/kine
COPY --from=build ${SRC_DIR}/bin /bin
FROM alpine:3.22 AS package
COPY bin/kine /bin/kine
RUN mkdir /db && chown nobody /db
VOLUME /db
EXPOSE 2379/tcp
USER nobody
ENTRYPOINT ["/bin/kine"]
FROM --platform=$BUILDPLATFORM tonistiigi/xx AS xx
FROM --platform=$BUILDPLATFORM golang:1.24-alpine3.22 AS multi-arch-build
COPY --from=xx / /
ARG TAG
ARG DIRTY
ARG TARGETOS
ARG TARGETARCH
ENV TAG=${TAG} DIRTY=${DIRTY} CGO_ENABLED=1
RUN apk -U add bash coreutils git vim less curl wget ca-certificates clang lld
RUN xx-apk add musl-dev gcc
# go imports version gopls/v0.15.3
# https://github.com/golang/tools/releases/latest
RUN xx-go install golang.org/x/tools/cmd/goimports@cd70d50baa6daa949efa12e295e10829f3a7bd46
RUN rm -rf /go/src /go/pkg
ENV SRC_DIR=/go/src/github.com/k3s-io/kine
WORKDIR ${SRC_DIR}/
COPY ./scripts/buildx ./scripts/version ./scripts/
COPY ./go.mod ./go.sum ./main.go ./
COPY ./pkg ./pkg
COPY ./.git ./.git
COPY ./.golangci.json ./.golangci.json
RUN --mount=type=cache,id=gomod,target=/go/pkg/mod \
./scripts/buildx
FROM scratch AS multi-arch-binary
ENV SRC_DIR=/go/src/github.com/k3s-io/kine
COPY --from=multi-arch-build ${SRC_DIR}/bin /
FROM alpine:3.22 AS multi-arch-package
ARG TARGETARCH
ENV ARCH=${TARGETARCH}
RUN if [ "${TARGETARCH}" == "arm/v7" ]; then \
ARCH=arm; \
fi
COPY --from=multi-arch-build /go/src/github.com/k3s-io/kine/bin/kine-$ARCH /bin/kine
RUN mkdir /db && chown nobody /db
VOLUME /db
EXPOSE 2379/tcp
USER nobody
ENTRYPOINT ["/bin/kine"]