consul-templaterb 1.18.1 → 1.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -1
- data/Dockerfile +15 -0
- data/README.md +7 -0
- data/TemplateAPI.md +12 -1
- data/docker-nginx-conf/nginx.conf +27 -0
- data/lib/consul/async/consul_template.rb +2 -2
- data/lib/consul/async/json_endpoint.rb +18 -3
- data/lib/consul/async/version.rb +1 -1
- data/samples/consul-ui/README.md +7 -0
- data/samples/consul-ui/js/keys.js +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d79f747c0b0378a3526f63fd7a4638f2cfe432da043821749c89f8b302a6489a
|
4
|
+
data.tar.gz: 69f3d665fda37542cc4496daeb77f2d300514d9708afb0eef363aebf1a5a74ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6e24033378a8bc9abd18c6e57da606e45aac7bf20ea8f295d33ea668f2d44b9abf4395099ecf0dbc804e50a0467426807f587ba2f07fc2149361b568ce5b791
|
7
|
+
data.tar.gz: 4a5c613be0aee5f4c7646286b699ab3d17cf4af3b26f6e227884f14c79648d6ea3086777d547de162bd5906e161877a1c3e5f7d19c2a5ecc8d1c94a072eebcb3
|
data/CHANGELOG.md
CHANGED
@@ -2,9 +2,25 @@
|
|
2
2
|
|
3
3
|
## (UNRELEASED)
|
4
4
|
|
5
|
+
## 1.18.2 (August 28, 2019)
|
6
|
+
|
7
|
+
BUGFIX:
|
8
|
+
|
9
|
+
* In Consul UI, showing data from KV with markup was not properly handled
|
10
|
+
|
11
|
+
NEW FEATURES:
|
12
|
+
|
13
|
+
Support any request method for remote_resource.as_json (#41)
|
14
|
+
|
15
|
+
- support post and other request methods
|
16
|
+
- accept any 2xx result (instead of just 200). This is a semi-breaking
|
17
|
+
change.
|
18
|
+
- accept body passed for non GET requests
|
19
|
+
- allow to add headers (such as Authorization)
|
20
|
+
|
5
21
|
## 1.18.1 (July 27, 2019)
|
6
22
|
|
7
|
-
|
23
|
+
BUGFIX:
|
8
24
|
|
9
25
|
Fixed wrong lazy initialization in `remote_resource.as_json` that
|
10
26
|
cause too many connections to be opened.
|
data/Dockerfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
FROM ruby:2.5
|
2
|
+
|
3
|
+
WORKDIR /usr/src/app
|
4
|
+
COPY . .
|
5
|
+
|
6
|
+
RUN apt-get update -qq && apt-get install -y build-essential nginx-light
|
7
|
+
|
8
|
+
RUN bundle install
|
9
|
+
|
10
|
+
EXPOSE 80
|
11
|
+
ENV LANG C.UTF-8
|
12
|
+
ENV CONSUL_HTTP_ADDR http://consul-relay.service.consul.preprod.crto.in:8500
|
13
|
+
|
14
|
+
ENTRYPOINT ["/usr/local/bin/bundle", "exec", "consul-templaterb"]
|
15
|
+
CMD ["--template", "samples/consul-ui/consul-keys-ui.html.erb", "--template", "samples/consul-ui/consul-nodes-ui.html.erb", "--template", "samples/consul-ui/consul-services-ui.html.erb", "--template", "samples/consul-ui/consul-timeline-ui.html.erb", "--template", "samples/consul-ui/consul_keys.json.erb", "--template", "samples/consul-ui/consul_nodes.json.erb", "--template", "samples/consul-ui/consul_services.json.erb", "--template", "samples/consul-ui/timeline.json.erb", "--template", "samples/consul-ui/consul-services-ui.html.erb:samples/consul-ui/index.html:touch samples/consul-ui/ready", "--sig-reload=NONE", "--exec=nginx -c /usr/src/app/docker-nginx-conf/nginx.conf"]
|
data/README.md
CHANGED
@@ -117,6 +117,13 @@ https://github.com/oneclick/rubyinstaller2/issues/96#issuecomment-434619796
|
|
117
117
|
gem install eventmachine consul-templaterb --platform ruby
|
118
118
|
```
|
119
119
|
|
120
|
+
### Run it with Docker
|
121
|
+
|
122
|
+
An Docker image is also available https://hub.docker.com/r/discoverycriteo/consul-templaterb
|
123
|
+
and allows to quickly have a working
|
124
|
+
[Consul-UI](https://github.com/criteo/consul-templaterb/blob/master/samples/consul-ui/README.md)
|
125
|
+
that will server the UI to explore your Consul Cluster.
|
126
|
+
|
120
127
|
### Playing with the samples templates
|
121
128
|
|
122
129
|
Samples are installed with the GEM, you can either
|
data/TemplateAPI.md
CHANGED
@@ -439,12 +439,23 @@ secret('secret/foo', [force_ttl: intInSecond])
|
|
439
439
|
### as_json(url, default_value, [refresh_delay_secs: intInSecond])
|
440
440
|
|
441
441
|
Fetch json data from any url. This allows to create templates with consul/vault data mixed in with data coming from other services/api.
|
442
|
-
Polling interval can be controlled with refresh_delay_secs.
|
442
|
+
Polling interval can be controlled with `refresh_delay_secs` option.
|
443
|
+
Request method (`GET`, `POST`, ...) can be controlled with `request_method` option.
|
443
444
|
|
444
445
|
```erb
|
445
446
|
remote_resource.as_json('http://my-api.dev/fridge/list.json', [])
|
446
447
|
```
|
447
448
|
|
449
|
+
Example with post (json_body will be applied `to_json` automatically):
|
450
|
+
```erb
|
451
|
+
remote_resource.as_json('http://my-api.dev/fridge', [], request_method: :post, json_body: {brand: 'any'})
|
452
|
+
```
|
453
|
+
|
454
|
+
Basic authentication can be done passing `headers` option.
|
455
|
+
```erb
|
456
|
+
remote_resource.as_json('http://my-api.dev/fridge/list.json', [], headers: { Authorization: [user, password]})
|
457
|
+
```
|
458
|
+
|
448
459
|
Full example: [samples/list_ruby_versions_from_rubygems.txt.erb](samples/list_ruby_versions_from_rubygems.txt.erb)
|
449
460
|
|
450
461
|
## template_info()
|
@@ -0,0 +1,27 @@
|
|
1
|
+
daemon off;
|
2
|
+
worker_processes 2;
|
3
|
+
|
4
|
+
error_log /usr/src/app/error.log info;
|
5
|
+
|
6
|
+
events {
|
7
|
+
worker_connections 128;
|
8
|
+
}
|
9
|
+
|
10
|
+
http {
|
11
|
+
server_tokens off;
|
12
|
+
include /etc/nginx/mime.types;
|
13
|
+
charset utf-8;
|
14
|
+
|
15
|
+
access_log /usr/src/app/access.log combined;
|
16
|
+
|
17
|
+
server {
|
18
|
+
server_name localhost;
|
19
|
+
listen 0.0.0.0:80;
|
20
|
+
root /usr/src/app/samples/consul-ui;
|
21
|
+
sendfile on;
|
22
|
+
|
23
|
+
error_page 500 502 503 504 /50x.html;
|
24
|
+
|
25
|
+
}
|
26
|
+
|
27
|
+
}
|
@@ -26,8 +26,8 @@ module Consul
|
|
26
26
|
@endp_manager = endpoints_manager
|
27
27
|
end
|
28
28
|
|
29
|
-
def as_json(url, default_value, refresh_delay_secs: 10)
|
30
|
-
conf = JSONConfiguration.new(url: url, min_duration: refresh_delay_secs, retry_on_non_diff: refresh_delay_secs)
|
29
|
+
def as_json(url, default_value, refresh_delay_secs: 10, **opts)
|
30
|
+
conf = JSONConfiguration.new(url: url, min_duration: refresh_delay_secs, retry_on_non_diff: refresh_delay_secs, **opts)
|
31
31
|
@endp_manager.create_if_missing(url, {}) do
|
32
32
|
if default_value.is_a?(Array)
|
33
33
|
ConsulTemplateJSONArray.new(JSONEndpoint.new(conf, url, default_value))
|
@@ -7,12 +7,16 @@ module Consul
|
|
7
7
|
module Async
|
8
8
|
class JSONConfiguration
|
9
9
|
attr_reader :url, :retry_duration, :min_duration, :retry_on_non_diff,
|
10
|
-
:debug, :enable_gzip_compression
|
10
|
+
:debug, :enable_gzip_compression, :request_method, :json_body,
|
11
|
+
:headers
|
11
12
|
def initialize(url:,
|
12
13
|
debug: { network: false },
|
13
14
|
retry_duration: 10,
|
14
15
|
min_duration: 10,
|
15
16
|
retry_on_non_diff: 10,
|
17
|
+
request_method: :get,
|
18
|
+
json_body: nil,
|
19
|
+
headers: {},
|
16
20
|
enable_gzip_compression: true)
|
17
21
|
@url = url
|
18
22
|
@debug = debug
|
@@ -20,6 +24,9 @@ module Consul
|
|
20
24
|
@retry_duration = retry_duration
|
21
25
|
@min_duration = min_duration
|
22
26
|
@retry_on_non_diff = retry_on_non_diff
|
27
|
+
@request_method = request_method
|
28
|
+
@json_body = json_body
|
29
|
+
@headers = headers
|
23
30
|
end
|
24
31
|
|
25
32
|
def create(_url)
|
@@ -135,7 +142,14 @@ module Consul
|
|
135
142
|
keepalive: true,
|
136
143
|
callback: method(:on_response)
|
137
144
|
}
|
145
|
+
if conf.json_body
|
146
|
+
res[:body] = conf.json_body.to_json
|
147
|
+
res[:head]['Content-Type'] = 'application/json'
|
148
|
+
end
|
138
149
|
res[:head]['accept-encoding'] = 'identity' unless conf.enable_gzip_compression
|
150
|
+
conf.headers.map do |k, v|
|
151
|
+
res[:head][k] = v
|
152
|
+
end
|
139
153
|
@query_params.each_pair do |k, v|
|
140
154
|
res[:query][k] = v
|
141
155
|
end
|
@@ -167,9 +181,10 @@ module Consul
|
|
167
181
|
conn: EventMachine::HttpRequest.new(conf.url, options)
|
168
182
|
}
|
169
183
|
cb = proc do
|
170
|
-
|
184
|
+
request_method = conf.request_method.to_sym
|
185
|
+
http = connection[:conn].send(request_method, build_request)
|
171
186
|
http.callback do
|
172
|
-
if enforce_json_200 && http.response_header.status
|
187
|
+
if enforce_json_200 && !(200..299).cover?(http.response_header.status) && http.response_header['Content-Type'] != 'application/json'
|
173
188
|
_handle_error(http) do
|
174
189
|
warn "[RETRY][#{url}] (#{@consecutive_errors} errors)" if (@consecutive_errors % 10) == 1
|
175
190
|
end
|
data/lib/consul/async/version.rb
CHANGED
data/samples/consul-ui/README.md
CHANGED
@@ -12,6 +12,13 @@ meaning that it can be scaled horizontally without any troubles with Consul.
|
|
12
12
|
* List all nodes
|
13
13
|
* List datacenters
|
14
14
|
|
15
|
+
## Quick install with Docker
|
16
|
+
|
17
|
+
An Docker image is also available https://hub.docker.com/r/discoverycriteo/consul-templaterb
|
18
|
+
and allows to quickly have a working
|
19
|
+
[Consul-UI](https://github.com/criteo/consul-templaterb/blob/master/samples/consul-ui/README.md)
|
20
|
+
that will server the UI to explore your Consul Cluster.
|
21
|
+
|
15
22
|
## Is it prod ready?
|
16
23
|
|
17
24
|
This application is used for several months within Criteo to replace Consul native interface and
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consul-templaterb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.18.
|
4
|
+
version: 1.18.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SRE Core Services
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-http-request
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- CHANGELOG.md
|
171
171
|
- CODE_OF_CONDUCT.md
|
172
172
|
- CONTRIBUTING.md
|
173
|
+
- Dockerfile
|
173
174
|
- Gemfile
|
174
175
|
- LICENSE.txt
|
175
176
|
- README.md
|
@@ -177,6 +178,7 @@ files:
|
|
177
178
|
- TemplateAPI.md
|
178
179
|
- bin/consul-templaterb
|
179
180
|
- consul-templaterb.gemspec
|
181
|
+
- docker-nginx-conf/nginx.conf
|
180
182
|
- docs/images/consul-ui_001.png
|
181
183
|
- lib/consul/async/consul_endpoint.rb
|
182
184
|
- lib/consul/async/consul_template.rb
|