1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

php用のgRPCソースを生成するDockerfile

Last updated at Posted at 2020-07-28

gRPCのプラグインをbrew等で入れることができなかったので、Dockerコマンド化しました.

ディレクトリ構成

├── Dockerfile
├── protos/
│   └── sample.proto
└── gen/
  • protos: protoファイルを置いておくディレクトリ
  • gen: 生成されたコードが配置されるディレクトリ

Dockerfile

FROM php:7.2.32-cli

WORKDIR /tmp
RUN apt-get update -y && apt-get install -y wget zip git automake zlib1g-dev libtool

# install protoc command
# releases: https://github.com/protocolbuffers/protobuf/releases
ENV proto_version 3.12.3
RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v${proto_version}/protoc-${proto_version}-linux-x86_64.zip \
    && unzip -d protoc protoc-${proto_version}-linux-x86_64.zip \
    && mv protoc/bin/* /usr/local/bin/ \
    && mv protoc/include/* /usr/local/include/

# install grpc php plugin
# releases: https://github.com/grpc/grpc/releases
ENV grpc_version v1.30.2
WORKDIR /var/local
RUN git clone -b ${grpc_version} https://github.com/grpc/grpc --depth=1
WORKDIR /var/local/grpc
RUN git submodule update --init \
    && make grpc_php_plugin \
    && cp -p ./bins/opt/grpc_php_plugin /usr/local/bin/

WORKDIR /var/local
RUN mkdir protos \
    && mkdir gen

ENTRYPOINT ["protoc", "--proto_path=/var/local/protos", "--php_out=/var/local/gen", "--grpc_out=/var/local/gen", "--plugin=protoc-gen-grpc=/usr/local/bin/grpc_php_plugin"]
CMD ["hello.proto"]

コード生成コマンド

  1. コンテナの中にボリュームマウントでprotoファイルを埋め込む
  2. コンテナ内でソースが生成される
  3. コンテナ内に生成されたファイルをボリュームマウントでローカルにコピーする

の流れです。

$ docker build -t grpc-php-gen -f docker/grpc-php-gen/Dockerfile .
$ docker run --rm -v $(PWD)/protos:/var/local/protos -v $(PWD)/gen:/var/local/gen grpc-php-gen sample.proto
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?