qb 0.3.25 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/ansible.cfg +10 -1
  4. data/exe/.qb_interop_receive +3 -10
  5. data/exe/qb +8 -2
  6. data/lib/python/qb/__init__.py +6 -0
  7. data/{roles/qb/ruby/rspec/setup/tasks/persistence.yml → lib/python/qb/ansible/__init__.py} +0 -0
  8. data/lib/python/qb/ansible/modules/__init__.py +0 -0
  9. data/lib/python/qb/ansible/modules/docker/__init__.py +0 -0
  10. data/lib/python/qb/ansible/modules/docker/client.py +177 -0
  11. data/lib/python/qb/ansible/modules/docker/image_manager.py +754 -0
  12. data/lib/python/qb/ipc/__init__.py +0 -0
  13. data/lib/python/qb/ipc/stdio/__init__.py +99 -0
  14. data/lib/python/qb/ipc/stdio/logging.py +151 -0
  15. data/lib/qb.rb +3 -3
  16. data/lib/qb/ansible/cmds/playbook.rb +5 -14
  17. data/lib/qb/ansible/env.rb +36 -6
  18. data/lib/qb/ansible/module.rb +396 -152
  19. data/lib/qb/ansible/module/response.rb +195 -0
  20. data/lib/qb/ansible/modules.rb +42 -0
  21. data/lib/qb/ansible/modules/docker/image.rb +273 -0
  22. data/lib/qb/cli.rb +5 -18
  23. data/lib/qb/cli/run.rb +2 -2
  24. data/lib/qb/data.rb +22 -0
  25. data/lib/qb/data/immutable.rb +39 -0
  26. data/lib/qb/docker.rb +2 -0
  27. data/lib/qb/docker/cli.rb +430 -0
  28. data/lib/qb/docker/image.rb +207 -0
  29. data/lib/qb/docker/image/name.rb +309 -0
  30. data/lib/qb/docker/image/tag.rb +113 -0
  31. data/lib/qb/docker/repo.rb +0 -0
  32. data/lib/qb/errors.rb +17 -3
  33. data/lib/qb/execution.rb +83 -0
  34. data/lib/qb/ipc.rb +48 -0
  35. data/lib/qb/ipc/stdio.rb +32 -0
  36. data/lib/qb/ipc/stdio/client.rb +267 -0
  37. data/lib/qb/ipc/stdio/server.rb +229 -0
  38. data/lib/qb/ipc/stdio/server/in_service.rb +18 -0
  39. data/lib/qb/ipc/stdio/server/log_service.rb +168 -0
  40. data/lib/qb/ipc/stdio/server/out_service.rb +20 -0
  41. data/lib/qb/ipc/stdio/server/service.rb +229 -0
  42. data/lib/qb/options.rb +360 -502
  43. data/lib/qb/options/option.rb +293 -115
  44. data/lib/qb/options/option/option_parser_concern.rb +228 -0
  45. data/lib/qb/options/types.rb +73 -0
  46. data/lib/qb/package.rb +0 -1
  47. data/lib/qb/package/version.rb +179 -58
  48. data/lib/qb/package/version/from.rb +192 -51
  49. data/lib/qb/package/version/leveled.rb +1 -1
  50. data/lib/qb/path.rb +3 -2
  51. data/lib/qb/repo/git.rb +9 -85
  52. data/lib/qb/role/default_dir.rb +2 -2
  53. data/lib/qb/role/errors.rb +2 -8
  54. data/lib/qb/util.rb +1 -2
  55. data/lib/qb/util/bundler.rb +73 -43
  56. data/lib/qb/util/decorators.rb +99 -0
  57. data/lib/qb/util/interop.rb +7 -8
  58. data/lib/qb/util/resource.rb +12 -13
  59. data/lib/qb/version.rb +10 -0
  60. data/library/path_facts +5 -10
  61. data/library/qb.module.rb +105 -0
  62. data/library/stream +6 -26
  63. data/load/ansible/module/autorun.rb +25 -0
  64. data/load/ansible/module/script.rb +123 -0
  65. data/load/rebundle.rb +39 -0
  66. data/plugins/filter/dict_filters.py +56 -0
  67. data/plugins/{filter_plugins/path_plugins.py → filter/path_filters.py} +0 -0
  68. data/plugins/{filter_plugins/ruby_interop_plugins.py → filter/ruby_interop_filters.py} +1 -17
  69. data/plugins/{filter_plugins/string_plugins.py → filter/string_filters.py} +1 -20
  70. data/plugins/{filter_plugins/version_plugins.py → filter/version_filters.py} +3 -18
  71. data/plugins/{lookup_plugins/every.py → lookup/every_lookups.py} +0 -0
  72. data/plugins/{lookup_plugins/resolve.py → lookup/resolve_lookups.py} +0 -0
  73. data/plugins/{lookup_plugins/version.py → lookup/version_lookups.py} +0 -16
  74. data/plugins/test/dict_tests.py +36 -0
  75. data/plugins/test/string_tests.py +36 -0
  76. data/qb.gemspec +7 -3
  77. data/roles/nrser.rb/library/set_fact_with_ruby.rb +3 -9
  78. data/roles/nrser.state_mate/library/state +3 -17
  79. data/roles/qb/call/meta/qb.yml +1 -1
  80. data/roles/qb/dev/ref/repo/git/meta/qb.yml +1 -1
  81. data/roles/qb/{ruby/rspec/setup → docker/mac/kubernetes}/defaults/main.yml +1 -1
  82. data/roles/qb/{ruby/rspec/setup → docker/mac/kubernetes}/meta/main.yml +3 -2
  83. data/roles/qb/{ruby/rspec/setup → docker/mac/kubernetes}/meta/qb.yml +12 -7
  84. data/roles/qb/docker/mac/kubernetes/tasks/main.yml +45 -0
  85. data/roles/qb/git/check/clean/meta/qb.yml +1 -1
  86. data/roles/qb/git/ignore/meta/qb +10 -3
  87. data/roles/qb/git/submodule/update/library/git_submodule_update +17 -27
  88. data/roles/qb/github/pages/setup/meta/qb.yml +1 -1
  89. data/roles/qb/labs/atom/apm/meta/qb.yml +1 -1
  90. data/roles/qb/osx/git/change_case/meta/qb.yml +1 -1
  91. data/roles/qb/osx/notif/meta/qb.yml +1 -1
  92. data/roles/qb/pkg/bump/library/bump +4 -16
  93. data/roles/qb/role/qb/defaults/main.yml +2 -0
  94. data/roles/qb/role/qb/meta/qb.yml +10 -5
  95. data/roles/qb/role/qb/templates/qb.yml.j2 +7 -2
  96. data/roles/qb/role/templates/library/module.rb.j2 +12 -23
  97. data/roles/qb/role/templates/meta/main.yml.j2 +14 -1
  98. data/roles/qb/ruby/bundler/meta/qb.yml +1 -1
  99. data/roles/qb/ruby/dependency/meta/qb.yml +1 -1
  100. data/roles/qb/ruby/gem/bin_stubs/meta/qb.yml +1 -1
  101. data/roles/qb/ruby/gem/bin_stubs/templates/console +8 -2
  102. data/roles/qb/ruby/gem/build/meta/qb.yml +1 -1
  103. data/roles/qb/ruby/gem/new/meta/qb.yml +1 -1
  104. data/roles/qb/ruby/nrser/rspex/generate/meta/qb.yml +5 -5
  105. data/roles/qb/ruby/nrser/rspex/issue/meta/qb.yml +1 -1
  106. data/roles/qb/ruby/yard/clean/meta/qb.yml +1 -1
  107. data/roles/qb/ruby/yard/config/library/yard.get_output_dir +5 -15
  108. data/roles/qb/ruby/yard/config/meta/qb.yml +1 -1
  109. data/roles/qb/ruby/yard/setup/meta/qb.yml +1 -1
  110. metadata +71 -22
  111. data/lib/qb/ansible_module.rb +0 -5
  112. data/lib/qb/util/stdio.rb +0 -187
  113. data/roles/qb/ruby/rspec/setup/tasks/main.yml +0 -4
