github.com/twelho/conform@v0.0.0-20231016230407-c25e9238598a/Dockerfile (about) 1 # syntax = docker/dockerfile-upstream:1.2.0-labs 2 3 # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. 4 # 5 # Generated on 2022-09-19T13:49:50Z by kres 9ea8a33. 6 7 ARG TOOLCHAIN 8 9 # cleaned up specs and compiled versions 10 FROM scratch AS generate 11 12 FROM ghcr.io/siderolabs/ca-certificates:v1.2.0 AS image-ca-certificates 13 14 FROM ghcr.io/siderolabs/fhs:v1.2.0 AS image-fhs 15 16 # runs markdownlint 17 FROM docker.io/node:18.9.0-alpine3.16 AS lint-markdown 18 WORKDIR /src 19 RUN npm i -g markdownlint-cli@0.32.2 20 RUN npm i sentences-per-line@0.2.1 21 COPY .markdownlint.json . 22 COPY ./CHANGELOG.md ./CHANGELOG.md 23 COPY ./README.md ./README.md 24 RUN markdownlint --ignore "CHANGELOG.md" --ignore "**/node_modules/**" --ignore '**/hack/chglog/**' --rules node_modules/sentences-per-line/index.js . 25 26 # base toolchain image 27 FROM ${TOOLCHAIN} AS toolchain 28 RUN apk --update --no-cache add bash curl build-base protoc protobuf-dev git 29 30 # build tools 31 FROM --platform=${BUILDPLATFORM} toolchain AS tools 32 ENV GO111MODULE on 33 ENV CGO_ENABLED 0 34 ENV GOPATH /go 35 ARG GOLANGCILINT_VERSION 36 RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCILINT_VERSION} \ 37 && mv /go/bin/golangci-lint /bin/golangci-lint 38 ARG GOFUMPT_VERSION 39 RUN go install mvdan.cc/gofumpt@${GOFUMPT_VERSION} \ 40 && mv /go/bin/gofumpt /bin/gofumpt 41 ARG GOIMPORTS_VERSION 42 RUN go install golang.org/x/tools/cmd/goimports@${GOIMPORTS_VERSION} \ 43 && mv /go/bin/goimports /bin/goimports 44 ARG DEEPCOPY_VERSION 45 RUN go install github.com/siderolabs/deep-copy@${DEEPCOPY_VERSION} \ 46 && mv /go/bin/deep-copy /bin/deep-copy 47 48 # tools and sources 49 FROM tools AS base 50 WORKDIR /src 51 COPY ./go.mod . 52 COPY ./go.sum . 53 RUN --mount=type=cache,target=/go/pkg go mod download 54 RUN --mount=type=cache,target=/go/pkg go mod verify 55 COPY ./cmd ./cmd 56 COPY ./internal ./internal 57 RUN --mount=type=cache,target=/go/pkg go list -mod=readonly all >/dev/null 58 59 # builds conform-darwin-amd64 60 FROM base AS conform-darwin-amd64-build 61 COPY --from=generate / / 62 WORKDIR /src/cmd/conform 63 ARG VERSION_PKG="github.com/siderolabs/conform/internal/version" 64 ARG SHA 65 ARG TAG 66 RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=amd64 GOOS=darwin go build -ldflags "-s -w -X ${VERSION_PKG}.Name=conform -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /conform-darwin-amd64 67 68 # builds conform-darwin-arm64 69 FROM base AS conform-darwin-arm64-build 70 COPY --from=generate / / 71 WORKDIR /src/cmd/conform 72 ARG VERSION_PKG="github.com/siderolabs/conform/internal/version" 73 ARG SHA 74 ARG TAG 75 RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=arm64 GOOS=darwin go build -ldflags "-s -w -X ${VERSION_PKG}.Name=conform -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /conform-darwin-arm64 76 77 # builds conform-linux-amd64 78 FROM base AS conform-linux-amd64-build 79 COPY --from=generate / / 80 WORKDIR /src/cmd/conform 81 ARG VERSION_PKG="github.com/siderolabs/conform/internal/version" 82 ARG SHA 83 ARG TAG 84 RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=amd64 GOOS=linux go build -ldflags "-s -w -X ${VERSION_PKG}.Name=conform -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /conform-linux-amd64 85 86 # builds conform-linux-arm64 87 FROM base AS conform-linux-arm64-build 88 COPY --from=generate / / 89 WORKDIR /src/cmd/conform 90 ARG VERSION_PKG="github.com/siderolabs/conform/internal/version" 91 ARG SHA 92 ARG TAG 93 RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg GOARCH=arm64 GOOS=linux go build -ldflags "-s -w -X ${VERSION_PKG}.Name=conform -X ${VERSION_PKG}.SHA=${SHA} -X ${VERSION_PKG}.Tag=${TAG}" -o /conform-linux-arm64 94 95 # runs gofumpt 96 FROM base AS lint-gofumpt 97 RUN FILES="$(gofumpt -l .)" && test -z "${FILES}" || (echo -e "Source code is not formatted with 'gofumpt -w .':\n${FILES}"; exit 1) 98 99 # runs goimports 100 FROM base AS lint-goimports 101 RUN FILES="$(goimports -l -local github.com/siderolabs/conform .)" && test -z "${FILES}" || (echo -e "Source code is not formatted with 'goimports -w -local github.com/siderolabs/conform .':\n${FILES}"; exit 1) 102 103 # runs golangci-lint 104 FROM base AS lint-golangci-lint 105 COPY .golangci.yml . 106 ENV GOGC 50 107 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 108 109 # runs unit-tests with race detector 110 FROM base AS unit-tests-race 111 ARG TESTPKGS 112 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} 113 114 # runs unit-tests 115 FROM base AS unit-tests-run 116 ARG TESTPKGS 117 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} 118 119 FROM scratch AS conform-darwin-amd64 120 COPY --from=conform-darwin-amd64-build /conform-darwin-amd64 /conform-darwin-amd64 121 122 FROM scratch AS conform-darwin-arm64 123 COPY --from=conform-darwin-arm64-build /conform-darwin-arm64 /conform-darwin-arm64 124 125 FROM scratch AS conform-linux-amd64 126 COPY --from=conform-linux-amd64-build /conform-linux-amd64 /conform-linux-amd64 127 128 FROM scratch AS conform-linux-arm64 129 COPY --from=conform-linux-arm64-build /conform-linux-arm64 /conform-linux-arm64 130 131 FROM scratch AS unit-tests 132 COPY --from=unit-tests-run /src/coverage.txt /coverage.txt 133 134 FROM conform-linux-${TARGETARCH} AS conform 135 136 FROM scratch AS image-conform 137 ARG TARGETARCH 138 COPY --from=conform conform-linux-${TARGETARCH} /conform 139 COPY --from=image-fhs / / 140 COPY --from=image-ca-certificates / / 141 LABEL org.opencontainers.image.source https://github.com/siderolabs/conform 142 ENTRYPOINT ["/conform"] 143