summaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
Diffstat (limited to 'dev')
-rw-r--r--dev/.rr-docker.yaml33
-rw-r--r--dev/Dockerfile.local39
-rw-r--r--dev/Makefile2
-rw-r--r--dev/README.md39
-rw-r--r--dev/composer.json19
-rw-r--r--dev/docker-compose.yml25
-rw-r--r--dev/psr-worker.php28
7 files changed, 185 insertions, 0 deletions
diff --git a/dev/.rr-docker.yaml b/dev/.rr-docker.yaml
new file mode 100644
index 00000000..c84179bf
--- /dev/null
+++ b/dev/.rr-docker.yaml
@@ -0,0 +1,33 @@
+rpc:
+ listen: tcp://0.0.0.0:6001
+
+server:
+ command: "php /etc/psr-worker.php"
+
+
+http:
+ address: 0.0.0.0:15395
+ max_request_size: 1024
+ middleware: [ "websockets" ]
+ uploads:
+ forbid: [ ".php", ".exe", ".bat" ]
+ trusted_subnets: [ "10.0.0.0/8", "127.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "::1/128", "fc00::/7", "fe80::/10" ]
+ pool:
+ num_workers: 1
+
+redis:
+ addrs:
+ - "redis:6379"
+
+websockets:
+ pubsubs: [ "memory" ]
+ path: "/ws"
+
+logs:
+ mode: production
+ level: error
+
+endure:
+ grace_period: 10s
+ print_graph: false
+ log_level: panic
diff --git a/dev/Dockerfile.local b/dev/Dockerfile.local
new file mode 100644
index 00000000..f990b3ee
--- /dev/null
+++ b/dev/Dockerfile.local
@@ -0,0 +1,39 @@
+# Image page: <https://hub.docker.com/_/golang>
+FROM --platform=${TARGETPLATFORM:-linux/amd64} golang:alpine as builder
+
+# app version and build date must be passed during image building (version without any prefix).
+# e.g.: `docker build --build-arg "APP_VERSION=1.2.3" --build-arg "BUILD_TIME=$(date +%FT%T%z)" .`
+ARG APP_VERSION="undefined"
+ARG BUILD_TIME="undefined"
+
+COPY . /src
+
+# Image page: <https://hub.docker.com/_/alpine>
+# https://alpinelinux.org/posts/Alpine-3.13.4-released.html
+# Critical issue with 3.13.3 https://nvd.nist.gov/vuln/detail/CVE-2021-28831
+FROM --platform=${TARGETPLATFORM:-linux/amd64} php:latest
+
+# use same build arguments for image labels
+ARG APP_VERSION="undefined"
+ARG BUILD_TIME="undefined"
+
+# copy required files from builder image
+COPY --from=builder /src/rr /usr/bin/rr
+COPY --from=builder /src/.rr-docker.yaml /etc/rr-docker.yaml
+COPY --from=builder /src/composer.json /etc/composer.json
+COPY --from=builder /src/psr-worker.php /etc/psr-worker.php
+
+WORKDIR /etc
+
+RUN docker-php-ext-install sockets
+
+RUN apt update -y
+RUN apt upgrade -y
+RUN apt install git zip unzip -y
+
+RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
+
+RUN composer install
+
+# use roadrunner binary as image entrypoint
+ENTRYPOINT ["/usr/bin/rr"]
diff --git a/dev/Makefile b/dev/Makefile
new file mode 100644
index 00000000..71c0ed5b
--- /dev/null
+++ b/dev/Makefile
@@ -0,0 +1,2 @@
+build:
+ CGO_ENABLED=0 go build -trimpath -ldflags "-s" -o rr ../cmd/rr/main.go
diff --git a/dev/README.md b/dev/README.md
new file mode 100644
index 00000000..0d055321
--- /dev/null
+++ b/dev/README.md
@@ -0,0 +1,39 @@
+# Local testing/development files
+
+### Usage:
+1. Build the RR binary with the following command: `make build`. As the result you'll see a RR binary.
+2. If you are testing you own plugin (Go), you may use `replace` directive in the root `go.mod` file, for example:
+```go
+module github.com/spiral/roadrunner-binary/v2
+
+go 1.17
+
+require (
+ github.com/buger/goterm v1.0.1
+ github.com/dustin/go-humanize v1.0.0
+ github.com/fatih/color v1.12.0
+ github.com/joho/godotenv v1.3.0
+ github.com/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d
+ github.com/mattn/go-runewidth v0.0.13
+ github.com/olekukonko/tablewriter v0.0.5
+ github.com/spf13/cobra v1.2.1
+ // SPIRAL ------------
+ github.com/spiral/endure v1.0.3
+ github.com/spiral/errors v1.0.12
+ github.com/spiral/goridge/v3 v3.2.1
+ github.com/spiral/roadrunner/v2 v2.4.0-rc.1
+ // ---------------------
+ github.com/stretchr/testify v1.7.0
+ // SPIRAL --------------
+ github.com/temporalio/roadrunner-temporal v1.0.9-beta.1
+ // ---------------------
+ github.com/vbauerster/mpb/v5 v5.4.0
+)
+
+replace github.com/spiral/roadrunner/v2 => ../roadrunner <----- SAMPLE
+```
+
+3. Replace sample worker `psr-worker.php` with your application. You can do that by putting all `dev` env into the folder
+with your app and replacing lines 21-24 of the `Dockerfile.local` with your app OR by replacing the sample worker. Also, do not forget to update `.rr-docker.yaml`.
+
+5. Next step is to build docker-compose: `docker-compose up`, that's it. After that, you'll have your app running in local dev env with RR.
diff --git a/dev/composer.json b/dev/composer.json
new file mode 100644
index 00000000..50178d1f
--- /dev/null
+++ b/dev/composer.json
@@ -0,0 +1,19 @@
+{
+ "minimum-stability": "beta",
+ "prefer-stable": true,
+ "require": {
+ "nyholm/psr7": "^1.3",
+ "spiral/roadrunner": "^2.0",
+ "spiral/roadrunner-http": "^2.0",
+ "temporal/sdk": ">=1.0",
+ "spiral/tokenizer": ">=2.7",
+ "spiral/roadrunner-metrics": "^2.0"
+ },
+ "autoload": {
+ "psr-4": {
+ "Temporal\\Tests\\": "src"
+ }
+ },
+ "name": "test/test",
+ "description": "test"
+}
diff --git a/dev/docker-compose.yml b/dev/docker-compose.yml
new file mode 100644
index 00000000..673f7cd5
--- /dev/null
+++ b/dev/docker-compose.yml
@@ -0,0 +1,25 @@
+version: '3.7'
+
+services:
+ redis:
+ image: redis:6
+
+ roadrunner:
+ container_name: roadrunner
+ environment:
+ - GOGC=100
+ ulimits:
+ nofile:
+ soft: 65000
+ hard: 65000
+ mem_limit: 1024
+ cpus: 1
+ restart: always
+ build:
+ context: .
+ dockerfile: Dockerfile.local
+ command: "serve -c /etc/rr-docker.yaml -d"
+ ports:
+ - "15395:15395"
+ - "6061:6061"
+ - "6001:6001"
diff --git a/dev/psr-worker.php b/dev/psr-worker.php
new file mode 100644
index 00000000..fd8d672f
--- /dev/null
+++ b/dev/psr-worker.php
@@ -0,0 +1,28 @@
+<?php
+/**
+ * @var Goridge\RelayInterface $relay
+ */
+use Spiral\Goridge;
+use Spiral\RoadRunner;
+
+ini_set('display_errors', 'stderr');
+require __DIR__ . "/vendor/autoload.php";
+
+$worker = new RoadRunner\Worker(new Goridge\StreamRelay(STDIN, STDOUT));
+$psr7 = new RoadRunner\Http\PSR7Worker(
+ $worker,
+ new \Nyholm\Psr7\Factory\Psr17Factory(),
+ new \Nyholm\Psr7\Factory\Psr17Factory(),
+ new \Nyholm\Psr7\Factory\Psr17Factory()
+);
+
+while ($req = $psr7->waitRequest()) {
+ try {
+ $resp = new \Nyholm\Psr7\Response();
+ $resp->getBody()->write("hellllo world!!!!!");
+
+ $psr7->respond($resp);
+ } catch (\Throwable $e) {
+ $psr7->getWorker()->error((string)$e);
+ }
+}