@@ -0,0 +1,113 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ # Requirements
5
+ # =======================================================================
6
+
7
+ # Stdlib
8
+ # -----------------------------------------------------------------------
9
+
10
+ # Deps
11
+ # -----------------------------------------------------------------------
12
+
13
+ # Project / Package
14
+ # -----------------------------------------------------------------------
15
+
16
+ require 'qb/data'
17
+
18
+ require 'qb/package/version'
19
+
20
+
21
+ # Refinements
22
+ # =======================================================================
23
+
24
+ require 'nrser/refinements/types'
25
+ using NRSER::Types
26
+
27
+
28
+
29
+ # Namespace
30
+ # ============================================================================
31
+
32
+ module QB
33
+ module Docker
34
+ class Image < QB::Data::Immutable
35
+
36
+ # Definitions
37
+ # =======================================================================
38
+
39
+ # A Docker image tag, with support for paring versions.
40
+ #
41
+ class Tag < QB::Data::Immutable
42
+
43
+ include NRSER::Log::Mixin
44
+
45
+
46
+ # @todo Document from_s method.
47
+ #
48
+ # @param [type] arg_name
49
+ # @todo Add name param description.
50
+ #
51
+ # @return [return_type]
52
+ # @todo Document return value.
53
+ #
54
+ def self.from_s string
55
+ new source: string
56
+ end # .from_s
57
+
58
+
59
+ # @!group Props
60
+ # ==========================================================================
61
+
62
+ prop :string,
63
+ type: t.non_empty_str,
64
+ source: :to_s
65
+
66
+ prop :source,
67
+ type: t.non_empty_str?,
68
+ default: nil
69
+
70
+ prop :version,
71
+ type: t.maybe( QB::Package::Version ),
72
+ default: ->( source: ) {
73
+ begin
74
+ QB::Package::Version::From.docker_tag source
75
+ rescue ArgumentError => error
76
+ nil
77
+ rescue TypeError => error
78
+ nil
79
+ end
80
+ }
81
+
82
+ # @!endgroup Props # *******************************************************
83
+
84
+
85
+ invariant t.attrs( source: ~t.nil ) |
86
+ t.attrs( version: ~t.nil )
87
+
88
+ # Instance Methods
89
+ # ======================================================================
90
+
91
+ def to_s
92
+ if version
93
+ version.docker_tag
94
+ else
95
+ source
96
+ end
97
+ end
98
+
99
+
100
+ def dirty?
101
+ version && version.build_dirty?
102
+ end
103
+
104
+
105
+ end # class Tag
106
+
107
+
108
+ # /Namespace
109
+ # ============================================================================
110
+
111
+ end # module QB
112
+ end # module Docker
113
+ end # class Image < QB::Data::Immutable
File without changes
@@ -1,16 +1,30 @@
1
+ # Requirements
2
+ # ========================================================================
3
+
4
+ # Deps
5
+ # ------------------------------------------------------------------------
6
+
7
+ require 'nrser/errors/nicer_error'
8
+
9
+
10
+ # Definitions
11
+ # ========================================================================
12
+
1
13
  module QB
