2021-08-13 16:12:38 +03:00
# syntax = docker/dockerfile-upstream:1.2.0-labs
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
2022-08-25 20:29:58 +04:00
# Generated on 2022-08-25T16:11:18Z by kres d2252ce.
2021-08-13 16:12:38 +03:00
ARG TOOLCHAIN
2021-10-13 21:34:32 +03:00
# cleaned up specs and compiled versions
FROM scratch AS generate
2022-08-25 20:29:58 +04:00
FROM ghcr.io/siderolabs/ca-certificates:v1.1.0 AS image-ca-certificates
2021-08-13 16:12:38 +03:00
2022-08-25 20:29:58 +04:00
FROM ghcr.io/siderolabs/fhs:v1.1.0 AS image-fhs
2021-08-13 16:12:38 +03:00
# runs markdownlint
2022-08-25 20:29:58 +04:00
FROM node:18.7.0-alpine AS lint-markdown
2021-08-13 16:12:38 +03:00
WORKDIR /src
2022-08-25 20:29:58 +04:00
RUN npm i -g markdownlint-cli@0.31.1
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
# base toolchain image
FROM ${TOOLCHAIN} AS toolchain
RUN apk --update --no-cache add bash curl build-base protoc protobuf-dev
# build tools
FROM toolchain AS tools
2021-05-09 11:30:47 -07:00
ENV GO111MODULE on
2021-08-13 16:12:38 +03:00
ENV CGO_ENABLED 0
ENV GOPATH /go
2022-08-25 20:29:58 +04:00
ARG GOLANGCILINT_VERSION
RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@${ GOLANGCILINT_VERSION } \
&& mv /go/bin/golangci-lint /bin/golangci-lint
2021-08-13 16:12:38 +03:00
ARG GOFUMPT_VERSION
2022-08-25 20:29:58 +04:00
RUN go install mvdan.cc/gofumpt@${ GOFUMPT_VERSION } \
&& mv /go/bin/gofumpt /bin/gofumpt
ARG GOIMPORTS_VERSION
RUN go install golang.org/x/tools/cmd/goimports@${ GOIMPORTS_VERSION } \
&& mv /go/bin/goimports /bin/goimports
ARG DEEPCOPY_VERSION
RUN go install github.com/siderolabs/deep-copy@${ DEEPCOPY_VERSION } \
&& mv /go/bin/deep-copy /bin/deep-copy
2021-08-13 16:12:38 +03:00
# tools and sources
FROM tools AS base
WORKDIR /src
COPY ./go.mod .
COPY ./go.sum .
RUN --mount= type = cache,target= /go/pkg go mod download
RUN --mount= type = cache,target= /go/pkg go mod verify
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
2021-10-13 21:34:32 +03:00
# builds discovery-service-linux-amd64
FROM base AS discovery-service-linux-amd64-build
COPY --from= generate / /
WORKDIR /src/cmd/discovery-service
RUN --mount= type = cache,target= /root/.cache/go-build --mount= type = cache,target= /go/pkg go build -ldflags "-s -w" -o /discovery-service-linux-amd64
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)
# runs goimports
FROM base AS lint-goimports
RUN FILES = " $( goimports -l -local github.com/siderolabs/discovery-service .) " && test -z " ${ FILES } " || ( echo -e " Source code is not formatted with 'goimports -w -local github.com/siderolabs/discovery-service .':\n ${ FILES } " ; exit 1)
2021-08-13 16:12:38 +03:00
# runs golangci-lint
FROM base AS lint-golangci-lint
COPY .golangci.yml .
ENV GOGC 50
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
# runs unit-tests with race detector
FROM base AS unit-tests-race
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
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 }
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
FROM scratch AS unit-tests
COPY --from= unit-tests-run /src/coverage.txt /coverage.txt
2021-09-22 23:08:22 +03:00
FROM discovery-service-linux-${TARGETARCH} AS discovery-service
2021-08-13 16:12:38 +03:00
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