sneaql 0.0.10-java → 0.0.12-java

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae5ae54b32bafed56eb242abd18f312b82bf409d
4
- data.tar.gz: dea557c2ff1e5cbacc6cad37061808973d15133e
3
+ metadata.gz: 782dd6823d85946ec67bf1f3386df376fd73fe75
4
+ data.tar.gz: 8579df76b676d3b3ad6a8cbc868940c9c98ae106
5
5
  SHA512:
6
- metadata.gz: f0ff329c317efd9c6d01b3df6a9adb33e43eb09538cd419690c5def60227d3eab854df88cc8dc8e6db43e72dc4ffb2967c9628b1d476fe6c5f9447e435f0e2b7
7
- data.tar.gz: 77eb3b2b2886cda59f4f87661b1ec4a49d91310644866c62e93e8549b4368316634f4a9263ea5b8d931f44819f1871718ee7f58f09b490bf672ca3b7ba354cab
6
+ metadata.gz: d690724dc1c9233b4ed2377bf54c4aa43f2a5aa9c2dd4cd23ae8b112d508aea340a8df0c486fec07b6fa53d2175e2b0160c0a7f37157f31721b931b9a13cba7b
7
+ data.tar.gz: c8f1073dad3e852eb85e58758d5af6fe09093a9a9e2bd78334f1cd1764466c722e6ac3fffbbf4348911d0e84a19cece36c142005912081789c913a88e27162e6
data/bin/sneaql CHANGED
@@ -268,6 +268,22 @@ the above will execute the transform in the current directory. note that sneaql
268
268
  exit 1
269
269
  end
270
270
 
271
+ desc "containerize PATH_TO_TRANFORM_ROOT CONTAINER_TAG", "build a docker container out of this transform"
272
+ long_desc <<-LONGDESC
273
+ builds a runnable docker image from the specified transform.
274
+
275
+ EXAMPLE \n
276
+ $ sneaql containerize . my-transform-name:0.0.1\n
277
+ the above will build a transform named my-transform-name:0.0.1 based upon the contents of the sneaql.json file in the provided (current) directory
278
+ LONGDESC
279
+
280
+ def containerize(repo_dir, container_tag)
281
+ Sneaql::Docker::LocalTransformDockerfile.new(
282
+ repo_dir,
283
+ container_tag
284
+ )
285
+ end
286
+
271
287
  end
272
288
  end
273
289
  end
data/lib/sneaql.rb CHANGED
@@ -12,6 +12,7 @@ require_relative 'sneaql_lib/expressions.rb'
12
12
  require_relative 'sneaql_lib/recordset.rb'
13
13
  require_relative 'sneaql_lib/database_manager.rb'
14
14
  require_relative 'sneaql_lib/standard_db_objects.rb'
15
+ require_relative 'sneaql_lib/docker.rb'
15
16
 
16
17
  # module for sneaql
17
18
  module Sneaql
@@ -112,7 +113,7 @@ module Sneaql
112
113
  @logger.info("#{@transform_name} validation time #{@end_time - @start_time}s")
113
114
  @logger.info("#{@transform_name} exit code: #{@exit_code} status: #{@status}")
114
115
  end
115
-
116
+
116
117
  # Runs the actual transform.
117
118
  def run
118
119
  @expression_handler = create_expression_handler
@@ -155,7 +156,7 @@ module Sneaql
155
156
  # Creates an ExpressionHandler object
156
157
  # @return [Sneaql::Core::ExpressionHandler]
157
158
  def create_expression_handler
158
- Sneaql::Core::ExpressionHandler.new(ENV, @logger)
159
+ Sneaql::Core::ExpressionHandler.new(@logger)
159
160
  end
160
161
 
161
162
  # Creates a RepoDownloadManager object
