Skip to content

SafeBike/docker-protoc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

docker-protoc

Based on https://github.com/haunt98/docker-protoc

Run protoc with docker.

What's included:

Supported language

  • Go

Install

From Docker Hub

docker pull safebike/protoc

Or with the makefile

make build IMAGE=image TAG=tag

Example

make example

This will generate gRPC code of hello/hello.proto with protoc and regenerate the hello/hello.pb.go and hello/hello_grpc.pb.go files, which contain:

  • Code for populating, serializing, and retrieving HelloRequest and HelloReply message types.
  • Generated client and server code.

Usage

/home/docker/app is mount point in docker container, because user is docker not root.

/home/docker/.local/include, /home/docker/.local/include/third_party/googleapis is where to store imported proto files.

Need to replace /path/to/output, /path/to/proto with your path.

Need to replace image, tag with your docker image, tag.

Lint

With buf:

Should include buf.yaml file.

docker run --rm --volume $(pwd):/home/docker/app --workdir /home/docker/app image:tag \
    protoc \
        -I /home/docker/.local/include \
        -I /home/docker/.local/include/third_party/googleapis \
        -I . \
        --buf-check-lint_out . \
        /path/to/proto

Build

docker run --rm --volume $(pwd):/home/docker/app --workdir /home/docker/app image:tag \
    protoc \
        -I /home/docker/.local/include \
        -I /home/docker/.local/include/third_party/googleapis \
        -I . \
        --go_out /path/to/output \
        --go-grpc_out /path/to/output \
        /path/to/proto

With grpc-gateway:

docker run --rm --volume $(pwd):/home/docker/app --workdir /home/docker/app image:tag \
    protoc \
        -I /home/docker/.local/include \
        -I /home/docker/.local/include/third_party/googleapis \
        -I . \
        --go_out /path/to/output \
        --go-grpc_out /path/to/output \
        --grpc-gateway_out /path/to/output \
        --grpc-gateway_opt logtostderr=true \
        --swagger_out /path/to/output \
        --swagger_out logtostderr=true \
        /path/to/proto

Format

Should include .clang-format file.

docker run --rm --volume $(pwd):/home/docker/app --workdir /home/docker/app image:tag \
    clang-format -i \
        /path/to/proto