Skip to content

Commit

Permalink
Filter containers on label
Browse files Browse the repository at this point in the history
  • Loading branch information
adi90x committed Feb 28, 2018
1 parent 21dfa26 commit 93fa9f0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Last Change ###

28/02/17 : v0.9.4 - Add a way to specify which services should be publish by RAP
28/02/17 : v0.9.3 - Add Let's Encrypt Bypass to enable standalone LE to work behind RAP.
26/01/17 : v0.9.2 - Avoid error if Let's Encrypt conf is empty on startup.
26/01/17 : v0.9.1 - Create Let's Encrypt folder on build.
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Provided your DNS is setup to forward foo.bar.com to the a host running rancher-
| `rap.https_listen_ports` | External Port you want Rancher-Active-Proxy to listen https for this server ( Default : `443` )
| `rap.server_tokens` | Enable to specify the server_token value per container
| `rap.client_max_body_size` | Enable to specify the client_max_body_size directive per container
| `rap.rap_name` | If RAP_NAME is specified for a RAP instance only container with label value matching RAP_NAME value will be publish

#### Summary of environment variable available for Rancher Active Proxy.

Expand All @@ -63,6 +64,7 @@ Provided your DNS is setup to forward foo.bar.com to the a host running rancher-
| `RAP_DEBUG` | Define Rancher-Gen-Rap verbosity (Valid values: "debug", "info", "warn", and "error"). Default: `info`
| `DEFAULT_PORT` | Default port use for containers ( Default : 80 )
| `SPECIFIC_HOST` | Limit RAP to only containers of a specific host name
| `RAP_NAME` | If specify RAP will only publish service with `rap.rap_name = RAP_NAME`

#### Quick Summary of interesting volume to mount.

Expand Down Expand Up @@ -203,6 +205,10 @@ If you would like to use the same configuration for multiple virtual host names,
If you want most of your virtual hosts to use a default single `server` block configuration and then override on a few specific ones, add a `/etc/nginx/vhost.d/default_server` file.
This file will be used on any virtual host which does not have a `/etc/nginx/vhost.d/{rap.host}_server` file associated with it.

### Limit RAP to some containers

If you want an RAP instance to only publish some specific containers/service, you can start the RAP container with environment variable `RAP_NAME = example`
In that situation, all containers to be publish by this instance of RAP should have a label `rap.rap_name = example`

***

Expand Down
5 changes: 3 additions & 2 deletions app/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ server {

{{- $default_port := or (env "DEFAULT_PORT") "80" }}
{{- $host_filter := or (env "SPECIFIC_HOST") "*" }}
{{- $rap_name := or (env "RAP_NAME") "*" }}

# Rancher Services config

Expand All @@ -311,7 +312,7 @@ server {

{{range $service := $services}}
{{- $addrLen := len $service.Ports }}
{{- range $cont := $service.Containers | filterHost $host_filter }}
{{- range $cont := $service.Containers | filterHost $host_filter | filterLabel "rap.rap_name" $rap_name}}
{{- $online := (and (or (eq .Health "") (eq .Health "healthy")) (eq .State "running")) -}}
{{- if ne $destPort ""}}
{{- template "upstream" (dict "HOST" $host "FIRST" $alive "IP" $cont.Address "ONLINE" $online "PORT" $destPort) }}
Expand Down Expand Up @@ -342,7 +343,7 @@ server {
# Standalone containers config

{{ if or (eq $host_filter "*") (eq host.Name $host_filter) }}
{{- range $opt, $conts := host.Containers | groupByMultiFilter "" "rap.host" ","}}
{{- range $opt, $conts := host.Containers | filterLabel "rap.rap_name" $rap_name | groupByMultiFilter "" "rap.host" ","}}
{{- $parts := split $opt "=>"}}
{{- $host := first $parts | trim }}
{{- $dest := last $parts | trim }}
Expand Down

0 comments on commit 93fa9f0

Please sign in to comment.