@@ -0,0 +1,59 @@
1
+ require 'json'
2
+
3
+ module Sneaql
4
+ module Docker
5
+ class LocalTransformDockerfile
6
+
7
+ def initialize(repo_dir, repo_tag)
8
+ @repo_dir = repo_dir
9
+ @repo_tag = repo_tag
10
+ @steps = JSON.parse(
11
+ File.read("#{repo_dir}/sneaql.json")
12
+ )
13
+
14
+ create_step_files
15
+ create_dockerfile
16
+ end
17
+
18
+ def create_step_files()
19
+ @step_files = []
20
+ @step_files << {
21
+ docker_path: 'sneaql.json',
22
+ local_path: 'sneaql.json' #File.expand_path("#{repo_dir}/sneaql.json")
23
+ }
24
+
25
+ @steps.each { |s|
26
+ @step_files << {
27
+ docker_path: s['step_file'],
28
+ local_path: s['step_file'] # File.expand_path(s['step_file'])
29
+ }
30
+ }
31
+ end
32
+
33
+ def dockerfile()
34
+ %{FROM sneaql:0.0.1
35
+ RUN mkdir /tmp/repo
36
+ #{@step_files.map {|s| "ADD #{s[:local_path]} /tmp/repo/#{s[:docker_path]}"}.join("\n")}
37
+ }
38
+ end
39
+
40
+ def create_dockerfile
41
+ Dir.chdir(@repo_dir) do
42
+ puts "creating Dockerfile..."
43
+ puts
44
+ create_step_files
45
+ puts dockerfile
46
+ f = File.open('Dockerfile', 'w')
47
+ f.puts(dockerfile)
48
+ f.close
49
+ puts
50
+ puts "building docker image..."
51
+ puts `docker build --no-cache -t #{@repo_tag} . `
52
+ #Docker::Image.build_from_dir('.')
53
+ puts
54
+ puts "image build complete"
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -9,9 +9,9 @@ module Sneaql
9
9
  class ExpressionHandler
10
10
  # @param [Hash] environment_variables pass in a set of ENV
11
11
  # @param [Logger] logger object otherwise will default to new Logger
12
- def initialize(environment_variables, logger = nil)
12
+ def initialize(logger = nil)
13
13
  @logger = logger ? logger : Logger.new(STDOUT)
14
- @environment_variables = environment_variables
14
+ @environment_variables = filtered_environment_variables
15
15
  @session_variables = {}
16
16
  end
17
17
 
@@ -233,6 +233,23 @@ module Sneaql
233
233
  def wildcard_to_regex(wildcard)
234
234
  Regexp.new("^#{wildcard}$".gsub('%','.*').gsub('_','.'))
235
235
  end
236
+
237
+ # create a hash built from supplied environment variables.
238
+ # if SNEAQL_AVAILABLE_ENV_VARS is provided (as a comma delimited list)
239
+ # only the listed values are included.
240
+ # return <Hash>
241
+ def filtered_environment_variables
242
+ env_vars = {}
243
+ if ENV['SNEAQL_AVAILABLE_ENV_VARS']
244
+ @logger.debug("filtering environment variables")
245
+ available = ENV['SNEAQL_AVAILABLE_ENV_VARS'].split(',')
246
+ ENV.keys.each { |k| env_vars[k] = ENV[k] if available.include?(k) }
247
+ else
248
+ @logger.debug("setting environment variables")
249
+ ENV.keys.each { |k| env_vars[k] = ENV[k] }
250
+ end
251
+ return env_vars
252
+ end
236
253
  end
237
254
  end
238
255
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sneaql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.12
5
5
  platform: java
6
6
  authors:
7
7
  - jeremy winters
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-31 00:00:00.000000000 Z
11
+ date: 2017-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -123,6 +123,7 @@ files:
123
123
  - lib/sneaql_lib/database_prefs/redshift.rb
124
124
  - lib/sneaql_lib/database_prefs/sqlite.rb
125
125
  - lib/sneaql_lib/database_prefs/vertica.rb
126
+ - lib/sneaql_lib/docker.rb
126
127
  - lib/sneaql_lib/exceptions.rb
127
128
  - lib/sneaql_lib/expressions.rb
128
129
  - lib/sneaql_lib/lock_manager.rb