github.com/pdmccormick/importable-docker-buildx@v0.0.0-20240426161518-e47091289030/hack/dockerfiles/generated-files.Dockerfile (about)

     1  # syntax=docker/dockerfile:1
     2  
     3  # Forked from https://github.com/moby/buildkit/blob/e1b3b6c4abf7684f13e6391e5f7bc9210752687a/hack/dockerfiles/generated-files.Dockerfile
     4  # Copyright The BuildKit Authors.
     5  # Copyright The Buildx Authors.
     6  # Licensed under the Apache License, Version 2.0
     7  
     8  ARG GO_VERSION="1.21"
     9  ARG PROTOC_VERSION="3.11.4"
    10  
    11  # protoc is dynamically linked to glibc so can't use alpine base
    12  FROM golang:${GO_VERSION}-bookworm AS base
    13  RUN apt-get update && apt-get --no-install-recommends install -y git unzip
    14  ARG PROTOC_VERSION
    15  ARG TARGETOS
    16  ARG TARGETARCH
    17  RUN <<EOT
    18    set -e
    19    arch=$(echo $TARGETARCH | sed -e s/amd64/x86_64/ -e s/arm64/aarch_64/)
    20    wget -q https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-${TARGETOS}-${arch}.zip
    21    unzip protoc-${PROTOC_VERSION}-${TARGETOS}-${arch}.zip -d /usr/local
    22  EOT
    23  WORKDIR /go/src/github.com/docker/buildx
    24  
    25  FROM base AS tools
    26  RUN --mount=type=bind,target=.,rw \
    27      --mount=type=cache,target=/root/.cache \
    28      --mount=type=cache,target=/go/pkg/mod \
    29      go install \
    30        github.com/gogo/protobuf/protoc-gen-gogo \
    31        github.com/gogo/protobuf/protoc-gen-gogofaster \
    32        github.com/gogo/protobuf/protoc-gen-gogoslick \
    33        github.com/golang/protobuf/protoc-gen-go
    34  
    35  FROM tools AS generated
    36  RUN --mount=type=bind,target=.,rw <<EOT
    37    set -ex
    38    go generate -mod=vendor -v ./...
    39    mkdir /out
    40    git ls-files -m --others -- ':!vendor' '**/*.pb.go' | tar -cf - --files-from - | tar -C /out -xf -
    41  EOT
    42  
    43  FROM scratch AS update
    44  COPY --from=generated /out /
    45  
    46  FROM base AS validate
    47  RUN --mount=type=bind,target=.,rw \
    48      --mount=type=bind,from=generated,source=/out,target=/generated-files <<EOT
    49    set -e
    50    git add -A
    51    if [ "$(ls -A /generated-files)" ]; then
    52      cp -rf /generated-files/* .
    53    fi
    54    diff=$(git status --porcelain -- ':!vendor' '**/*.pb.go')
    55    if [ -n "$diff" ]; then
    56      echo >&2 'ERROR: The result of "go generate" differs. Please update with "make generated-files"'
    57      echo "$diff"
    58      exit 1
    59    fi
    60  EOT