Skip to content

feat(streams): add support for nginx streams #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions nginx/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ include:
{%- if nginx.snippets is defined %}
- nginx.snippets
{%- endif %}
{%- if nginx.streams is defined %}
- nginx.streams
{%- endif %}
- nginx.servers
- nginx.certificates

Expand Down
14 changes: 14 additions & 0 deletions nginx/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'server_available': '/etc/nginx/sites-available',
'server_enabled': '/etc/nginx/sites-enabled',
'snippets_dir': '/etc/nginx/snippets',
'streams_dir': '/etc/nginx/streams',
'server_use_symlink': True,
'pid_file': '/run/nginx.pid',
'openssl_package': 'openssl',
Expand All @@ -32,6 +33,7 @@
'server_available': '/etc/nginx/conf.d',
'server_enabled': '/etc/nginx/conf.d',
'snippets_dir': '/etc/nginx/snippets',
'streams_dir': '/etc/nginx/streams',
'server_use_symlink': False,
'pid_file': '/run/nginx.pid',
'rh_os_releasever': '$releasever',
Expand All @@ -49,6 +51,7 @@
'server_available': '/etc/nginx/conf.d',
'server_enabled': '/etc/nginx/conf.d',
'snippets_dir': '/etc/nginx/snippets',
'streams_dir': '/etc/nginx/streams',
'server_use_symlink': False,
'pid_file': '/run/nginx.pid',
'rh_os_releasever': '$releasever',
Expand All @@ -69,6 +72,7 @@
'server_available': '/etc/nginx/vhosts.d',
'server_enabled': '/etc/nginx/vhosts.d',
'snippets_dir': '/etc/nginx/snippets',
'streams_dir': '/etc/nginx/streams',
'server_use_symlink': False,
'pid_file': '/run/nginx.pid',
'gpg_check': True,
Expand All @@ -84,6 +88,7 @@
'server_available': '/etc/nginx/sites-available',
'server_enabled': '/etc/nginx/sites-enabled',
'snippets_dir': '/etc/nginx/snippets',
'streams_dir': '/etc/nginx/streams',
'server_use_symlink': True,
'openssl_package': 'openssl',
},
Expand All @@ -95,6 +100,7 @@
'server_available': '/etc/nginx/sites-available',
'server_enabled': '/etc/nginx/sites-enabled',
'snippets_dir': '/etc/nginx/snippets',
'streams_dir': '/etc/nginx/streams',
'server_use_symlink': True,
'openssl_package': 'dev-libs/openssl',
},
Expand All @@ -107,6 +113,7 @@
'server_available': '/usr/local/etc/nginx/sites-available',
'server_enabled': '/usr/local/etc/nginx/sites-enabled',
'snippets_dir': '/usr/local/etc/nginx/snippets',
'streams_dir': '/usr/local/etc/nginx/streams',
'server_use_symlink': True,
'openssl_package': 'openssl',
'pid_file': '/var/run/nginx.pid',
Expand Down Expand Up @@ -140,6 +147,9 @@
'events': {
'worker_connections': 512,
},
'stream' : {
'include': '/etc/nginx/streams/*',
},
'http': {
'sendfile': 'on',
'tcp_nopush': 'on',
Expand Down Expand Up @@ -204,3 +214,7 @@
}) %}
{% endif %}
{% endif %}

{% if salt['grains.get']('os_family') == 'FreeBSD' %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a whitespace after the closing bracket, that tests are showing. Can you remove it?

{% do nginx.server.config.stream.update({'include' : nginx.lookup.streams_dir ~ '/*'}) %}
{% endif %}
3 changes: 3 additions & 0 deletions nginx/passenger.sls
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ include:
{%- if nginx.snippets is defined %}
- nginx.snippets
{%- endif %}
{%- if nginx.streams is defined %}
- nginx.streams
{%- endif %}
- nginx.servers
- nginx.certificates

Expand Down
22 changes: 0 additions & 22 deletions nginx/pkg.sls
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,6 @@ nginx_official_repo:
- watch_in:
- pkg: nginx_install

{%- if grains.os not in ('Debian',) %}
## applies to Ubuntu and derivatives only #}
nginx_ppa_repo:
pkgrepo:
{%- if from_ppa %}
- managed
{%- else %}
- absent
{%- endif %}
{% if grains.os == 'Ubuntu' %}
- ppa: nginx/{{ nginx.ppa_version }}
{% else %}
- name: deb http://ppa.launchpad.net/nginx/{{ nginx.ppa_version }}/ubuntu {{ grains.oscodename }} main
- keyid: C300EE8C
- keyserver: keyserver.ubuntu.com
{% endif %}
- require_in:
- pkg: nginx_install
- watch_in:
- pkg: nginx_install
{%- endif %}

{%- if from_phusionpassenger %}
nginx_phusionpassenger_repo_keyring:
file.managed:
Expand Down
1 change: 1 addition & 0 deletions nginx/servers_config.sls
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{% set server_states = [] %}
{#- _nginx is a lightened copy of nginx map intended to passed in templates #}
{%- set _nginx = nginx.copy() %}
{%- do _nginx.pop('streams') if nginx.streams is defined %}
{%- do _nginx.pop('snippets') if nginx.snippets is defined %}
{%- do _nginx.pop('servers') if nginx.servers is defined %}

Expand Down
33 changes: 33 additions & 0 deletions nginx/streams.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# nginx.streams
#
# Manages creation of streams

{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ '/map.jinja' import nginx, sls_block with context %}
{%- from tplroot ~ '/libtofs.jinja' import files_switch with context %}

{#- _nginx is a lightened copy of nginx map intended to passed in templates #}
{%- set _nginx = nginx.copy() %}

{%- do _nginx.pop('streams') if nginx.snippets is defined %}
{%- do _nginx.pop('servers') if nginx.servers is defined %}


nginx_streams_dir:
file.directory:
{{ sls_block(nginx.servers.dir_opts) }}
- name: {{ nginx.lookup.streams_dir }}

{% for stream, config in nginx.streams.items() %}
nginx_streams_{{ stream }}:
file.managed:
- name: {{ nginx.lookup.streams_dir ~ '/' ~ stream }}
- source: {{ files_switch([ stream, 'server.conf' ],
'nginx_stream_file_managed'
)
}}
- template: jinja
- context:
config: {{ config|json() }}
nginx: {{ _nginx|json() }}
{% endfor %}
11 changes: 10 additions & 1 deletion pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,16 @@ nginx:
- upstream netdata:
- server: 127.0.0.1:19999
- keepalive: 64


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are whitespaces after the closing bracket, that tests are showing. Can you remove them?

streams:
example_stream:
- upstream some_upstream:
- server: '10.0.0.1:8000'
- server: '10.0.0.2:8000'
- server:
- listen: 7000
- proxy_pass: some_upstream

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are whitespaces after the closing bracket, that tests are showing. Can you remove them?

server:
# this partially exposes file.managed parameters as they relate to the main
# nginx.conf file
Expand Down