spiral-modules / php-grpc

:electric_plug: Fast and furious GRPC server for PHP applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hello-world docker example

greggdonovan opened this issue · comments

I'd love a hello-world docker example for php-grpc. I've been able to get php-grpc working outside of Docker, but inside of Docker I'm running into:

ERRO[0000] [grpc]: [grpc]: unable to connect to worker: invalid data found in the buffer (possible echo): signal: killed

Even a simple example that showed how to make sure php-grpc is configured correctly, has all of the dependencies it needs, etc. would be great. Thanks!

Hi,

check the troubleshooting part of this article:
https://roadrunner.dev/docs/php-worker

@wolfy-j Thank you! That did the trick. Running php worker.php from inside of the Docker container allowed me to see the bug in my configuration. Much appreciated.

The Dockerfile I ended up using is:

FROM spiralscout/roadrunner:2.1.1 as rr

FROM php:7.4.18-fpm-buster

RUN apt-get update && apt-get install -y \
  vim \
  libzip-dev \
  unzip \
  && rm -rf /var/lib/apt/lists/*

# Install PHP Extensions
RUN docker-php-ext-install zip \
  && docker-php-ext-install sockets \
  && docker-php-ext-install opcache \
  && docker-php-ext-enable opcache

# Copy Composer
COPY --from=composer /usr/bin/composer /usr/bin/composer

# Copy RoadRunner
COPY --from=rr /usr/bin/rr /usr/bin/rr

# Copy RoadRunner config
COPY --from=rr /etc/rr.yaml /etc/rr.yaml

RUN mkdir /tmp/rr-grpc-install && cd /tmp/rr-grpc-install && curl -sL https://github.com/spiral/php-grpc/releases/download/v1.5.0/rr-grpc-1.5.0-linux-amd64.tar.gz | tar -xzv && cp /tmp/rr-grpc-install/rr-grpc-1.5.0-linux-amd64/rr-grpc /usr/bin && rm -rf /tmp/rr-grpc-install

WORKDIR /app/

COPY service.proto ./
COPY .rr.yaml ./
COPY worker.php ./
COPY src src/
COPY vendor vendor/

EXPOSE 2112
EXPOSE 6001
EXPOSE 6061
EXPOSE 50055

ENTRYPOINT ["/usr/bin/rr-grpc", "serve", "--verbose", "-d"]

Let me know if that would be a useful example to have and I'd be happy to open a PR.