Skip to content

Commit

Permalink
feat(route-provisioner): increased client body size and added nginx s…
Browse files Browse the repository at this point in the history
…nippet annotations

Signed-off-by: Ben Meier <[email protected]>
  • Loading branch information
astromechza committed May 16, 2024
1 parent 37de302 commit 8d1ba21
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
9 changes: 8 additions & 1 deletion examples/09-dns-and-route/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ This adds an additional nginx service to the compose file which contains an HTTP

By default, this listens on http://localhost:8080 and in the example will route paths like `/my/fizz/path`, `/my/buzz/path/thing`. The port 8080 unfortunately cannot be changed without modifying the provisioner in the default provisioners file after running `score-compose init`.

By default, this uses a `Prefix` route matching type so `/` can match `/any/request/path` but you can add a `score-compose.score.dev/route-provisioner-path-type: Exact` annotation to a Route to restrict this behavior to just an exact match.
By default, this uses a `Prefix` route matching type so `/` can match `/any/request/path` but you can add a `compose.score.dev/route-provisioner-path-type: Exact` annotation to a Route to restrict this behavior to just an exact match.

When running this compose project, we can test these routes using curl (in this instance the generated dns name was `dnsmntq6e`):

Expand All @@ -51,6 +51,13 @@ $ curl http://dnsmntq6e.localhost:8080/my/buzz/path/
buzz
```

## Adjusting Nginx configuration

The default `route` provisioner generates an nginx config file. If you need to adjust any of the settings or send particular headers, you can use the following snippet annotations.

- `compose.score.dev/route-provisioner-server-snippet` - indents and then adds the lines in the "server" block of nginx.
- `compose.score.dev/route-provisioner-location-snippet` - indents and then adds the lines to every "block" block of nginx.

## Fixed DNS names

If you want a fixed DNS name, you can add a new DNS provisioner to your `.score-compose/0-custom-provisioners.yaml` file:
Expand Down
11 changes: 8 additions & 3 deletions internal/command/default.provisioners.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@
{{ if not $ports }}{{ fail "no service ports exist" }}{{ end }}
{{ $port := index $ports (print .Params.port) }}
{{ if not $port.TargetPort }}{{ fail "params.port is not a named service port" }}{{ end }}
shared: |
{{ .Init.sk }}:
instancePort: {{ dig .Init.sk "instancePort" 8080 .Shared }}
Expand All @@ -414,7 +415,7 @@
{{ $target := (printf "%s:%d" $targetHost $targetPort) }}
{{ $hBefore := dig .Init.sk "hosts" (dict) .Shared }}
{{ $rBefore := dig .Params.host (dict) $hBefore }}
{{ $pathType := dig "score-compose.score.dev/route-provisioner-path-type" "Prefix" (dig "annotations" (dict) (.Metadata | default (dict))) }}
{{ $pathType := dig "compose.score.dev/route-provisioner-path-type" "Prefix" (dig "annotations" (dict) (.Metadata | default (dict))) }}
{{ $inner := dict "path" .Params.path "target" $target "port" $targetPort "path_type" $pathType }}
{{ $rAfter := (merge $rBefore (dict .Uid $inner)) }}
{{ $hAfter := (merge $hBefore (dict .Params.host $rAfter)) }}
Expand Down Expand Up @@ -444,7 +445,9 @@
proxy_read_timeout 60s;
proxy_buffers 16 4k;
proxy_buffer_size 2k;
client_max_body_size 10m;
{{ dig "compose.score.dev/route-provisioner-server-snippet" "" (dig "annotations" (dict) (.Metadata | default (dict))) | indent 4 }}
location = /favicon.ico {
return 204;
access_log off;
Expand All @@ -456,13 +459,15 @@
location ~ ^{{ index $v "path" }}$ {
set $backend {{ index $v "target" }};
proxy_pass http://$backend;
{{ dig "compose.score.dev/route-provisioner-location-snippet" "" (dig "annotations" (dict) (.Metadata | default (dict))) | indent 6 }}
}
# The prefix match variants are included by default but can be excluded via 'score-compose.score.dev/route-provisioner-path-type' annotation
# The prefix match variants are included by default but can be excluded via 'compose.score.dev/route-provisioner-path-type' annotation
{{ if eq (index $v "path_type") "Prefix" }}
location ~ ^{{ index $v "path" | trimSuffix "/" }}/.* {
set $backend {{ index $v "target" }};
proxy_pass http://$backend;
{{ dig "compose.score.dev/route-provisioner-location-snippet" "" (dig "annotations" (dict) (.Metadata | default (dict))) | indent 6 }}
}
{{ end }}
{{ end }}
Expand Down
2 changes: 1 addition & 1 deletion internal/command/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ resources:
type: route
metadata:
annotations:
score-compose.score.dev/route-provisioner-path-type: Exact
compose.score.dev/route-provisioner-path-type: Exact
params:
host: localhost2
path: /third
Expand Down

0 comments on commit 8d1ba21

Please sign in to comment.