consul-templaterb 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/.gitreview +5 -0
- data/.rspec +2 -0
- data/.rubocop.yml +43 -0
- data/.ruby_app +0 -0
- data/.travis.yml +13 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +201 -0
- data/README.md +270 -0
- data/Rakefile +6 -0
- data/bin/consul-templaterb +246 -0
- data/consul-templaterb.gemspec +37 -0
- data/lib/consul/async/consul_endpoint.rb +279 -0
- data/lib/consul/async/consul_template.rb +323 -0
- data/lib/consul/async/consul_template_engine.rb +57 -0
- data/lib/consul/async/consul_template_render.rb +80 -0
- data/lib/consul/async/process_handler.rb +64 -0
- data/lib/consul/async/utilities.rb +17 -0
- data/lib/consul/async/version.rb +5 -0
- data/samples/checks.html.erb +96 -0
- data/samples/common/footer.html.erb +10 -0
- data/samples/common/header.html.erb +51 -0
- data/samples/consul_template.html.erb +94 -0
- data/samples/consul_template.json.erb +77 -0
- data/samples/consul_template.txt.erb +45 -0
- data/samples/consul_template.xml.erb +70 -0
- data/samples/criteo/haproxy.cfg.erb +163 -0
- data/samples/criteo_choregraphies.html.erb +91 -0
- data/samples/ha_proxy.cfg.erb +127 -0
- data/samples/keys.html.erb +38 -0
- data/samples/nodes.html.erb +17 -0
- data/samples/services.html.erb +89 -0
- metadata +189 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c3c5dba956cece1ad77f8eb4edaee447c86bbade6442adb8b1a1dc21577a62ae
|
4
|
+
data.tar.gz: 8b0e94328289d7529074b608da3284d7fc9ec97d51167d90ad92b817e6582bc3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7e0e3f61b3cfac004babf0aba88cd36eedb5bba31dc029ed014eb0c1c5d5e92c4a9eb17be31dc9ade62a1ca23269ea1cc69e593e8d55041a62386e2041963d81
|
7
|
+
data.tar.gz: c4bd56c30874d36f7aaefe4b4abd488fae373a1b7275252a3208424ff47b2770c9666654f3254d4652429c8a3c9c1f1775ed0ca16721de6a167f50a3563b2a6a
|
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
/samples/*.json
|
11
|
+
/samples/*.xml
|
12
|
+
/samples/*.html
|
13
|
+
/samples/*.txt
|
14
|
+
/samples/*.cfg
|
15
|
+
/samples/criteo/haproxy.cfg
|
16
|
+
/samples/consul_template
|
17
|
+
/samples/find_blocked_choregraphies
|
18
|
+
/spec/consul/async/resources/templates/*.txt
|
19
|
+
/spec/consul/async/resources/templates/*.result
|
20
|
+
/out.txt
|
21
|
+
|
22
|
+
# rspec failure tracking
|
23
|
+
.rspec_status
|
24
|
+
# Max OS
|
25
|
+
.DS_Store
|
data/.gitreview
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- bundle/**/*
|
4
|
+
TargetRubyVersion: 2.4
|
5
|
+
|
6
|
+
Metrics/AbcSize:
|
7
|
+
Max: 80
|
8
|
+
|
9
|
+
Metrics/BlockLength:
|
10
|
+
Max: 120
|
11
|
+
|
12
|
+
Metrics/BlockNesting:
|
13
|
+
Max: 4
|
14
|
+
|
15
|
+
Metrics/ClassLength:
|
16
|
+
Max: 160
|
17
|
+
|
18
|
+
Metrics/CyclomaticComplexity:
|
19
|
+
Max: 15
|
20
|
+
|
21
|
+
Metrics/LineLength:
|
22
|
+
Max: 150
|
23
|
+
|
24
|
+
Metrics/MethodLength:
|
25
|
+
Max: 50
|
26
|
+
|
27
|
+
Metrics/ParameterLists:
|
28
|
+
Max: 12
|
29
|
+
|
30
|
+
Metrics/PerceivedComplexity:
|
31
|
+
Max: 18
|
32
|
+
|
33
|
+
Style/Documentation:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
Style/FrozenStringLiteralComment:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
Style/MultilineBlockChain:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
Style/VariableNumber:
|
43
|
+
Enabled: false
|
data/.ruby_app
ADDED
File without changes
|
data/.travis.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.3
|
4
|
+
deploy:
|
5
|
+
provider: rubygems
|
6
|
+
api_key:
|
7
|
+
secure: l78H6Ow9HCeEz0hcAP2XCXaGGBNRXZ/QLFPNzwyNmHToko9WqZj6mbiNIcVwZ8aCcZEzFmtcB7m1lC1l+mvot3Snfh4OUErK7EXMLiNxUWybtA4qJqmsb2J8JGS69pTohPKagi1YyRbyVs2tJpM5OVazcNxEQDAVkWVxJuPVz6tsn4rXZsL77nTSVyB6YGKgguRGhtS/3M0ufk1ymOpuk8pxXKaotlYGRXmht2OHW+FDQczTMgqu6jiZubjWlNHVxtYn+CsLYNj1BswzD6fF1uous6nchV0if2QW5N4OJVyZCx3yEQ0RswfI8G1kG/Jm8wd2lSknY2wpnd1qkRnAcFlKBpUv8aQd6SdbSO84GTAOvucgK7Mcf0LRvYSE2FyagaAPFSfMybWd+GS26g5AuRPpkhtsS9ijfdIzpudiF18pvnJ+wQj+hWM/THWowYNyKv9NeckxdrULaHPisA346r5eM/EADOhyEUtPm11PFgcheGjff1H4qXGc9gcm50u6mNNHkWv38oGhAPpRk/bU7qybTKqRKNGWGP0MiT4WVIFXp62/JMY7AmufOdJx5Ca5JVsaWoN4fsS9r3+R+FxvRtV9NOrRJVKKaQhzi4UHEUDQ2hQjpLDijD5L0vUsl6arl+nufTt5G5jp9QvdY7fhYT1mpGgWj0hTBd8Pxsl3N8U=
|
8
|
+
gem: consul-templaterb
|
9
|
+
edge:
|
10
|
+
branch: v1.8.47
|
11
|
+
on:
|
12
|
+
tags: true
|
13
|
+
repo: criteo/consul-templaterb
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,270 @@
|
|
1
|
+
# Consul::Templaterb
|
2
|
+
|
3
|
+
This GEM is both a library and an executable that allows to generate files
|
4
|
+
using data from Consul (Discovery and Key/Value Store) easily using ruby's
|
5
|
+
erb templates. It also support launching programs and babysitting processes
|
6
|
+
when rendering the files, thus notifying programs when data do change.
|
7
|
+
|
8
|
+
It is intended for user accustomed to expressiveness or Ruby templating (ERB),
|
9
|
+
allowing for more flexibility and than Go Templating.
|
10
|
+
|
11
|
+
It also allow to use all of ruby language, especially usefull for generating
|
12
|
+
files in several formats (JSON, XML) where text substitutions are hard to get
|
13
|
+
right.
|
14
|
+
|
15
|
+
It also focuses on good performance and lightweight usage of bandwidth,
|
16
|
+
especially for very large clusters and watching lots of services.
|
17
|
+
|
18
|
+
For complicated rendering of templates and large Consul Clusters, it usually
|
19
|
+
render faster with a more predictible way the template than the original
|
20
|
+
consul-template.
|
21
|
+
|
22
|
+
## Differences with HashiCorp's consul-template
|
23
|
+
|
24
|
+
[Hashicorp's Consul Template](https://github.com/hashicorp/consul-template)
|
25
|
+
inspired strongly the creation of this GEM and this executable wants
|
26
|
+
to achieve better results in some use cases, especially for very large
|
27
|
+
Consul clusters with many nodes and servers.
|
28
|
+
|
29
|
+
consul-template has more features regarding Consul support (for instance, it
|
30
|
+
has support for Hashicorp's Vault), but consul-templaterb focuses on getting
|
31
|
+
more power with the generation of templates and more performance.
|
32
|
+
|
33
|
+
Consul Template uses Go templates which is very limited in its set of
|
34
|
+
features is quite limited: it is complicated to sort, apply real transformations
|
35
|
+
using code and even interact with the OS (ex: get the current date, format
|
36
|
+
timestamps...).
|
37
|
+
|
38
|
+
The sort feature for instances allow you to create predictible output (i.e: meaning
|
39
|
+
that the order of nodes is predictible), thus it might offer better performance
|
40
|
+
since the reload of processes if happening ONLY when the files are binary
|
41
|
+
different. Thus, if using consul-templaterb, you will reload less your haproxy or
|
42
|
+
load-balancer than you would do with consul-template.
|
43
|
+
|
44
|
+
Compared to consul-template, consul-templaterb offers the following features:
|
45
|
+
|
46
|
+
* Hot-Reload of template files
|
47
|
+
* Bandwith limitation per endpoint (will soon support dynamic bandwith limiter)
|
48
|
+
* Supports baby sitting of multiple processes
|
49
|
+
* Supports all Ruby features (ex: base64, real JSON/XML generation...)
|
50
|
+
* Information about bandwidth
|
51
|
+
|
52
|
+
The executable supports close semantics to Consul template, it also supports
|
53
|
+
commands when files are modified and babysitting of multiple processes with
|
54
|
+
ability to send signals to those processes whenever the files do change.
|
55
|
+
|
56
|
+
## Installation
|
57
|
+
|
58
|
+
You might either use the executable direcly OR use this GEM as a library by
|
59
|
+
adding this line to your application's Gemfile:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
gem 'consul-templaterb'
|
63
|
+
```
|
64
|
+
|
65
|
+
And then execute:
|
66
|
+
|
67
|
+
```shell
|
68
|
+
$ bundle
|
69
|
+
[...]
|
70
|
+
```
|
71
|
+
|
72
|
+
Or install it yourself as:
|
73
|
+
|
74
|
+
```shell
|
75
|
+
$ gem install consul-templaterb
|
76
|
+
[...]
|
77
|
+
```
|
78
|
+
|
79
|
+
## Usage of consul-templaterb
|
80
|
+
|
81
|
+
### Show help
|
82
|
+
|
83
|
+
```shell
|
84
|
+
$ consul-templaterb --help
|
85
|
+
USAGE: bin/consul-templaterb [[options]]
|
86
|
+
-h, --help Show help
|
87
|
+
-v, --version Show Version
|
88
|
+
-c, --consul-addr=<address> Address of Consul, eg: http://locahost:8500
|
89
|
+
--consul-token=<token> Use a token to connect to Consul
|
90
|
+
-w, --wait=<min_duration> Wait at least n seconds before each template generation
|
91
|
+
-r, --retry-delay=<min_duration> Min Retry delay on Error/Missing Consul Index
|
92
|
+
-k, --hot-reload=<behavior> Control hot reload behaviour, one of :[die (kill daemon on hot reload failure), keep (on error, keep running), disable (hot reload disabled)]
|
93
|
+
-K, --sig-term=kill_signal Signal to sent to next --exec command on kill, default=#{cur_sig_term}
|
94
|
+
-R, --sig-reload=reload_signal Signal to sent to next --exec command on reload (NONE supported), default=#{cur_sig_reload}
|
95
|
+
-e, --exec=<command> Execute the following command
|
96
|
+
-d, --debug-network-usage Debug the network usage
|
97
|
+
-t erb_file:[output]:[command], Add a erb template, its output and optional reload command
|
98
|
+
--template
|
99
|
+
--once Do not run the process as a daemon
|
100
|
+
```
|
101
|
+
|
102
|
+
### Generate multiple templates
|
103
|
+
|
104
|
+
In the same way as consul-template, consul-templaterb supports multiple templates and executing
|
105
|
+
commands when the files do change. The parameter `--template <ERB>:<DEST>:[reload_command]` works
|
106
|
+
in the following way:
|
107
|
+
|
108
|
+
* ERB : the ERB file to use as a template
|
109
|
+
* DEST: the destination file
|
110
|
+
* reload_command: optional shell command executed whenever the file has been modified
|
111
|
+
|
112
|
+
The argument can be specified multiple times, ex:
|
113
|
+
|
114
|
+
Example of usage:
|
115
|
+
|
116
|
+
```shell
|
117
|
+
$ consul-templaterb \\
|
118
|
+
--template "samples/ha_proxy.cfg.erb:/opt/haproxy/etc/haproxy.cfg:sudo service haproxy reload"
|
119
|
+
--template "samples/consul_template.erb:consul-summary.txt"
|
120
|
+
```
|
121
|
+
|
122
|
+
### Process management and signalisation of configuration files
|
123
|
+
|
124
|
+
With the --exec argument (can be specified multiple times), consul-templaterb will launch
|
125
|
+
the process specified when all templates have been generated and will send a reload signal
|
126
|
+
if the content of any of the files do change (the signal will be sent atomically however,
|
127
|
+
meaning that if 2 results of templates are modified at the same time, the signal will be
|
128
|
+
sent only once (it is helpful for instance if your app is using several configurations
|
129
|
+
files that must be consistent all together).
|
130
|
+
|
131
|
+
Signals can be customized per process. Two signals are supported with options --sig-reload and
|
132
|
+
--sig-term. When the option is added, the next --exec options to start a process will use the
|
133
|
+
given signal. By default, HUP will be sent to reload events (you can use NONE to avoid sending any
|
134
|
+
reload signal), TERM will be used when leaving consul-templaterb.
|
135
|
+
|
136
|
+
### Bandwidth limitation
|
137
|
+
|
138
|
+
This is actually the original reason for the creation of this GEM: on Criteo's large clusters,
|
139
|
+
consul-template generated several hundreds of Mb/s to the Consul-Agent which also
|
140
|
+
generated several hundreds of Mb/s with the Consul servers.
|
141
|
+
|
142
|
+
By design, the GEM supports limiting the number of requests per endpoints (see code in
|
143
|
+
`bin/consul-templaterb` file). It avoids using too much network to fetch data from Consul
|
144
|
+
in large Consul Clusters (especially when watching lots of files).
|
145
|
+
|
146
|
+
The limitation is currently static, but fair dynamic bandwidth allocation will allow to limit
|
147
|
+
the bandwidth used to get information for all services by capping the global bandwidth used
|
148
|
+
by consul-templaterb.
|
149
|
+
|
150
|
+
### Samples
|
151
|
+
|
152
|
+
Have a look into the [samples/](samples/) directory to browse example files.
|
153
|
+
|
154
|
+
If you want to test it quickly, you might try with (assuming you consul agent is listening on
|
155
|
+
http://localhost:8500):
|
156
|
+
|
157
|
+
```
|
158
|
+
$ be bin/consul-templaterb -c 'http://localhost:8500' samples/*.html.erb
|
159
|
+
```
|
160
|
+
|
161
|
+
It will generate a full website in samples/ directory with lots of Consul information ready to
|
162
|
+
use (website updated automagically when values to change).
|
163
|
+
|
164
|
+
## Template development
|
165
|
+
|
166
|
+
Here are the various functions you might use in your templates.
|
167
|
+
|
168
|
+
For each function, mandatory arguments are specified at the begining while optional ones are marked with `[]`.
|
169
|
+
Most of them support the optional dc attribute to access data from another datacenter. If the `dc`
|
170
|
+
attribute is not specified, the function will output data from the current datacenter.
|
171
|
+
|
172
|
+
To ease template development, `consul-templaterb` supports HOT reload of templates, thus it is possible to
|
173
|
+
develop the templates interactivelly. While developping, it is possible to use the switch `--hot-reload=keep`,
|
174
|
+
thus the application will display a warning if the template is invalid and won't stop
|
175
|
+
(`--hot-reload=die` is the default, thus if the hot-reloaded template has issue, the application will die).
|
176
|
+
|
177
|
+
### datacenters()
|
178
|
+
|
179
|
+
[Get the list of datacenters as string array](https://www.consul.io/api/catalog.html#list-datacenters).
|
180
|
+
|
181
|
+
### services([dc: datacenter], [tag: tagToFilterWith])
|
182
|
+
|
183
|
+
[List the services matching the optional tag filter](https://www.consul.io/api/catalog.html#list-services),
|
184
|
+
if tag is not specified, will match all the services. Note that this endpoint performs client side tag
|
185
|
+
filtering for services to ease templates development since this feature is not available on Consul's endpoint.
|
186
|
+
|
187
|
+
### service(serviceName, [dc: datacenter], [tag: tagToFilterWith], [passing: true])
|
188
|
+
|
189
|
+
[List the instances](https://www.consul.io/api/health.html#list-nodes-for-service) of a service having the given
|
190
|
+
optional tag. If no tag is specified, will return all instances of service. By default, it will return all the
|
191
|
+
well services that are passing or not. An optional argument passing might be used to retrieve only passing instances.
|
192
|
+
|
193
|
+
### nodes([dc: datacenter])
|
194
|
+
|
195
|
+
[List all the nodes of selected datacenter](https://www.consul.io/api/catalog.html#list-nodes). No filtering is
|
196
|
+
applied.
|
197
|
+
|
198
|
+
### node(nodeNameOrId, [dc: datacenter])
|
199
|
+
|
200
|
+
[List all the services of a given Node](https://www.consul.io/api/catalog.html#list-services-for-node) using its
|
201
|
+
name or its ID. If DC is specified, will lookup for given node in another datacenter.
|
202
|
+
|
203
|
+
### checks_for_service(name, dc: nil, passing: false, tag: nil)
|
204
|
+
|
205
|
+
[Find all the checks](https://www.consul.io/api/health.html#list-checks-for-service) of a given service.
|
206
|
+
|
207
|
+
### kv(name = nil, dc: nil, keys: nil, recurse: false)
|
208
|
+
|
209
|
+
[Read keys from KV Store](https://www.consul.io/api/kv.html#read-key). It can be used for both listing the keys and
|
210
|
+
getting the values. See the file in samples [keys.html.erb](samples/keys.html.erb) for a working example.
|
211
|
+
|
212
|
+
### agent_metrics()
|
213
|
+
|
214
|
+
[Get the metrics of Consul Agent](https://www.consul.io/api/agent.html#view-metrics). Since this endpoint does
|
215
|
+
not support blocking queries, data will be refreshed every few seconds, but will not use blocking queries
|
216
|
+
mechanism.
|
217
|
+
|
218
|
+
### agent_self()
|
219
|
+
|
220
|
+
[Get the configuration of Consul Agent](https://www.consul.io/api/agent.html#read-configuration). Since this
|
221
|
+
endpoint does not support blocking queries, data will be refreshed every few seconds, but will not use blocking
|
222
|
+
queries mechanism.
|
223
|
+
|
224
|
+
### render_file RELATIVE_PATH_TO_ERB_FILE
|
225
|
+
|
226
|
+
This allow to include a template file into another one. Beware, it does not check for infinite recursion!
|
227
|
+
The template can be either a static file either another template. The file has to be a valid template, but
|
228
|
+
can also be raw text (if it is a valid template.
|
229
|
+
|
230
|
+
Example:
|
231
|
+
|
232
|
+
```erb
|
233
|
+
<%= render_file 'header.html.erb' %>
|
234
|
+
```
|
235
|
+
|
236
|
+
## Development
|
237
|
+
|
238
|
+
We recommend using bundle using `bundle install`, you can now run `bundle exec bin/consul-templaterb`.
|
239
|
+
|
240
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
241
|
+
version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
|
242
|
+
push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
243
|
+
|
244
|
+
## Known bugs
|
245
|
+
|
246
|
+
Here are the known bugs of the application:
|
247
|
+
|
248
|
+
* [ ] On Mac OS X, with many services, consul-templaterb sometimes crashes when watching lots of changes (more than 2k
|
249
|
+
watches) at the same time. This bug is a race condition, probably in `em-http-request`. Only visible on very large
|
250
|
+
clusters.
|
251
|
+
* [ ] render_file might create an infinite recusion if a template includes itself indirectly.
|
252
|
+
|
253
|
+
## TODO
|
254
|
+
|
255
|
+
* [ ] Hashi's Vault support
|
256
|
+
* [ ] Implement automatic dynamic rate limit
|
257
|
+
* [ ] More samples: apache, nginx, full website displaying consul information...
|
258
|
+
* [ ] Optimize rendering speed at startup: an iteration is done very second by default, but it would be possible to speed
|
259
|
+
up rendering by iterating with higher frequency until the first write of result has been performed.
|
260
|
+
* [ ] Allow to tune bandwith using a simple config file (while it should not be necessary for 90% of use-cases)
|
261
|
+
|
262
|
+
## Contributing
|
263
|
+
|
264
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/criteo/consul-templaterb.
|
265
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
|
266
|
+
[Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
267
|
+
|
268
|
+
## License
|
269
|
+
|
270
|
+
The gem is available as open source under the terms of the Apache v2 license. See LICENSE.txt file.
|