Last active
January 12, 2019 16:34
-
-
Save SC7639/a396bc63c5672020a0e6c1c283b57ed7 to your computer and use it in GitHub Desktop.
PHP gRPC example Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM alpine as build | |
ADD https://github.com/spiral/php-grpc/releases/download/v1.0.0/rr-grpc-1.0.0-linux-amd64.tar.gz /rr-grpc/ | |
ADD https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip /proto/ | |
ADD https://github.com/spiral/php-grpc/releases/download/v1.0.0/protoc-gen-php-grpc-1.0.0-linux-amd64.tar.gz /protoc-php-grpc/ | |
# Extract and copy protoc binary to /usr/local | |
RUN unzip /proto/protoc-3.6.1-linux-x86_64.zip -d /proto/ | |
# Extract rr-grpc | |
RUN tar -xvzf /rr-grpc/rr-grpc-1.0.0-linux-amd64.tar.gz -C /rr-grpc/ | |
# Extract rr-grpc | |
RUN tar -xvzf /protoc-php-grpc/protoc-gen-php-grpc-1.0.0-linux-amd64.tar.gz -C /protoc-php-grpc/ | |
RUN ls -al /protoc-php-grpc/ | |
FROM php:7.2-fpm | |
# Copy rr-grpc and protoc binary to /usr/local/bin | |
COPY --from=build /rr-grpc/rr-grpc-1.0.0-linux-amd64/rr-grpc /usr/local/bin/ | |
COPY --from=build /proto/bin/protoc /usr/local/bin/ | |
COPY --from=build /proto/include/ /usr/local/include/ | |
COPY --from=build /protoc-php-grpc/protoc-gen-php-grpc-1.0.0-linux-amd64/protoc-gen-php-grpc /usr/local/bin/ | |
ADD run.sh /root/run.sh | |
WORKDIR /app/server | |
# Build protobuf file and start grpc server | |
CMD ["/root/run.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Run grpc server | |
if [ "$ENV" = "production" ] | |
then | |
rr-grpc serve | |
else | |
# Build protobuf file | |
protoc --php_out=src --php-grpc_out=src service.proto | |
rr-grpc serve -v -d | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment