forked from moby/buildkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hack: use tools build constraint for generated-files deps
Signed-off-by: CrazyMax <[email protected]>
- Loading branch information
Showing
55 changed files
with
19,872 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,57 @@ | ||
# syntax=docker/dockerfile-upstream:master | ||
|
||
# protoc is dynamically linked to glibc to can't use golang:1.10-alpine | ||
FROM golang:1.19-buster AS gobuild-base | ||
|
||
RUN apt-get update && apt-get --no-install-recommends install -y \ | ||
unzip \ | ||
&& true | ||
|
||
# https://github.com/golang/protobuf/blob/v1.3.5/.travis.yml#L15 | ||
ARG PROTOC_VERSION=3.11.4 | ||
ARG TARGETOS TARGETARCH | ||
RUN set -e; \ | ||
arch=$(echo $TARGETARCH | sed -e s/amd64/x86_64/ -e s/arm64/aarch_64/); \ | ||
wget -q https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-${TARGETOS}-${arch}.zip && unzip protoc-${PROTOC_VERSION}-${TARGETOS}-${arch}.zip -d /usr/local | ||
|
||
ARG GOGO_VERSION=v1.3.2 | ||
RUN --mount=target=/root/.cache,type=cache GO111MODULE=on go install \ | ||
github.com/gogo/protobuf/protoc-gen-gogo@${GOGO_VERSION} \ | ||
github.com/gogo/protobuf/protoc-gen-gogofaster@${GOGO_VERSION} \ | ||
github.com/gogo/protobuf/protoc-gen-gogoslick@${GOGO_VERSION} | ||
|
||
ARG PROTOBUF_VERSION=v1.3.5 | ||
RUN --mount=target=/root/.cache,type=cache GO111MODULE=on go install \ | ||
github.com/golang/protobuf/protoc-gen-go@${PROTOBUF_VERSION} | ||
|
||
ARG GO_VERSION="1.19" | ||
ARG PROTOC_VERSION="3.11.4" | ||
|
||
# protoc is dynamically linked to glibc so can't use alpine base | ||
FROM golang:${GO_VERSION}-buster AS base | ||
RUN apt-get update && apt-get --no-install-recommends install -y git unzip | ||
ARG PROTOC_VERSION | ||
ARG TARGETOS | ||
ARG TARGETARCH | ||
RUN <<EOT | ||
set -e | ||
arch=$(echo $TARGETARCH | sed -e s/amd64/x86_64/ -e s/arm64/aarch_64/) | ||
wget -q https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-${TARGETOS}-${arch}.zip | ||
unzip protoc-${PROTOC_VERSION}-${TARGETOS}-${arch}.zip -d /usr/local | ||
EOT | ||
WORKDIR /go/src/github.com/moby/buildkit | ||
|
||
# Generate into a subdirectory because if it is in the root then the | ||
# extraction with `docker export` ends up putting `.dockerenv`, `dev`, | ||
# `sys` and `proc` into the source directory. With this we can use | ||
# `tar --strip-components=1 generated-files` on the output of `docker | ||
# export`. | ||
FROM gobuild-base AS generated | ||
RUN mkdir /generated-files | ||
RUN --mount=target=/tmp/src \ | ||
cp -r /tmp/src/. . && \ | ||
git add -A && \ | ||
go generate -mod=vendor -v ./... && \ | ||
git ls-files -m --others -- **/*.pb.go | tar -cf - --files-from - | tar -C /generated-files -xf - | ||
FROM base AS tools | ||
RUN --mount=type=bind,target=.,rw \ | ||
--mount=type=cache,target=/root/.cache \ | ||
--mount=type=cache,target=/go/pkg/mod \ | ||
go install \ | ||
github.com/gogo/protobuf/protoc-gen-gogo \ | ||
github.com/gogo/protobuf/protoc-gen-gogofaster \ | ||
github.com/gogo/protobuf/protoc-gen-gogoslick && \ | ||
# FIXME: Should be inferred from go.mod (1.5.2 atm) | ||
go install \ | ||
github.com/golang/protobuf/[email protected] | ||
|
||
FROM tools AS generated | ||
RUN --mount=type=bind,target=.,rw <<EOT | ||
set -ex | ||
go generate -mod=vendor -v ./... | ||
mkdir /out | ||
git ls-files -m --others -- ':!vendor' '**/*.pb.go' | tar -cf - --files-from - | tar -C /out -xf - | ||
EOT | ||
|
||
FROM scratch AS update | ||
COPY --from=generated /generated-files /generated-files | ||
|
||
FROM gobuild-base AS validate | ||
RUN --mount=target=/tmp/src \ | ||
cp -r /tmp/src/. . && \ | ||
go generate -mod=vendor -v ./... && git diff && ./hack/validate-generated-files check | ||
COPY --from=generated /out / | ||
|
||
FROM base AS validate | ||
RUN --mount=type=bind,target=.,rw \ | ||
--mount=type=bind,from=generated,source=/out,target=/generated-files <<EOT | ||
set -e | ||
git add -A | ||
if [ "$(ls -A /generated-files)" ]; then | ||
cp -rf /generated-files/* . | ||
fi | ||
diff=$(git status --porcelain -- ':!vendor' '**/*.pb.go') | ||
if [ -n "$diff" ]; then | ||
echo >&2 'ERROR: The result of "go generate" differs. Please update with "make generated-files"' | ||
echo "$diff" | ||
exit 1 | ||
fi | ||
EOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
. $(dirname $0)/util | ||
set -eu | ||
|
||
case ${1:-} in | ||
'') | ||
. $(dirname $0)/util | ||
gogo_version=$(awk '$1 == "github.com/gogo/protobuf" { print $2 }' go.mod) | ||
buildxCmd build \ | ||
--target validate \ | ||
--build-arg "GOGO_VERSION=$gogo_version" \ | ||
--file ./hack/dockerfiles/generated-files.Dockerfile \ | ||
. | ||
;; | ||
check) | ||
diffs="$(git status --porcelain -- **/*.pb.go 2>/dev/null)" | ||
set +x | ||
if [ "$diffs" ]; then | ||
{ | ||
echo 'The result of "go generate" differs' | ||
echo | ||
echo "$diffs" | ||
echo | ||
echo 'Please update with "make generated-files"' | ||
echo | ||
} >&2 | ||
exit 1 | ||
fi | ||
echo 'Congratulations! All auto generated files are correct.' | ||
;; | ||
esac | ||
buildxCmd build \ | ||
--target "validate" \ | ||
--output "type=cacheonly" \ | ||
--file "./hack/dockerfiles/generated-files.Dockerfile" \ | ||
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//go:build tools | ||
// +build tools | ||
|
||
// Package tools tracks dependencies on binaries not referenced in this codebase. | ||
// https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module | ||
// Disclaimer: Avoid adding tools that don't need to be inferred from go.mod | ||
// like golangci-lint and check they don't import too many dependencies. | ||
package tools | ||
|
||
import ( | ||
_ "github.com/gogo/protobuf/protoc-gen-gogo" | ||
_ "github.com/gogo/protobuf/protoc-gen-gogofaster" | ||
_ "github.com/gogo/protobuf/protoc-gen-gogoslick" | ||
_ "github.com/golang/protobuf/protoc-gen-go" | ||
) |
Oops, something went wrong.