2024-05-10 12:08:16 +02:00
# syntax = docker/dockerfile-upstream:1.7.1-labs
2021-08-13 16:12:38 +03:00
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
2024-05-28 02:57:44 +03:00
# Generated on 2024-05-28T00:03:10Z by kres bcb280a.
2021-08-13 16:12:38 +03:00
ARG TOOLCHAIN
2024-05-10 12:08:16 +02:00
FROM ghcr.io/siderolabs/ca-certificates:v1.7.0 AS image-ca-certificates
2021-10-13 21:34:32 +03:00
2024-05-10 12:08:16 +02:00
FROM ghcr.io/siderolabs/fhs:v1.7.0 AS image-fhs
2021-08-13 16:12:38 +03:00
# runs markdownlint
2024-05-10 12:08:16 +02:00
FROM docker.io/node:22.2.0-alpine3.19 AS lint-markdown
2021-08-13 16:12:38 +03:00
WORKDIR /src
2024-05-28 02:57:44 +03:00
RUN npm i -g markdownlint-cli@0.41.0
2022-08-25 20:29:58 +04:00
RUN npm i sentences-per-line@0.2.1
2021-08-13 16:12:38 +03:00
COPY .markdownlint.json .
COPY ./README.md ./README.md
2022-08-25 20:29:58 +04:00
RUN markdownlint --ignore "CHANGELOG.md" --ignore "**/node_modules/**" --ignore '**/hack/chglog/**' --rules node_modules/sentences-per-line/index.js .
2021-08-13 16:12:38 +03:00
2024-05-10 12:08:16 +02:00
# collects proto specs
FROM scratch AS proto-specs
ADD api/storage/storage.proto /api/storage/
2021-08-13 16:12:38 +03:00
# base toolchain image
2024-05-28 02:57:44 +03:00
FROM --platform=${BUILDPLATFORM} ${TOOLCHAIN} AS toolchain
2021-08-13 16:12:38 +03:00
RUN apk --update --no-cache add bash curl build-base protoc protobuf-dev
# build tools
2023-01-30 20:44:11 +04:00
FROM --platform=${BUILDPLATFORM} toolchain AS tools
2021-05-09 11:30:47 -07:00
ENV GO111MODULE on
2023-01-30 20:44:11 +04:00
ARG CGO_ENABLED
ENV CGO_ENABLED ${ CGO_ENABLED }
2023-10-11 14:51:30 +04:00
ARG GOTOOLCHAIN
ENV GOTOOLCHAIN ${ GOTOOLCHAIN }
ARG GOEXPERIMENT
ENV GOEXPERIMENT ${ GOEXPERIMENT }
2021-08-13 16:12:38 +03:00
ENV GOPATH /go
2024-05-10 12:08:16 +02:00
ARG PROTOBUF_GO_VERSION
RUN --mount= type = cache,target= /root/.cache/go-build --mount= type = cache,target= /go/pkg go install google.golang.org/protobuf/cmd/protoc-gen-go@v${ PROTOBUF_GO_VERSION }
RUN mv /go/bin/protoc-gen-go /bin
ARG GRPC_GO_VERSION
RUN --mount= type = cache,target= /root/.cache/go-build --mount= type = cache,target= /go/pkg go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v${ GRPC_GO_VERSION }
RUN mv /go/bin/protoc-gen-go-grpc /bin
ARG GRPC_GATEWAY_VERSION
RUN --mount= type = cache,target= /root/.cache/go-build --mount= type = cache,target= /go/pkg go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v${ GRPC_GATEWAY_VERSION }
RUN mv /go/bin/protoc-gen-grpc-gateway /bin
ARG GOIMPORTS_VERSION
RUN --mount= type = cache,target= /root/.cache/go-build --mount= type = cache,target= /go/pkg go install golang.org/x/tools/cmd/goimports@v${ GOIMPORTS_VERSION }
RUN mv /go/bin/goimports /bin
ARG VTPROTOBUF_VERSION
RUN --mount= type = cache,target= /root/.cache/go-build --mount= type = cache,target= /go/pkg go install github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto@v${ VTPROTOBUF_VERSION }
RUN mv /go/bin/protoc-gen-go-vtproto /bin
2023-10-11 14:51:30 +04:00
ARG DEEPCOPY_VERSION
RUN --mount= type = cache,target= /root/.cache/go-build --mount= type = cache,target= /go/pkg go install github.com/siderolabs/deep-copy@${ DEEPCOPY_VERSION } \
&& mv /go/bin/deep-copy /bin/deep-copy
2022-08-25 20:29:58 +04:00
ARG GOLANGCILINT_VERSION
2023-01-30 20:44:11 +04:00
RUN --mount= type = cache,target= /root/.cache/go-build --mount= type = cache,target= /go/pkg go install github.com/golangci/golangci-lint/cmd/golangci-lint@${ GOLANGCILINT_VERSION } \
2022-08-25 20:29:58 +04:00
&& mv /go/bin/golangci-lint /bin/golangci-lint
2023-01-30 20:44:11 +04:00
RUN --mount= type = cache,target= /root/.cache/go-build --mount= type = cache,target= /go/pkg go install golang.org/x/vuln/cmd/govulncheck@latest \
&& mv /go/bin/govulncheck /bin/govulncheck
2023-10-11 14:51:30 +04:00
ARG GOFUMPT_VERSION
RUN go install mvdan.cc/gofumpt@${ GOFUMPT_VERSION } \
&& mv /go/bin/gofumpt /bin/gofumpt
2021-08-13 16:12:38 +03:00
# tools and sources
FROM tools AS base
WORKDIR /src
2023-10-11 14:51:30 +04:00
COPY go.mod go.mod
COPY go.sum go.sum
RUN cd .
2021-08-13 16:12:38 +03:00
RUN --mount= type = cache,target= /go/pkg go mod download
RUN --mount= type = cache,target= /go/pkg go mod verify
2024-05-10 12:08:16 +02:00
COPY ./api ./api
2021-09-22 23:08:22 +03:00
COPY ./cmd ./cmd
2021-08-13 16:12:38 +03:00
COPY ./internal ./internal
COPY ./pkg ./pkg
RUN --mount= type = cache,target= /go/pkg go list -mod= readonly all >/dev/null
2024-05-10 12:08:16 +02:00
# runs protobuf compiler
FROM tools AS proto-compile
COPY --from= proto-specs / /
RUN protoc -I/api --go_out= paths = source_relative:/api --go-grpc_out= paths = source_relative:/api --go-vtproto_out= paths = source_relative:/api --go-vtproto_opt= features = marshal+unmarshal+size+equal+clone /api/storage/storage.proto
RUN rm /api/storage/storage.proto
RUN goimports -w -local github.com/siderolabs/discovery-service /api
RUN gofumpt -w /api
2021-08-13 16:12:38 +03:00
# runs gofumpt
FROM base AS lint-gofumpt
2022-08-25 20:29:58 +04:00
RUN FILES = " $( gofumpt -l .) " && test -z " ${ FILES } " || ( echo -e " Source code is not formatted with 'gofumpt -w .':\n ${ FILES } " ; exit 1)
2021-08-13 16:12:38 +03:00
# runs golangci-lint
FROM base AS lint-golangci-lint
2023-10-11 14:51:30 +04:00
WORKDIR /src
2021-08-13 16:12:38 +03:00
COPY .golangci.yml .
ENV GOGC 50
2024-05-10 12:08:16 +02:00
RUN golangci-lint config verify --config .golangci.yml
2021-08-13 16:12:38 +03:00
RUN --mount= type = cache,target= /root/.cache/go-build --mount= type = cache,target= /root/.cache/golangci-lint --mount= type = cache,target= /go/pkg golangci-lint run --config .golangci.yml
2023-01-30 20:44:11 +04:00
# runs govulncheck
FROM base AS lint-govulncheck
2023-10-11 14:51:30 +04:00
WORKDIR /src
2023-01-30 20:44:11 +04:00
RUN --mount= type = cache,target= /root/.cache/go-build --mount= type = cache,target= /go/pkg govulncheck ./...
2021-08-13 16:12:38 +03:00
# runs unit-tests with race detector
FROM base AS unit-tests-race
2023-10-11 14:51:30 +04:00
WORKDIR /src
2021-08-13 16:12:38 +03:00
ARG TESTPKGS
RUN --mount= type = cache,target= /root/.cache/go-build --mount= type = cache,target= /go/pkg --mount= type = cache,target= /tmp CGO_ENABLED = 1 go test -v -race -count 1 ${ TESTPKGS }
# runs unit-tests
FROM base AS unit-tests-run
2023-10-11 14:51:30 +04:00
WORKDIR /src
2021-08-13 16:12:38 +03:00
ARG TESTPKGS
RUN --mount= type = cache,target= /root/.cache/go-build --mount= type = cache,target= /go/pkg --mount= type = cache,target= /tmp go test -v -covermode= atomic -coverprofile= coverage.txt -coverpkg= ${ TESTPKGS } -count 1 ${ TESTPKGS }
2024-05-10 12:08:16 +02:00
# cleaned up specs and compiled versions
FROM scratch AS generate
COPY --from= proto-compile /api/ /api/
FROM scratch AS unit-tests
COPY --from= unit-tests-run /src/coverage.txt /coverage-unit-tests.txt
# builds discovery-service-linux-amd64
FROM base AS discovery-service-linux-amd64-build
COPY --from= generate / /
WORKDIR /src/cmd/discovery-service
ARG GO_BUILDFLAGS
ARG GO_LDFLAGS
RUN --mount= type = cache,target= /root/.cache/go-build --mount= type = cache,target= /go/pkg GOARCH = amd64 GOOS = linux go build ${ GO_BUILDFLAGS } -ldflags " ${ GO_LDFLAGS } " -o /discovery-service-linux-amd64
# builds discovery-service-linux-arm64
FROM base AS discovery-service-linux-arm64-build
COPY --from= generate / /
WORKDIR /src/cmd/discovery-service
ARG GO_BUILDFLAGS
ARG GO_LDFLAGS
RUN --mount= type = cache,target= /root/.cache/go-build --mount= type = cache,target= /go/pkg GOARCH = arm64 GOOS = linux go build ${ GO_BUILDFLAGS } -ldflags " ${ GO_LDFLAGS } " -o /discovery-service-linux-arm64
# builds snapshot-decoder-linux-amd64
FROM base AS snapshot-decoder-linux-amd64-build
COPY --from= generate / /
WORKDIR /src/cmd/snapshot-decoder
ARG GO_BUILDFLAGS
ARG GO_LDFLAGS
RUN --mount= type = cache,target= /root/.cache/go-build --mount= type = cache,target= /go/pkg GOARCH = amd64 GOOS = linux go build ${ GO_BUILDFLAGS } -ldflags " ${ GO_LDFLAGS } " -o /snapshot-decoder-linux-amd64
# builds snapshot-decoder-linux-arm64
FROM base AS snapshot-decoder-linux-arm64-build
COPY --from= generate / /
WORKDIR /src/cmd/snapshot-decoder
ARG GO_BUILDFLAGS
ARG GO_LDFLAGS
RUN --mount= type = cache,target= /root/.cache/go-build --mount= type = cache,target= /go/pkg GOARCH = arm64 GOOS = linux go build ${ GO_BUILDFLAGS } -ldflags " ${ GO_LDFLAGS } " -o /snapshot-decoder-linux-arm64
2021-10-13 21:34:32 +03:00
FROM scratch AS discovery-service-linux-amd64
COPY --from= discovery-service-linux-amd64-build /discovery-service-linux-amd64 /discovery-service-linux-amd64
2021-08-13 16:12:38 +03:00
2024-01-21 12:30:28 +02:00
FROM scratch AS discovery-service-linux-arm64
COPY --from= discovery-service-linux-arm64-build /discovery-service-linux-arm64 /discovery-service-linux-arm64
2024-05-10 12:08:16 +02:00
FROM scratch AS snapshot-decoder-linux-amd64
COPY --from= snapshot-decoder-linux-amd64-build /snapshot-decoder-linux-amd64 /snapshot-decoder-linux-amd64
FROM scratch AS snapshot-decoder-linux-arm64
COPY --from= snapshot-decoder-linux-arm64-build /snapshot-decoder-linux-arm64 /snapshot-decoder-linux-arm64
2021-08-13 16:12:38 +03:00
2021-09-22 23:08:22 +03:00
FROM discovery-service-linux-${TARGETARCH} AS discovery-service
2021-08-13 16:12:38 +03:00
2023-01-30 20:44:11 +04:00
FROM scratch AS discovery-service-all
COPY --from= discovery-service-linux-amd64 / /
2024-01-21 12:30:28 +02:00
COPY --from= discovery-service-linux-arm64 / /
2023-01-30 20:44:11 +04:00
2024-05-10 12:08:16 +02:00
FROM snapshot-decoder-linux-${TARGETARCH} AS snapshot-decoder
FROM scratch AS snapshot-decoder-all
COPY --from= snapshot-decoder-linux-amd64 / /
COPY --from= snapshot-decoder-linux-arm64 / /
2021-09-22 23:08:22 +03:00
FROM scratch AS image-discovery-service
2021-08-13 16:12:38 +03:00
ARG TARGETARCH
2021-09-22 23:08:22 +03:00
COPY --from= discovery-service discovery-service-linux-${ TARGETARCH } /discovery-service
2021-08-13 16:12:38 +03:00
COPY --from= image-fhs / /
COPY --from= image-ca-certificates / /
2022-08-25 20:29:58 +04:00
LABEL org.opencontainers.image.source https://github.com/siderolabs/discovery-service
2021-09-22 23:08:22 +03:00
ENTRYPOINT [ "/discovery-service" ]
2021-08-13 16:12:38 +03:00