kubes 0.7.0 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +7 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +84 -0
  4. data/.github/ISSUE_TEMPLATE/documentation.md +12 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +64 -0
  6. data/.github/ISSUE_TEMPLATE/question.md +14 -0
  7. data/.github/PULL_REQUEST_TEMPLATE.md +50 -0
  8. data/CHANGELOG.md +18 -0
  9. data/README.md +2 -0
  10. data/docs/_docs/config/reference.md +1 -1
  11. data/docs/_docs/dsl/multiple-resources.md +14 -17
  12. data/docs/_docs/intro/concepts.md +8 -9
  13. data/docs/_docs/intro/docker-image.md +2 -2
  14. data/docs/_docs/intro/ordering.md +9 -10
  15. data/docs/_docs/patterns/multiple-envs.md +6 -6
  16. data/docs/_docs/resources/role.md +8 -9
  17. data/docs/_docs/yaml.md +4 -5
  18. data/docs/_docs/yaml/multiple-files.md +6 -7
  19. data/docs/_docs/yaml/multiple-resources.md +13 -14
  20. data/docs/_includes/commands.html +8 -9
  21. data/docs/_includes/header.html +7 -0
  22. data/docs/_includes/vs/kubes/structure.md +12 -13
  23. data/docs/_sass/theme.scss +92 -0
  24. data/docs/search/data.json +44 -0
  25. data/docs/search/index.html +30 -0
  26. data/docs/search/lunr.js +3475 -0
  27. data/docs/search/search.js +247 -0
  28. data/docs/search/tips.md +48 -0
  29. data/lib/kubes.rb +1 -0
  30. data/lib/kubes/cli/compile.rb +1 -1
  31. data/lib/kubes/command.rb +1 -0
  32. data/lib/kubes/compiler/decorator/base.rb +2 -2
  33. data/lib/kubes/compiler/dsl/core/base.rb +2 -6
  34. data/lib/kubes/compiler/dsl/core/fields.rb +1 -1
  35. data/lib/kubes/compiler/dsl/syntax/resource.rb +2 -3
  36. data/lib/kubes/compiler/shared/helpers.rb +4 -2
  37. data/lib/kubes/compiler/shared/runtime_helpers.rb +78 -0
  38. data/lib/kubes/compiler/strategy/dispatcher.rb +4 -3
  39. data/lib/kubes/compiler/strategy/erb.rb +2 -7
  40. data/lib/kubes/config.rb +1 -1
  41. data/lib/kubes/core.rb +6 -0
  42. data/lib/kubes/docker/strategy/image_name.rb +7 -3
  43. data/lib/kubes/version.rb +1 -1
  44. metadata +15 -6
  45. data/lib/kubes/compiler/shared/custom_helpers.rb +0 -17
  46. data/lib/kubes/compiler/shared/custom_variables.rb +0 -38
  47. data/lib/kubes/compiler/shared/plugin_helpers.rb +0 -14
