Fix proto gen

This commit is contained in:
CrazyMax
2022-11-20 16:58:31 +01:00
parent 19c4a7d1f4
commit 0dd85a21a9
3 changed files with 24 additions and 26 deletions

View File

@@ -2,25 +2,18 @@
ARG GO_VERSION="1.19" ARG GO_VERSION="1.19"
ARG PROTOC_VERSION="3.17.3" ARG PROTOC_VERSION="3.17.3"
ARG GLIBC_VERSION="2.33-r0"
FROM golang:${GO_VERSION}-alpine AS base # protoc is dynamically linked to glibc so can't use alpine base
ARG GLIBC_VERSION FROM golang:${GO_VERSION}-bullseye AS base
RUN apk add --no-cache curl file git unzip RUN apt-get update && apt-get --no-install-recommends install -y git unzip
RUN <<EOT
set -e
curl -sSL "https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub" -o "/etc/apk/keys/sgerrand.rsa.pub"
curl -sSL "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk" -o "glibc.apk"
apk add glibc.apk
rm /etc/apk/keys/sgerrand.rsa.pub glibc.apk
EOT
ARG PROTOC_VERSION ARG PROTOC_VERSION
ARG TARGETOS
ARG TARGETARCH
RUN <<EOT RUN <<EOT
set -e set -e
curl -sSL "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip" -o "protoc.zip" arch=$(echo $TARGETARCH | sed -e s/amd64/x86_64/ -e s/arm64/aarch_64/)
unzip "protoc.zip" -d "/usr/local" wget -q https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-${TARGETOS}-${arch}.zip
protoc --version unzip protoc-${PROTOC_VERSION}-${TARGETOS}-${arch}.zip -d /usr/local
rm "protoc.zip"
EOT EOT
WORKDIR /src WORKDIR /src
@@ -30,15 +23,17 @@ RUN --mount=type=cache,target=/go/pkg/mod \
go mod download go mod download
FROM vendored AS tools FROM vendored AS tools
RUN --mount=type=bind,target=.,rw \ RUN --mount=type=bind,target=. \
--mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/go/pkg/mod \
go install -v $(sed -n -e 's|^\s*_\s*"\(.*\)".*$|\1| p' tools.go) go install \
google.golang.org/grpc/cmd/protoc-gen-go-grpc \
google.golang.org/protobuf/cmd/protoc-gen-go
FROM tools AS generate FROM tools AS generate
RUN --mount=type=bind,target=.,rw \ RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/go/pkg/mod <<EOT --mount=type=cache,target=/go/pkg/mod <<EOT
set -e set -e
go generate ./... go generate -v ./...
mkdir /out mkdir /out
cp -Rf pb /out cp -Rf pb /out
EOT EOT

View File

@@ -1,8 +0,0 @@
// +build tools
package tools
import (
_ "google.golang.org/grpc/cmd/protoc-gen-go-grpc"
_ "google.golang.org/protobuf/cmd/protoc-gen-go"
)

11
tools/tools.go Normal file
View File

@@ -0,0 +1,11 @@
//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
package tools
import (
_ "google.golang.org/grpc/cmd/protoc-gen-go-grpc"
_ "google.golang.org/protobuf/cmd/protoc-gen-go"
)