protoc-gen-validate icon indicating copy to clipboard operation
protoc-gen-validate copied to clipboard

Buf.build plugin

Open george-oakling opened this issue 3 years ago • 6 comments

Hi!

This protoc plugin already has already schema on buf.build: https://buf.build/envoyproxy/protoc-gen-validate, but it only has proto definitions included, so I made also a plugin, which can be used remotely - https://buf.build/jirkad/plugins/protoc-gen-validate

It would be fine to have this plugin in the official buf.build repo also as it makes generating code using remote plugins super easy :)

Usage:

...
plugins:
  - remote: buf.build/jirkad/plugins/protoc-gen-validate:v0.6.1
    out: pkg/proto
    opt:
      - lang=go
      - paths=source_relative

Dockerfile:

FROM golang as builder
ENV GOOS=linux GOARCH=amd64 CGO_ENABLED=0
RUN go install github.com/envoyproxy/[email protected]

FROM scratch
COPY --from=builder /go/bin/protoc-gen-validate /protoc-gen-validate
ENTRYPOINT [ "/protoc-gen-validate" ]

george-oakling avatar Sep 29 '21 07:09 george-oakling

  • buf.yaml
version: v1
name: buf.build/envoyproxy/protoc-gen-validate
build:
  excludes:
    - example-workspace
    - java
    - tests
lint:
  use:
    - DEFAULT
breaking:
  use:
    - FILE
  • buf.work.yaml
version: v1
directories:
  - .
  • buf.gen.yaml
version: v1
managed:
  enabled: true
  go_package_prefix:
    default: github.com/envoyproxy/protoc-gen-validate
plugins:
  - remote: buf.build/library/plugins/go:v1.27.1-1
    out: .
    opt:
      - paths=source_relative
buf push --tag v0.6.3
  • Dockerfile.buf
FROM golang as builder

ENV GOOS=linux GOARCH=amd64 CGO_ENABLED=0

RUN go install -v github.com/envoyproxy/[email protected]

FROM scratch

LABEL "build.buf.plugins.runtime_library_versions.0.name"="github.com/envoyproxy/protoc-gen-validate"
LABEL "build.buf.plugins.runtime_library_versions.0.version"="v0.6.3"

COPY --from=builder /go/bin/protoc-gen-validate /protoc-gen-validate

ENTRYPOINT ["/protoc-gen-validate"]
# docker login -u anonymous plugins.buf.build
docker build --platform linux/amd64 --force-rm --compress -f Dockerfile.buf -t plugins.buf.build/envoyproxy/protoc-gen-validate:v0.6.3-1 .

starudream avatar Jan 26 '22 07:01 starudream

Just a friendly comment to revive this issue :smile: I've tested @george-oakling 's plugin and it indeed works like a charm.

To the maintainers, here is more context regarding buf.build remote plugin execution : https://buf.build/blog/remote-plugin-execution

This would be an awesome addition to the proto sources already distributed on the BSR.

vallahaye avatar Mar 11 '22 17:03 vallahaye

Hi guys, just letting you know my unofficial plugin is now available at v0.6.7 tag - https://buf.build/jirkad/plugins/protoc-gen-validate

Enjoy :) and hopefully one day we will have an official release :)

george-oakling avatar Apr 04 '22 18:04 george-oakling

@george-oakling thanks so much ❤️

levanlongktmt avatar Apr 25 '22 08:04 levanlongktmt

I desparately want an official release

debkanchan avatar May 20 '22 05:05 debkanchan

Really cool work @george-oakling. I hope they accept this plugin. If anyone else is getting started with this stuff (Buf + protoc-gen-validate), I have an example PR.

kevinmichaelchen avatar May 28 '22 03:05 kevinmichaelchen

Would like to see official plugin!

ysomad avatar Oct 12 '22 20:10 ysomad

So the strange thing is that the plugins are available in the GH repository. Though they're not published on the BSR 🤔

Just made this issue in the plugins GH repository to ask whether this is intentional. I used the official GH repository to publish the most recent version of protoc-gen-validate, if anyone needs it, it can be found here: https://buf.build/strmprivacy/plugins/protoc-gen-validate

Did the following steps to create this plugin:

  1. Cloned https://github.com/bufbuild/plugins/
  2. cd plugins/bufbuild/validate-java/v0.6.13
  3. buf beta registry plugin create buf.build/strmprivacy/plugins/protoc-gen-validate --visibility public
  4. docker buildx build --platform linux/amd64 --push -t plugins.buf.build/strmprivacy/protoc-gen-validate:v0.6.13-1 . (as I'm using an M1 Mac)

trietsch avatar Nov 07 '22 10:11 trietsch

Just updating that PGV can be used as a remote plugin with newer buf CLI (>v1.9.0): ref.

In light of the above development, this issue can probably be closed.

furqanmk avatar Feb 22 '23 22:02 furqanmk