2
14
  # Base class for QB errors.
3
- class Error < StandardError; end
15
+ class Error < StandardError
16
+ include NRSER::NicerError
17
+ end
4
18
 
5
19
 
6
20
  # State Errors
7
21
  # =====================================================================
8
22
  #
9
- # Raised when something - a role, the file system, etc. - is in a state
23
+ # Raised when something - a role, the file system, etc. - is in a state
10
24
  # that we can't deal with.
11
25
  #
12
26
 
13
- # Raised when something is in a bad state and no more specific error
27
+ # Raised when something is in a bad state and no more specific error
14
28
  # subclass applies.
15
29
  class StateError < Error; end
16
30
 
@@ -0,0 +1,83 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ # Requirements
5
+ # =======================================================================
6
+
7
+ # Stdlib
8
+ # -----------------------------------------------------------------------
9
+
10
+ # Deps
11
+ # -----------------------------------------------------------------------
12
+
13
+ # Need mutable props mixin
14
+ require 'nrser/props/immutable/instance_variables'
15
+
16
+ # Need {Time#iso8601_for_idiots}
17
+ require 'nrser/core_ext/time'
18
+
19
+ # Project / Package
20
+ # -----------------------------------------------------------------------
21
+
22
+
23
+ # Refinements
24
+ # =======================================================================
25
+
26
+
27
+ # Declarations
28
+ # =======================================================================
29
+
30
+
31
+ # Definitions
32
+ # =======================================================================
33
+
34
+
35
+ # An object that encapsulates an execution of the QB program.
36
+ #
37
+ class QB::Execution
38
+
39
+ # Constants
40
+ # ========================================================================
41
+
42
+
43
+ # Mixins
44
+ # ========================================================================
45
+
46
+ include NRSER::Props::Mutable::InstanceVariables
47
+
48
+
49
+ # Class Methods
50
+ # ========================================================================
51
+
52
+
53
+ # Props
54
+ # ========================================================================
55
+
56
+ # @!attribute [r]
57
+ prop :started_at,
58
+ type: Time,
59
+ writer: false,
60
+ default: -> { Time.current }
61
+
62
+ prop :pid,
63
+ type: Fixnum,
64
+ source: -> { Process.pid }
65
+
66
+ prop :id,
67
+ type: String,
68
+ source: -> { "#{ self.started_at }-pid_#{ self.pid }" }
69
+
70
+ # Construction
71
+ # ========================================================================
72
+
73
+ # Instantiate a new `QB::Execution`.
74
+ def initialize values = {}
75
+ initialize_props values
76
+ end # #initialize
77
+
78
+
79
+ # Instance Methods
80
+ # ========================================================================
81
+
82
+
83
+ end # class QB::Execution
@@ -0,0 +1,48 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ # Requirements
5
+ # =======================================================================
6
+
7
+ # Stdlib
8
+ # -----------------------------------------------------------------------
9
+
10
+ # Deps
11
+ # -----------------------------------------------------------------------
12
+
13
+ # Project / Package
14
+ # -----------------------------------------------------------------------
15
+
16
+
17
+ # Refinements
18
+ # =======================================================================
19
+
20
+
21
+ # Declarations
22
+ # =======================================================================
23
+
24
+
25
+ # Definitions
26
+ # =======================================================================
27
+
28
+ # Module for handling inter-process communication (IPC), which is needed
29
+ # for child processes - Ansible processes and Ansible module processes -
30
+ # to interact with the
31
+ #
32
+ module QB::IPC
33
+
34
+
35
+ # @todo Document is_master_process! method.
36
+ #
37
+ # @param [type] arg_name
38
+ # @todo Add name param description.
39
+ #
40
+ # @return [return_type]
41
+ # @todo Document return value.
42
+ #
43
+ def self.is_master_process!
44
+
45
+ end # .is_master_process!
46
+
47
+
48
+ end # module QB::IPC
@@ -0,0 +1,32 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ # Declarations
5
+ # =======================================================================
6
+
7
+ module QB::IPC; end
8
+
9
+ # Definitions
10
+ # =======================================================================
11
+
12
+ # Simple & shitty inter-process communication (IPC) system for passing
13
+ # standard-IO lines, intended and used to move them from Ansible module
14
+ # child processes up to the QB master process for display.
15
+ #
16
+ module QB::IPC::STDIO
17
+
18
+ # Get the ENV var name that will hold the socket path for a stream name -
19
+ # `:in`, `:out` or `:err` - when passed from parent to child processes.
20
+ #
21
+ # @example
22
+ # path_env_var_name :in
23
+ # # => "QB_STDIO_IN"
24
+ #
25
+ # @param [Symbol] name
26
+ # @return [String]
27
+ #
28
+ def self.path_env_var_name name
29
+ "QB_STDIO_#{ name.to_s.upcase }"
30
+ end # .env_key
31
+
32
+ end # module QB::IPC::STDIO
@@ -0,0 +1,267 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ # Requirements
5
+ # =======================================================================
6
+
7
+ # Stdlib
8
+ # -----------------------------------------------------------------------
9
+
10
+ # Need {UNIXSocket}
11
+ require 'socket'
12
+
13
+ # Deps
14
+ # -----------------------------------------------------------------------
15
+
16
+ # Need logging
17
+ require 'nrser'
18
+
19
+ # Project / Package
20
+ # -----------------------------------------------------------------------
21
+
22
+ # Need {QB::IPC::STDIO.path_env_var_name}
23
+ require 'qb/ipc/stdio'
24
+
25
+
26
+ # Definitions
27
+ # =======================================================================
28
+
29
+ # @todo document QB::IPC::STDIO::Client class.
30
+ class QB::IPC::STDIO::Client
31
+
32
+ # Mixins
33
+ # ========================================================================
34
+
35
+ # Add {.logger} and {#logger} methods
36
+ include NRSER::Log::Mixin
37
+
38
+
39
+ # Classes
40
+ # ============================================================================
41
+
42
+ # @todo document Connection class.
43
+ class Connection
44
+
45
+ # Mixins
46
+ # ========================================================================
47
+
48
+ # Add {.logger} and {#logger} methods
49
+ include NRSER::Log::Mixin
50
+
51
+
52
+ # Attributes
53
+ # ========================================================================
54
+
55
+ # TODO document `name` attribute.
56
+ #
57
+ # @return [Symbol]
58
+ #
59
+ attr_reader :name
60
+
61
+
62
+ # TODO document `type` attribute.
63
+ #
64
+ # @return [:in | :out]
65
+ #
66
+ attr_reader :type
67
+
68
+
69
+ # TODO document `path` attribute.
70
+ #
71
+ # @return [Pathname?]
72
+ #
73
+ attr_reader :path
74
+
75
+
76
+ # TODO document `socket` attribute.
77
+ #
78
+ # @return [UNIXSocket?]
79
+ #
80
+ attr_reader :socket
81
+
82
+
83
+ # TODO document `global_original` attribute.
84
+ #
85
+ # @return [attr_type]
86
+ #
87
+ attr_reader :global_original
88
+
89
+
90
+ # TODO document `env_var_name` attribute.
91
+ #
92
+ # @return [String]
93
+ #
94
+ attr_reader :env_var_name
95
+
96
+
97
+ # Construction
98
+ # ========================================================================
99
+
100
+ # Instantiate a new `Connection`.
101
+ def initialize name:, type:
102
+ @name = name
103
+ @type = type
104
+ @global_original = nil
105
+ @path = nil
106
+ @socket = nil
107
+ @env_var_name = QB::IPC::STDIO.path_env_var_name name
108
+ end # #initialize
109
+
110
+
111
+ # Instance Methods
112
+ # ========================================================================
113
+
114
+ def connected?
115
+ !!socket
116
+ end
117
+
118
+
119
+ def connect!
120
+ if connected?
121
+ raise "#{ inspect } is already connected!"
122
+ end
123
+
124
+ if get_path!
125
+ @global_original = global_get
126
+ @socket = UNIXSocket.new path.to_s
127
+ global_set! socket
128
+ end
129
+ end
130
+
131
+
132
+ def disconnect!
133
+ return unless connected?
134
+
135
+ logger.debug "Disconnecting...",
136
+ name: name,
137
+ socket: socket,
138
+ global_original: global_original
139
+
140
+ # Restore the original global and `nil` it out (if we have one)
141
+ if global_original
142
+ global_set! global_original
143
+ @global_original = nil
144
+ end
145
+
146
+ # Flush the socket if it's an out-bound
147
+ socket.flush if type == :out
148
+
149
+ # And close and `nil` it
150
+ socket.close
151
+ @socket = nil
152
+ end
153
+
154
+
155
+ protected
156
+ # ========================================================================
157
+
158
+ # Get the socket path from the ENV and set `@path` to it (which may be
159
+ # `nil` if we don't find anything).
160
+ #
161
+ # @return [Pathname?]
162
+ #
163
+ def get_path!
164
+ @path = ENV[ env_var_name ]
165
+ @path = path.to_pn if path
166
+ path
167
+ end
168
+
169
+
170
+ # Get the IO global (`$stdin`, `$stdout`, `$stderr`) if {#name} lines
171
+ # up for one of those.
172
+ #
173
+ # @return [IO?]
174
+ #
175
+ def global_get
176
+ case name
177
+ when :in
178
+ $stdin
179
+ when :out
180
+ $stdout
181
+ when :err
182
+ $stderr
183
+ end
184
+ end # #global_get
185
+
186
+
187
+ # Set the IO global (`$stdin`, `$stdout`, `$stderr`) to `value` if
188
+ # {#name} lines up for one of those.
189
+ #
190
+ # @param [IO] value
191
+ # @return [void]
192
+ #
193
+ def global_set! value
194
+ case name
195
+ when :in
196
+ $stdin = value
197
+ when :out
198
+ $stdout = value
199
+ when :err
200
+ $stderr = value
201
+ end
202
+ end
203
+
204
+ public # end protected ***************************************************
205
+
206
+ end # class Connection
207
+
208
+
209
+ # Class Methods
210
+ # ========================================================================
211
+
212
+
213
+ # Attributes
214
+ # ========================================================================
215
+
216
+ # @return [Connection]
217
+ attr_reader :stdin
218
+
219
+ # @return [Connection]
220
+ attr_reader :stdout
221
+
222
+ # @return [Connection]
223
+ attr_reader :stderr
224
+
225
+ # @return [Connection]
226
+ attr_reader :log
227
+
228
+
229
+ # Construction
230
+ # ========================================================================
231
+
232
+ # Instantiate a new `QB::IPC::STDIO::Client`.
233
+ def initialize
234
+ @stdin = Connection.new name: :in, type: :in
235
+ @stdout = Connection.new name: :out, type: :out
236
+ @stderr = Connection.new name: :err, type: :out
237
+ @log = Connection.new name: :log, type: :out
238
+ end # #initialize
239
+
240
+
241
+ # Instance Methods
242
+ # ========================================================================
243
+
244
+ # @return [Array<Connection>]
245
+ # The three {Connection} instances.
246
+ def connections
247
+ [ @stdin, @stdout, @stderr, @log ]
248
+ end # #connections
249
+
250
+
251
+ # Attempt to connect the three streams.
252
+ #
253
+ # @return [self]
254
+ #
255
+ def connect!
256
+ connections.each &:connect!
257
+ self
258
+ end # #start!
259
+
260
+
261
+
262
+ def disconnect!
263
+ connections.each &:disconnect!
264
+ self
265
+ end
266
+
267
+ end # class QB::IPC::STDIO::Client