Skip to content

Commit

Permalink
feat(plugins): Introduce roadrunner plugin (#238)
Browse files Browse the repository at this point in the history
* feat(plugins): Introduce roadrunner plugin

* Fix roadrunner tests

* Update READMEs

* Fix documentation and use env var time and rr version

* Increase waiting time webgo & skipper

* Update deps

* Bump to v1.6.17

* Last fixes

* Add @fredliang44 in the credits section for his help
  • Loading branch information
darkweak authored Jul 25, 2022
1 parent 2209f91 commit 033229a
Show file tree
Hide file tree
Showing 38 changed files with 3,849 additions and 74 deletions.
81 changes: 78 additions & 3 deletions .github/workflows/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ jobs:
-
name: Build Souin as Beego plugin
run: make build-and-run-beego
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
-
name: Wait for Souin is really loaded inside Beego as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -107,6 +109,8 @@ jobs:
-
name: Build Souin as Chi plugin
run: make build-and-run-chi
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
-
name: Wait for Souin is really loaded inside Chi as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -152,6 +156,8 @@ jobs:
-
name: Build Souin as Dotweb plugin
run: make build-and-run-dotweb
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
-
name: Wait for Souin is really loaded inside Dotweb as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -197,6 +203,8 @@ jobs:
-
name: Build Souin as Echo plugin
run: make build-and-run-echo
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
-
name: Wait for Souin is really loaded inside Echo as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -242,6 +250,8 @@ jobs:
-
name: Build Souin as Fiber plugin
run: make build-and-run-fiber
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
-
name: Wait for Souin is really loaded inside Fiber as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -287,6 +297,8 @@ jobs:
-
name: Build Souin as Gin plugin
run: make build-and-run-gin
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
-
name: Wait for Souin is really loaded inside Gin as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -332,6 +344,8 @@ jobs:
-
name: Build Souin as Go-zero plugin
run: make build-and-run-go-zero
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
-
name: Wait for Souin is really loaded inside Go-zero as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -377,6 +391,8 @@ jobs:
-
name: Build Souin as Goyave plugin
run: make build-and-run-goyave
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
-
name: Wait for Souin is really loaded inside Goyave as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -422,6 +438,8 @@ jobs:
-
name: Build Souin as Kratos plugin
run: make build-and-run-kratos
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
-
name: Wait for Souin is really loaded inside Kratos as middleware
uses: jakejarvis/wait-action@master
Expand All @@ -445,6 +463,53 @@ jobs:
folder: Kratos
reporters: cli
delayRequest: 5000
build-roadrunner-validator:
name: Check that Souin build as Roadrunner middleware
runs-on: ubuntu-latest
steps:
-
name: Add domain.com host to /etc/hosts
run: |
sudo echo "127.0.0.1 domain.com" | sudo tee -a /etc/hosts
-
name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.18
-
name: Checkout code
uses: actions/checkout@v2
-
name: Run Roadrunner tests
run: cd plugins/roadrunner && go test -v .
-
name: Build Souin as Roadrunner plugin
run: make build-and-run-roadrunner
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
-
name: Wait for Souin is really loaded inside Roadrunner as middleware
uses: jakejarvis/wait-action@master
with:
time: 10s
-
name: Set Roadrunner logs configuration result as environment variable
run: cd plugins/roadrunner && echo "$(make load-checker)" >> $GITHUB_ENV
-
name: Check if the configuration is loaded to define if Souin is loaded too
uses: nick-invision/assert-action@v1
with:
expected: '"Souin configuration is now loaded."'
actual: ${{ env.MIDDLEWARE_RESULT }}
comparison: contains
-
name: Run Roadrunner E2E tests
uses: anthonyvscode/newman-action@v1
with:
collection: "docs/e2e/Souin E2E.postman_collection.json"
folder: Roadrunner
reporters: cli
delayRequest: 5000
build-skipper-validator:
name: Check that Souin build as Skipper middleware
runs-on: ubuntu-latest
Expand All @@ -467,11 +532,13 @@ jobs:
-
name: Build Souin as Skipper plugin
run: make build-and-run-skipper
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
-
name: Wait for Souin is really loaded inside Skipper as middleware
uses: jakejarvis/wait-action@master
with:
time: 60s
time: 65s
-
name: Set Skipper logs configuration result as environment variable
run: cd plugins/skipper && echo "$(make load-checker)" >> $GITHUB_ENV
Expand Down Expand Up @@ -512,6 +579,8 @@ jobs:
-
name: Build Souin as Souin plugin
run: make build-and-run-souin
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
-
name: Wait for Souin is really loaded inside Souin as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -557,11 +626,13 @@ jobs:
-
name: Build Souin as Traefik plugin
run: make build-and-run-traefik
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
-
name: Wait for Souin is really loaded inside Traefik as middleware
uses: jakejarvis/wait-action@master
with:
time: 30s
time: 20s
-
name: Set Traefik logs configuration result as environment variable
run: cd plugins/traefik && echo "$(make load-checker)" >> $GITHUB_ENV
Expand Down Expand Up @@ -602,6 +673,8 @@ jobs:
-
name: Build Souin as Tyk plugin
run: make build-and-run-tyk
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
-
name: Wait for Souin is really loaded inside Tyk as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -647,11 +720,13 @@ jobs:
-
name: Build Souin as Webgo plugin
run: make build-and-run-webgo
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
-
name: Wait for Souin is really loaded inside Webgo as middleware
uses: jakejarvis/wait-action@master
with:
time: 30s
time: 35s
-
name: Set Webgo logs configuration result as environment variable
run: cd plugins/webgo && echo "$(make load-checker)" >> $GITHUB_ENV
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/workflow_plugins_generator.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

plugins=("beego" "chi" "dotweb" "echo" "fiber" "gin" "go-zero" "goyave" "kratos" "skipper" "souin" "traefik" "tyk" "webgo")
durations=("35" "30" "30" "30" "45" "40" "50" "40" "50" "60" "40" "30" "30" "30")
versions=("16" "16" "16" "16" "16" "16" "16" "16" "18" "18" "16" "16" "16" "16")
plugins=("beego" "chi" "dotweb" "echo" "fiber" "gin" "go-zero" "goyave" "kratos" "roadrunner" "skipper" "souin" "traefik" "tyk" "webgo")
durations=("35" "30" "30" "30" "45" "40" "50" "40" "50" "10" "65" "40" "20" "30" "35")
versions=("16" "16" "16" "16" "16" "16" "16" "16" "18" "18" "18" "16" "16" "16" "16")

IFS= read -r -d '' tpl <<EOF
name: Build and validate Souin as plugins
Expand Down Expand Up @@ -76,6 +76,8 @@ for i in ${!plugins[@]}; do
-
name: Build Souin as $capitalized plugin
run: make build-and-run-$lower
env:
GH_APP_TOKEN: \${{ secrets.GH_APP_TOKEN }}
-
name: Wait for Souin is really loaded inside $capitalized as middleware
uses: jakejarvis/wait-action@master
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
DC=docker-compose
DC_BUILD=$(DC) build
DC_EXEC=$(DC) exec
PLUGINS_LIST=beego caddy chi dotweb echo fiber gin go-zero goyave kratos skipper traefik tyk webgo souin
PLUGINS_LIST=beego caddy chi dotweb echo fiber gin go-zero goyave kratos roadrunner skipper traefik tyk webgo souin

base-build-and-run-%:
cd plugins/$* && $(MAKE) prepare
Expand All @@ -31,6 +31,8 @@ build-and-run-fiber: base-build-and-run-fiber ## Run Fiber with Souin as plugin

build-and-run-kratos: base-build-and-run-kratos ## Run Kratos with Souin as plugin

build-and-run-roadrunner: base-build-and-run-roadrunner ## Run Roadrunner with Souin as plugin

build-and-run-skipper: base-build-and-run-skipper ## Run Skipper with Souin as plugin

build-and-run-souin: base-build-and-run-souin ## Run Souin as plugin
Expand Down
87 changes: 80 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
8.8. [Go-zero middleware](#go-zero-middleware)
8.9. [Goyave middleware](#goyave-middleware)
8.10. [Kratos filter](#kratos-filter)
8.11. [Skipper filter](#skipper-filter)
8.12. [Træfik plugin](#træfik-plugin)
8.13. [Tyk plugin](#tyk-plugin)
8.14. [Webgo middleware](#webgo-middleware)
8.15. [Prestashop plugin](#prestashop-plugin)
8.16. [Wordpress plugin](#wordpress-plugin)
8.11. [Roadrunner middleware](#roadrunner-middleware)
8.12. [Skipper filter](#skipper-filter)
8.13. [Træfik plugin](#træfik-plugin)
8.14. [Tyk plugin](#tyk-plugin)
8.15. [Webgo middleware](#webgo-middleware)
8.16. [Prestashop plugin](#prestashop-plugin)
8.17. [Wordpress plugin](#wordpress-plugin)
9. [Credits](#credits)

# Souin HTTP cache
Expand Down Expand Up @@ -787,6 +788,77 @@ func main() {
}
```

### Roadrunner middleware
To use Souin as roadrunner middleware, you have to build your `rr` binary with the souin dependency.
```toml
[velox]
build_args = ['-trimpath', '-ldflags', '-s -X github.com/roadrunner-server/roadrunner/v2/internal/meta.version=${VERSION} -X github.com/roadrunner-server/roadrunner/v2/internal/meta.buildTime=${TIME}']
[roadrunner]
ref = "master"
[github]
[github.token]
token = "GH_TOKEN"
[github.plugins]
logger = { ref = "master", owner = "roadrunner-server", repository = "logger" }
cache = { ref = "master", owner = "darkweak", repository = "souin/plugins/roadrunner" }
# others ...
[log]
level = "debug"
mode = "development"
```

After that, you'll be able to set each Souin configuration key under the `http.cache` key.
```yaml
# .rr.yaml
http:
# Other http sub keys
cache:
api:
basepath: /httpcache_api
prometheus:
basepath: /anything-for-prometheus-metrics
souin: {}
default_cache:
allowed_http_verbs:
- GET
- POST
- HEAD
cdn:
api_key: XXXX
dynamic: true
hostname: XXXX
network: XXXX
provider: fastly
strategy: soft
headers:
- Authorization
regex:
exclude: '/excluded'
ttl: 5s
stale: 10s
log_level: debug
ykeys:
The_First_Test:
headers:
Content-Type: '.+'
The_Second_Test:
url: 'the/second/.+'
surrogate_keys:
The_First_Test:
headers:
Content-Type: '.+'
The_Second_Test:
url: 'the/second/.+'
middleware:
- cache
# Other middlewares
```


### Skipper filter
To use Souin as skipper filter, you can refer to the [Skipper plugin integration folder](https://github.com/darkweak/souin/tree/master/plugins/skipper) to discover how to configure it.
You just have to add to your Skipper instance the Souin filter like below:
Expand Down Expand Up @@ -824,7 +896,7 @@ experimental:
plugins:
souin:
moduleName: github.com/darkweak/souin
version: v1.6.16
version: v1.6.17
```
After that you can declare either the whole configuration at once in the middleware block or by service. See the examples below.
```yaml
Expand Down Expand Up @@ -1014,3 +1086,4 @@ Thanks to these users for contributing or helping this project in any way
* [Duy Nguyen](https://github.com/duy-nguyen-devops)
* [Kiss Karoly](https://github.com/kresike)
* [Matthias von Bargen](https://github.com/mattvb91)
* [Fred Liang](https://github.com/fredliang44)
Loading

0 comments on commit 033229a

Please sign in to comment.