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.
#
2021-09-23 23:58:01 +03:00
# Generated on 2021-09-23T16:56:44Z by kres 2a27963-dirty.
2021-08-13 16:12:38 +03:00
ARG TOOLCHAIN
FROM ghcr.io/talos-systems/ca-certificates:v0.3.0-12-g90722c3 AS image-ca-certificates
FROM ghcr.io/talos-systems/fhs:v0.3.0-12-g90722c3 AS image-fhs
# runs markdownlint
FROM node:14.8.0-alpine AS lint-markdown
RUN npm i -g markdownlint-cli@0.23.2
RUN npm i sentences-per-line@0.2.1
WORKDIR /src
COPY .markdownlint.json .
COPY ./README.md ./README.md
RUN markdownlint --ignore "CHANGELOG.md" --ignore "**/node_modules/**" --ignore '**/hack/chglog/**' --rules /node_modules/sentences-per-line/index.js .
2021-09-22 23:08:22 +03:00
# collects proto specs
FROM scratch AS proto-specs
ADD https://raw.githubusercontent.com/protocolbuffers/protobuf/master/src/google/protobuf/duration.proto /api/vendor/google/
2021-09-23 23:58:01 +03:00
ADD api/v1alpha1/server/cluster.proto /api/v1alpha1/server/pb/
ADD api/v1alpha1/client/affiliate.proto /api/v1alpha1/client/pb/
2021-09-22 23:08:22 +03:00
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
2021-09-22 23:08:22 +03:00
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b /bin v1.42.1
2021-08-13 16:12:38 +03:00
ARG GOFUMPT_VERSION
2021-09-22 23:08:22 +03:00
RUN go install mvdan.cc/gofumpt/gofumports@${ GOFUMPT_VERSION } \
2021-08-13 16:12:38 +03:00
&& mv /go/bin/gofumports /bin/gofumports
2021-09-22 23:08:22 +03:00
ARG PROTOBUF_GO_VERSION
RUN 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 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 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 VTPROTOBUF_VERSION
RUN go install github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto@${ VTPROTOBUF_VERSION }
RUN mv /go/bin/protoc-gen-go-vtproto /bin
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 ./api ./api
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-09-22 23:08:22 +03:00
# runs protobuf compiler
FROM tools AS proto-compile
COPY --from= proto-specs / /
2021-09-23 23:58:01 +03:00
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 /api/v1alpha1/server/pb/cluster.proto
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 /api/v1alpha1/client/pb/affiliate.proto
RUN rm /api/v1alpha1/server/pb/cluster.proto
RUN rm /api/v1alpha1/client/pb/affiliate.proto
2021-08-13 16:12:38 +03:00
# runs gofumpt
FROM base AS lint-gofumpt
RUN find . -name '*.pb.go' | xargs -r rm
RUN find . -name '*.pb.gw.go' | xargs -r rm
2021-09-22 23:08:22 +03:00
RUN FILES = " $( gofumports -l -local github.com/talos-systems/discovery-service .) " && test -z " ${ FILES } " || ( echo -e " Source code is not formatted with 'gofumports -w -local github.com/talos-systems/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-09-22 23:08:22 +03:00
# cleaned up specs and compiled versions
FROM scratch AS generate
COPY --from= proto-compile /api/ /api/
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
# 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
FROM scratch AS discovery-service-linux-amd64
COPY --from= discovery-service-linux-amd64-build /discovery-service-linux-amd64 /discovery-service-linux-amd64
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 / /
2021-09-22 23:08:22 +03:00
LABEL org.opencontainers.image.source https://github.com/talos-systems/discovery-service
ENTRYPOINT [ "/discovery-service" ]
2021-08-13 16:12:38 +03:00