@@ -0,0 +1,247 @@
1
+ /**
2
+ * A simple JSON search
3
+ * Requires jQuery (v 1.7+)
4
+ *
5
+ * @author Mat Hayward - Erskine Design
6
+ * @author Rishikesh Darandale <Rishikesh.Darandale@gmail.com>
7
+ * @version 1.1
8
+ */
9
+
10
+ var q, jsonFeedUrl = "/search/data.json",
11
+ $searchForm = $("[data-search-form]"),
12
+ $searchInput = $("[data-search-input]"),
13
+ $resultTemplate = $("#search-result"),
14
+ $resultsPlaceholder = $("[data-search-results]"),
15
+ $foundContainer = $("[data-search-found]"),
16
+ $foundTerm = $("[data-search-found-term]"),
17
+ $foundCount = $("[data-search-found-count]"),
18
+ $foundWord = $("[data-search-found-word]"),
19
+ allowEmpty = true,
20
+ showLoader = true,
21
+ loadingClass = "is--loading",
22
+ indexVar;
23
+
24
+
25
+ $(document).ready( function() {
26
+ // hide items found string
27
+ $foundContainer.hide();
28
+ // initiate search functionality
29
+ initSearch();
30
+ });
31
+
32
+ function initSearch() {
33
+ if(!sessionStorage.getItem("lunrIndex")) {
34
+ // get the data
35
+ getData();
36
+ } else {
37
+ // Get search results if q parameter is set in querystring
38
+ if (getParameterByName('q')) {
39
+ q = decodeURIComponent(getParameterByName('q'));
40
+ $searchInput.val(q);
41
+ execSearch(q);
42
+ }
43
+ }
44
+
45
+ // Get search results on submission of form
46
+ $(document).on("submit", $searchForm, function(e) {
47
+ console.log("form submitted");
48
+ e.preventDefault();
49
+ q = $searchInput.val();
50
+ execSearch(q);
51
+ });
52
+ }
53
+
54
+ /**
55
+ * Get the JSON data
56
+ * Get the generated feeds/feed.json file so lunr.js can search it locally.
57
+ * Store the index in sessionStorage
58
+ */
59
+ function getData(indexVar) {
60
+ jqxhr = $.getJSON(jsonFeedUrl)
61
+ .done(function(loaded_data){
62
+ // save the actual data as well
63
+ sessionStorage.setItem("actualData", JSON.stringify(loaded_data));
64
+ // set the index fields
65
+ indexVar = lunr(function () {
66
+ this.field('id');
67
+ this.field('title', { boost: 10 });
68
+ this.field('search_title', { boost: 10 });
69
+ this.field('content', { boost: 10 });
70
+ this.field('author');
71
+ loaded_data.forEach(function (doc, index) {
72
+ if ( doc.search_omit != "true" ) {
73
+ console.log("adding to index: " + doc.title);
74
+ this.add($.extend({ "id": index }, doc));
75
+ }
76
+ }, this)
77
+ });
78
+ // store the index in sessionStorage
79
+ sessionStorage.setItem("lunrIndex", JSON.stringify(indexVar));
80
+ // Get search results if q parameter is set in querystring
81
+ if (getParameterByName('q')) {
82
+ q = decodeURIComponent(getParameterByName('q'));
83
+ $searchInput.val(q);
84
+ execSearch(q);
85
+ }
86
+ })
87
+ .fail( function() {
88
+ console.log("get json failed...");
89
+ })
90
+ .always( function() {
91
+ console.log("finally...");
92
+ });
93
+ }
94
+
95
+ /**
96
+ * Get the search result from lunr
97
+ * @param {String} q
98
+ * @returns search results
99
+ */
100
+ function getResults(q) {
101
+ var savedIndexData = JSON.parse(sessionStorage.getItem("lunrIndex"));
102
+ console.log("Indexed var from sessionStorage: " + savedIndexData);
103
+ return lunr.Index.load(savedIndexData).search(q);
104
+ }
105
+
106
+ /**
107
+ * Executes search
108
+ * @param {String} q
109
+ * @return null
110
+ */
111
+ function execSearch(q) {
112
+ if (q != '' || allowEmpty) {
113
+ if (showLoader) {
114
+ toggleLoadingClass();
115
+ }
116
+ processResultData(getResults(q));
117
+ changeUrl("Search", "/search/?q=" + encodeURIComponent(q));
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Toggles loading class on results and found string
123
+ * @return null
124
+ */
125
+ function toggleLoadingClass() {
126
+ $resultsPlaceholder.toggleClass(loadingClass);
127
+ $foundContainer.toggleClass(loadingClass);
128
+ }
129
+
130
+ /**
131
+ * Process search result data
132
+ * @return null
133
+ */
134
+ function processResultData(searchResults) {
135
+ $results = [];
136
+
137
+ console.log("Search Results: " + searchResults);
138
+ var resultsCount = 0,
139
+ results = "";
140
+
141
+ // Iterate over the results
142
+ searchResults.forEach(function(result) {
143
+ var loaded_data = JSON.parse(sessionStorage.getItem("actualData"));
144
+ var item = loaded_data[result.ref];
145
+ var result = populateResultContent($resultTemplate.html(), item);
146
+ resultsCount++;
147
+ results += result;
148
+ });
149
+
150
+
151
+ if (showLoader) {
152
+ toggleLoadingClass();
153
+ }
154
+
155
+ populateResultsString(resultsCount);
156
+ showSearchResults(results);
157
+ }
158
+
159
+ /**
160
+ * Add search results to placeholder
161
+ * @param {String} results
162
+ * @return null
163
+ */
164
+ function showSearchResults(results) {
165
+ // Add results HTML to placeholder
166
+ $resultsPlaceholder.html(results);
167
+ }
168
+
169
+ /**
170
+ * Add results content to item template
171
+ * @param {String} html
172
+ * @param {object} item
173
+ * @return {String} Populated HTML
174
+ */
175
+ function populateResultContent(html, item) {
176
+ var title = item.search_title || item.title
177
+ html = injectContent(html, title, '##Title##');
178
+ html = injectContent(html, item.link, '##Url##');
179
+ var content = text_truncate(item.content);
180
+ html = injectContent(html, content, '##Content##');
181
+ return html;
182
+ }
183
+
184
+ function text_truncate(str, length, ending) {
185
+ if (length == null) {
186
+ length = 255;
187
+ }
188
+ if (ending == null) {
189
+ ending = '...';
190
+ }
191
+ if (str.length > length) {
192
+ return str.substring(0, length - ending.length) + ending;
193
+ } else {
194
+ return str;
195
+ }
196
+ };
197
+
198
+ /**
199
+ * Populates results string
200
+ * @param {String} count
201
+ * @return null
202
+ */
203
+ function populateResultsString(count) {
204
+ $foundTerm.text(q);
205
+ $foundCount.text(count);
206
+ if (count == 1)
207
+ $foundWord.text("result")
208
+ else
209
+ $foundWord.text("results")
210
+ $foundContainer.show();
211
+ }
212
+
213
+ /* ==========================================================================
214
+ Helper functions
215
+ ========================================================================== */
216
+
217
+
218
+ /**
219
+ * Gets query string parameter - taken from http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
220
+ * @param {String} name
221
+ * @return {String} parameter value
222
+ */
223
+ function getParameterByName(name) {
224
+ var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
225
+ return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
226
+ }
227
+
228
+ /**
229
+ * Injects content into template using placeholder
230
+ * @param {String} originalContent
231
+ * @param {String} injection
232
+ * @param {String} placeholder
233
+ * @return {String} injected content
234
+ */
235
+ function injectContent(originalContent, injection, placeholder) {
236
+ var regex = new RegExp(placeholder, 'g');
237
+ return originalContent.replace(regex, injection);
238
+ }
239
+
240
+ function changeUrl(page, url) {
241
+ if (typeof(window.history.pushState) != "undefined") {
242
+ var obj = { Page: page, Url: url };
243
+ window.history.pushState(obj, obj.Page, obj.Url);
244
+ } else {
245
+ console.log("Browser does not support HTML5.");
246
+ }
247
+ }
@@ -0,0 +1,48 @@
1
+ ---
2
+ title: Search Tips
3
+ ---
4
+
5
+ Here are some useful search tips that can help to make searching more effective.
6
+
7
+ ## OR Searches
8
+
9
+ By default, searches for multiple terms are combined with OR. If a document matches at least one of the search terms, it will show in the results. So:
10
+
11
+ install aws
12
+
13
+ Will always result in more results just `install` by itself.
14
+
15
+
16
+ ## AND Searches
17
+
18
+ To do an AND search of "install AND aws" mark both terms as required, you use a `+` sign in front of each term. Example:
19
+
20
+ +install +aws
21
+
22
+ This results in pages only with both exactly install and aws.
23
+
24
+ ## Filter Terms
25
+
26
+ To filter "keywords", you use a `-` sign in front of each term. Example:
27
+
28
+ +install -aws
29
+
30
+ This results in pages only with install but filter or reject any pages with aws.
31
+
32
+ ## Wildcard
33
+
34
+ You can use wildcards:
35
+
36
+ install*
37
+
38
+ ## Fields
39
+
40
+ You can target specific fields:
41
+
42
+ title:install
43
+
44
+ For fields see: [search data.json]({% link search/data.json %})
45
+
46
+ ## More Tips
47
+
48
+ More search tips can be found at: [lunrjs searching](https://lunrjs.com/guides/searching.html)
data/lib/kubes.rb CHANGED
@@ -16,6 +16,7 @@ require "hash_squeezer"
16
16
  require "kubes/version"
17
17
  require "memoist"
18
18
  require "rainbow/ext/string"
19
+ require "singleton"
19
20
  require "yaml"
20
21
 
21
22
  # core helper libraries
@@ -16,7 +16,7 @@ class Kubes::CLI
16
16
 
17
17
  # auto build docker image and push image if kubes docker build not yet called
18
18
  def build_docker_image
19
- return if File.exist?("#{Kubes.root}/.kubes/state/docker_image.txt")
19
+ return if File.exist?(Kubes.config.state.path)
20
20
  Build.new(@options).run
21
21
  end
22
22
  end
data/lib/kubes/command.rb CHANGED
@@ -57,6 +57,7 @@ module Kubes
57
57
  end
58
58
 
59
59
  def check_project!(command_name)
60
+ return if command_name.nil?
60
61
  return if %w[-h -v completion completion_script help init new version].include?(command_name)
61
62
  Kubes.check_project!
62
63
  end
@@ -12,9 +12,9 @@ module Kubes::Compiler::Decorator
12
12
 
13
13
  def result
14
14
  if @data.key?(Kubes::Compiler::Dsl::Core::Blocks)
15
- @data.results.each { |k,v| process(v) } # returns nil
15
+ @data.results.each { |k,v| run(v) } # returns nil
16
16
  else
17
- process # processes and returns @data
17
+ run # processes and returns @data
18
18
  end
19
19
  @data # important to return @data so we keep the original @data structure: Blocks or Hash
20
20
  end
@@ -3,17 +3,13 @@ module Kubes::Compiler::Dsl::Core
3
3
  extend Fields
4
4
  include DslEvaluator
5
5
  include Helpers
6
- include Kubes::Compiler::Shared::CustomHelpers
7
- include Kubes::Compiler::Shared::CustomVariables
8
- include Kubes::Compiler::Shared::PluginHelpers
6
+ include Kubes::Compiler::Shared::RuntimeHelpers
9
7
 
10
8
  def initialize(options={})
11
9
  @options = options
12
10
  @name = options[:name]
13
11
  @path = options[:path]
14
- load_plugin_helpers
15
- load_custom_variables
16
- load_custom_helpers
12
+ load_runtime_helpers
17
13
  end
18
14
 
19
15
  def run
@@ -64,7 +64,7 @@ module Kubes::Compiler::Dsl::Core
64
64
  result = instance_variable_get(ivar)
65
65
  result = {} if mode == "reset" # allow user to override with mode: reset option
66
66
  result ||= {} # maintain value for layering
67
- result.deeper_merge!(value)
67
+ Kubes.deep_merge!(result, value)
68
68
  instance_variable_set(ivar, result)
69
69
  end
70
70
  end
@@ -1,7 +1,6 @@
1
1
  module Kubes::Compiler::Dsl::Syntax
2
2
  class Resource < Kubes::Compiler::Dsl::Core::Base
3
3
  include Kubes::Compiler::Util::Normalize
4
- include Kubes::Compiler::Shared::Helpers
5
4
 
6
5
  fields :apiVersion, # <string>
7
6
  :kind, # <string>
@@ -19,7 +18,7 @@ module Kubes::Compiler::Dsl::Syntax
19
18
  # top-level of resource is quite common
20
19
  def default_result
21
20
  data = top.merge(default_top)
22
- data.deeper_merge!(default_result_append)
21
+ Kubes.deep_merge!(data, default_result_append)
23
22
  data.deep_stringify_keys!
24
23
  HashSqueezer.squeeze(data)
25
24
  end
@@ -64,7 +63,7 @@ module Kubes::Compiler::Dsl::Syntax
64
63
 
65
64
  # For generic kind
66
65
  def field(name, data)
67
- top.deeper_merge!(name => data)
66
+ Kubes.deep_merge!(top, {name => data})
68
67
  end
69
68
  end
70
69
  end
@@ -1,4 +1,5 @@
1
1
  require "base64"
2
+ require "json"
2
3
 
3
4
  module Kubes::Compiler::Shared
4
5
  module Helpers
@@ -17,11 +18,12 @@ module Kubes::Compiler::Shared
17
18
  end
18
19
 
19
20
  def built_image_helper
20
- path = Kubes.config.state.docker_image_path
21
+ path = Kubes.config.state.path
21
22
  unless File.exist?(path)
22
23
  raise Kubes::MissingDockerImage.new("Missing file with docker image built by kubes: #{path}. Try first running: kubes docker build")
23
24
  end
24
- IO.read(path)
25
+ data = JSON.load(IO.read(path))
26
+ data['image']
25
27
  end
26
28
 
27
29
  def with_extra(value)
@@ -0,0 +1,78 @@
1
+ module Kubes::Compiler::Shared
2
+ module RuntimeHelpers
3
+ include Kubes::Compiler::Shared::Helpers
4
+
5
+ def load_runtime_helpers
6
+ load_custom_variables # also load custom variables
7
+ load_plugin_helpers
8
+ load_custom_helpers
9
+ end
10
+
11
+ @@custom_helpers_loaded = false
12
+ def load_custom_helpers
13
+ return if @@custom_helpers_loaded
14
+ paths = Dir.glob("#{Kubes.root}/.kubes/helpers/**/*.rb")
15
+ paths.sort_by! { |p| p.size } # so namespaces are loaded first
16
+
17
+ paths.each do |path|
18
+ filename = path.sub(%r{.*.kubes/helpers/},'').sub('.rb','')
19
+ module_name = filename.camelize
20
+ base_class_for_helper.send :include, module_name.constantize
21
+ end
22
+ @@custom_helpers_loaded = true
23
+ end
24
+
25
+ # Load plugin helper methods from project
26
+ @@plugin_helpers_loaded = false
27
+ def load_plugin_helpers
28
+ return if @@plugin_helpers_loaded
29
+ Kubes::Plugin.plugins.each do |klass|
30
+ helpers_class = "#{klass}::Helpers".constantize # IE: KubesAws::Helpers
31
+ base_class_for_helper.send :include, helpers_class
32
+ end
33
+ @@plugin_helpers_loaded = true
34
+ end
35
+
36
+ def base_class_for_helper
37
+ if self.is_a?(Kubes::Compiler::Strategy::Erb)
38
+ Kubes::Compiler::Strategy::Erb
39
+ else
40
+ Kubes::Compiler::Dsl::Core::Base
41
+ end
42
+ end
43
+
44
+ include DslEvaluator
45
+ # Load custom variables from project
46
+ @@custom_variables_loaded = false
47
+ def load_custom_variables
48
+ return if Kubes.kustomize?
49
+
50
+ ext = File.extname(@path)
51
+ role = @path.sub(%r{.*\.kubes/resources/},'').sub(ext,'').split('/').first # IE: web
52
+ kind = File.basename(@path).sub(ext,'') # IE: deployment
53
+ all = "all"
54
+ if @block_form
55
+ kind = kind.pluralize
56
+ all = all.pluralize
57
+ end
58
+
59
+ layers = [
60
+ "base.rb",
61
+ "#{Kubes.env}.rb",
62
+ "base/all.rb",
63
+ "base/all/#{Kubes.env}.rb",
64
+ "base/#{kind}.rb",
65
+ "base/#{kind}/base.rb",
66
+ "base/#{kind}/#{Kubes.env}.rb",
67
+ "#{role}/#{kind}.rb",
68
+ "#{role}/#{kind}/base.rb",
69
+ "#{role}/#{kind}/#{Kubes.env}.rb",
70
+ ]
71
+
72
+ layers.each do |layer|
73
+ path = "#{Kubes.root}/.kubes/variables/#{layer}"
74
+ evaluate_file(path)
75
+ end
76
+ end
77
+ end
78
+ end