jarbs 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8aee7bfc746ed5e58dfd6577850abab88c2c09d4
4
- data.tar.gz: 5fb103e40bce30237c937ef469b35830a83253fc
3
+ metadata.gz: 5bccaf78f308809bfd3db697d8ce78253dd09397
4
+ data.tar.gz: e5c01044236be1a93eace8106f9464d5ffc91fb5
5
5
  SHA512:
6
- metadata.gz: 5e9bb53cf84b6df0e0da406859c7a6ad48b8a94c531997888010154b86e39f6bfac5774372e7acea2e8eb9f777047959135dbace13ff78ff3d886588ee03591f
7
- data.tar.gz: 12d91612386943a5172caee840032a3896283d85f479f646083dffd4d33c846625153a2db9fe7017ed3cf8fdeb51f496e98da6b6619acc7aaea67acc3663a4b9
6
+ metadata.gz: 7dd415e13e4e86ca2d55133b162c7b404b97c3685ad4c215e3e7926945e194b8f6f973ab10db78c02213089b03a40160669c20420a008ff9456ceb7c08f093a5
7
+ data.tar.gz: e83e3b3003ccaa8acf3fc1268a055100c482ee7e770700f0b3a8769f62de32d31e5c7e3a6f9dbc56e10a0bce400a5472be2deed34d1a79d76cde5bc02a600f5d
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Articulate Global, Inc
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -10,15 +10,13 @@ Currently we distributed the `jarbs` runtime via gems hosted by RubyGems.org.
10
10
 
11
11
  `gem install jarbs`
12
12
 
13
- If this is a new machine or you haven't had to install any C extentions for Ruby yet, you may also need `cmake` before this gem will install: `brew install cmake`. We're looking at options for eliminating this step.
14
-
15
13
  ## Usage
16
14
 
17
15
  For the most up-to-date documentation and usage, run `jarbs -h`
18
16
 
19
17
  ### Generate a new lambda project:
20
18
 
21
- `lambda new my-function`
19
+ `jarbs new my-function`
22
20
 
23
21
  This produces:
24
22
 
@@ -36,7 +34,7 @@ This produces:
36
34
 
37
35
  (while in the project folder created above):
38
36
 
39
- `lambda new other-function`
37
+ `jarbs new other-function`
40
38
 
41
39
  Your project will then look like:
42
40
 
@@ -78,5 +76,5 @@ Will destroy the lambda function on AWS (will still leave files in your lambdas
78
76
 
79
77
  ## License
80
78
 
81
- *MIT*
79
+ This software is provided under the the [MIT license](LICENSE).
82
80
 
data/Rakefile CHANGED
@@ -1,11 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
- require 'jarbs/version'
3
- # require "rake/testtask"
2
+ require "rake/testtask"
4
3
 
5
- # Rake::TestTask.new(:test) do |t|
6
- # t.libs << "test"
7
- # t.libs << "lib"
8
- # t.test_files = FileList['test/**/*_test.rb']
9
- # end
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
10
9
 
11
- # task :default => :test
10
+ task :default => :test
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["hungerandthirst@gmail.com"]
11
11
 
12
12
  spec.summary = %q{Jarbs: CLI Tooling for Lambda}
13
- spec.description = %q{Jarbs: They took em.}
13
+ spec.description = %q{Jarbs: They took 'em.}
14
14
  spec.homepage = "https://docs.articulate.zone/tools/jarbs.html"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -20,9 +20,11 @@ Gem::Specification.new do |spec|
20
20
  spec.add_dependency "commander"
21
21
  spec.add_dependency "aws-sdk", "~> 2"
22
22
  spec.add_dependency "rubyzip"
23
- spec.add_dependency "rugged"
23
+ spec.add_dependency "crash-reporter"
24
+ spec.add_dependency "octokit"
24
25
 
25
26
  spec.add_development_dependency "bundler", "~> 1.10"
26
27
  spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "minitest"
27
29
  spec.add_development_dependency "pry"
28
30
  end
@@ -2,7 +2,12 @@ require 'rubygems'
2
2
  require 'fileutils'
3
3
  require 'commander'
4
4
 
5
+ require 'crash_reporter'
6
+ require 'crash_reporter/reporters/github_issues'
7
+
5
8
  require 'jarbs/version'
9
+ require 'jarbs/config'
10
+ require 'jarbs/github_auth'
6
11
  require 'jarbs/lambda'
7
12
 
8
13
  module Jarbs
@@ -11,6 +16,17 @@ module Jarbs
11
16
 
12
17
  GLOBAL_DEFAULTS = { env: 'dev' }
13
18
 
19
+ def initialize
20
+ @config = Config.new
21
+
22
+ if @config.get('crashes.report')
23
+ CrashReporter.configure do |c|
24
+ c.engines = [CrashReporter::GithubIssues.new('articulate/jarbs', @config.get('github.token'))]
25
+ c.version = Jarbs::VERSION
26
+ end
27
+ end
28
+ end
29
+
14
30
  def run
15
31
  program :version, Jarbs::VERSION
16
32
  program :description, 'Lambda Tooling'
@@ -20,27 +36,19 @@ module Jarbs
20
36
 
21
37
  command :new do |c|
22
38
  c.syntax = 'jarbs new [options] name'
23
- c.summary = "Generate a new lambda function skeleton"
39
+ c.summary = "Generate a new lambda function or project skeleton"
24
40
  c.option "-f", "--force", "Force overwrite of existing function definition"
25
41
  c.action do |args, options|
26
42
  name = args.shift || abort("Must provide a lambda name")
27
43
  options.default GLOBAL_DEFAULTS
28
44
 
29
- if Dir.exists? name
30
- if options.force
31
- FileUtils.rm_r name
32
- else
33
- abort("Function exists. Use the -f flag to force overwrite.")
34
- end
35
- end
45
+ lambda = Lambda.new(name, options)
36
46
 
37
- # create project dir if doesn't exist yet
38
- if !Dir.exists?('lambdas')
39
- ProjectGenerator.new(name).generate
40
- Dir.chdir name
41
- end
47
+ project_exists?(name, remove: options.force)
48
+ lambda_exists?(lambda, remove: options.force)
42
49
 
43
- Lambda.new(name, options).generate
50
+ generate_project(name) unless jarbs_project?
51
+ lambda.generate
44
52
  end
45
53
  end
46
54
 
@@ -52,7 +60,11 @@ module Jarbs
52
60
  name = args.shift || abort('Name argument required')
53
61
  options.default GLOBAL_DEFAULTS
54
62
 
55
- Lambda.new(name, options).deploy
63
+ lambda = Lambda.new(name, options)
64
+
65
+ abort("Lambda '#{name}' does not exist.") unless lambda.exists?
66
+
67
+ lambda.deploy
56
68
  end
57
69
  end
58
70
 
@@ -60,7 +72,7 @@ module Jarbs
60
72
  c.syntax = 'jarbs rm NAME [NAME...]'
61
73
  c.summary = "Delete a lambda function"
62
74
  c.action do |args, options|
63
- name = args.shift || abort('Name argument required')
75
+ abort('Name argument required') if args.empty?
64
76
  options.default GLOBAL_DEFAULTS
65
77
 
66
78
  begin
@@ -76,7 +88,58 @@ module Jarbs
76
88
  end
77
89
  end
78
90
 
91
+ command :ls do |c|
92
+ c.syntax = 'jarbs ls'
93
+ c.summary = "List lambda functions in this project"
94
+ c.action do |args, options|
95
+ lambdas = Dir.glob("lambdas/*").map {|x| Lambda.new(File.basename(x), options) }
96
+
97
+ lambdas.each do |l|
98
+ say "#{l.function.name}: #{l.function.description}"
99
+ end
100
+ end
101
+ end
102
+
79
103
  run!
80
104
  end
105
+
106
+ private
107
+
108
+ def project_exists?(name, remove: false)
109
+ if Dir.exists? name
110
+ if remove
111
+ FileUtils.rm_r name
112
+ else
113
+ abort("Project #{name} exists. Use the -f flag to force overwrite.")
114
+ end
115
+ end
116
+ end
117
+
118
+ def lambda_exists?(lambda, remove: false)
119
+ if lambda.function.exists?
120
+ if remove
121
+ lambda.function.remove!
122
+ else
123
+ abort("Function #{lambda.name} exists. Use the -f flag to force overwrite.")
124
+ end
125
+ end
126
+ end
127
+
128
+ def jarbs_project?
129
+ File.exists?('.jarbs')
130
+ end
131
+
132
+ def generate_project(name)
133
+ ProjectGenerator.new(name).generate
134
+
135
+ # run future commands in the new jarbs dir
136
+ Dir.chdir name
137
+
138
+ # create a config inside of the new project dir
139
+ config = Config.new
140
+ autolog = config.get('crashes.report') { agree("Would you like to log jarbs crashes to GitHub automatically (y/n)? ") }
141
+
142
+ GithubAuth.new(config).generate_token if autolog
143
+ end
81
144
  end
82
145
  end
@@ -0,0 +1,40 @@
1
+ module Jarbs
2
+ class Config
3
+ FILE_NAME = '.jarbs'
4
+
5
+ def initialize(file=FILE_NAME)
6
+ @file = file
7
+ @config = read
8
+ end
9
+
10
+ def set(key, value)
11
+ @config[key] = value
12
+ finalize
13
+ end
14
+
15
+ def get(key, &block)
16
+ val = @config[key]
17
+
18
+ if !val && block_given?
19
+ val = yield
20
+ set(key, val)
21
+ end
22
+
23
+ val
24
+ end
25
+
26
+ private
27
+
28
+ def finalize
29
+ File.open(@file, 'w') {|f| f.write JSON.pretty_generate(@config) }
30
+ end
31
+
32
+ def read
33
+ if File.exists? @file
34
+ JSON.parse(File.read(@file))
35
+ else
36
+ {}
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,6 +1,11 @@
1
+ require 'forwardable'
2
+
1
3
  module Jarbs
2
4
  class FunctionDefinition
5
+ extend Forwardable
6
+
3
7
  attr_reader :env, :name, :root_path
8
+ def_delegators :manifest, :description
4
9
 
5
10
  def initialize(name, env='dev')
6
11
  @env = env
@@ -8,8 +13,16 @@ module Jarbs
8
13
  @root_path = File.join('lambdas', name)
9
14
  end
10
15
 
16
+ def exists?
17
+ Dir.exists? root_path
18
+ end
19
+
20
+ def remove!
21
+ FileUtils.rm_r root_path
22
+ end
23
+
11
24
  def manifest
12
- @manifest ||= JSON.parse File.read(manifest_file)
25
+ @manifest ||= OpenStruct.new JSON.parse(File.read(manifest_file))
13
26
  end
14
27
 
15
28
  def manifest_file
@@ -0,0 +1,22 @@
1
+ require 'octokit'
2
+
3
+ module Jarbs
4
+ class GithubAuth
5
+ include Commander::UI
6
+
7
+ def initialize(config)
8
+ @config = config
9
+ @client = Octokit::Client.new \
10
+ login: @config.get('github.username') { ask('GitHub username: ') },
11
+ password: password('Password (not saved): ')
12
+ end
13
+
14
+ def generate_token
15
+ resp = @client.create_authorization scopes: ['public_repo'],
16
+ note: 'Jarbs error reporting',
17
+ headers: { 'X-GitHub-OTP' => ask('GitHub two-factor token: ') }
18
+
19
+ @config.set('github.token', resp.token)
20
+ end
21
+ end
22
+ end
@@ -10,6 +10,9 @@ require 'jarbs/packager'
10
10
  module Jarbs
11
11
  class Lambda
12
12
  include Commander::UI
13
+ include CrashReporter::DSL
14
+
15
+ attr_accessor :function
13
16
 
14
17
  def initialize(name, options)
15
18
  @options = options
@@ -23,7 +26,7 @@ module Jarbs
23
26
  end
24
27
 
25
28
  def deploy
26
- exists? ? update : create
29
+ deployed? ? update : create
27
30
  end
28
31
 
29
32
  def create
@@ -31,13 +34,16 @@ module Jarbs
31
34
  role = @options[:role] || ask("IAM role for function: ")
32
35
 
33
36
  say "Creating #{@function.env_name} on Lambda..."
34
- @client.create_function function_name: @function.env_name,
35
- runtime: 'nodejs',
36
- handler: 'index.handler',
37
- role: role,
38
- memory_size: 128,
39
- timeout: 10,
40
- code: { zip_file: data }
37
+
38
+ capture_errors do
39
+ @client.create_function function_name: @function.env_name,
40
+ runtime: 'nodejs',
41
+ handler: 'index.handler',
42
+ role: role,
43
+ memory_size: 128,
44
+ timeout: 10,
45
+ code: { zip_file: data }
46
+ end
41
47
 
42
48
  say_ok "Complete!"
43
49
  end
@@ -46,7 +52,11 @@ module Jarbs
46
52
  data = prepare_for_aws
47
53
 
48
54
  say "Updating #{@function.env_name} on Lambda..."
49
- @client.update_function_code function_name: @function.env_name, zip_file: data
55
+
56
+ capture_errors do
57
+ @client.update_function_code function_name: @function.env_name, zip_file: data
58
+ end
59
+
50
60
  say_ok "Complete!"
51
61
  end
52
62
 
@@ -59,12 +69,16 @@ module Jarbs
59
69
  @client.get_function(function_name: @function.env_name)
60
70
  end
61
71
 
62
- def exists?
72
+ def deployed?
63
73
  true if info
64
74
  rescue Aws::Lambda::Errors::ResourceNotFoundException => e
65
75
  false
66
76
  end
67
77
 
78
+ def exists?
79
+ Dir.exists? function.source_path
80
+ end
81
+
68
82
  private
69
83
 
70
84
  def prepare_for_aws
@@ -1,5 +1,3 @@
1
- require 'rugged'
2
-
3
1
  module Jarbs
4
2
  module ManifestHelpers
5
3
 
@@ -14,9 +12,7 @@ module Jarbs
14
12
  end
15
13
 
16
14
  def repo_url
17
- Rugged::Repository.discover(".").remotes.first.url
18
- rescue Rugged::RepositoryError => e
19
- nil
15
+ @repo_url ||= `git config --get remote.origin.url`.chomp
20
16
  end
21
17
  end
22
18
  end
@@ -1,13 +1,14 @@
1
1
  module Jarbs
2
2
  class NodeBuild
3
3
  include Commander::UI
4
+ include CrashReporter::DSL
4
5
 
5
6
  def initialize(function)
6
7
  @function = function
7
8
  end
8
9
 
9
10
  def npm_install(path, flags="")
10
- run_in path, "npm install #{flags}"
11
+ capture_errors { run_in(path, "npm install #{flags}") }
11
12
  end
12
13
 
13
14
  def npm_build
@@ -15,9 +16,12 @@ module Jarbs
15
16
 
16
17
  # Copy source dir to build location and build in-place
17
18
  FileUtils.cp_r @function.source_path, @function.build_path
18
- abortable_run "npm run build:function -- --out-dir #{@function.build_path} #{@function.source_path}"
19
19
 
20
- npm_install @function.build_path, '--production'
20
+ capture_errors do
21
+ abortable_run "npm run build:function -- --out-dir #{@function.build_path} #{@function.source_path}"
22
+
23
+ npm_install @function.build_path, '--production'
24
+ end
21
25
  end
22
26
 
23
27
  def clean
@@ -1,14 +1,11 @@
1
1
  module Jarbs
2
2
  class ProjectGenerator
3
3
  include ManifestHelpers
4
-
5
4
  def initialize(name)
6
5
  @name = name
7
6
  end
8
7
 
9
8
  def generate
10
- FileUtils.mkdir @name
11
-
12
9
  manifest = {
13
10
  name: @name,
14
11
  version: '0.0.0',
@@ -31,7 +28,9 @@ module Jarbs
31
28
  }
32
29
  }
33
30
 
31
+ FileUtils.mkdir @name
34
32
  write_package(manifest, @name)
33
+
35
34
  NodeBuild.new(nil).npm_install(@name)
36
35
  end
37
36
  end
@@ -1,3 +1,3 @@
1
1
  module Jarbs
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jarbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke van der Hoeven
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-04 00:00:00.000000000 Z
11
+ date: 2015-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -53,7 +53,21 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rugged
56
+ name: crash-reporter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: octokit
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
@@ -94,6 +108,20 @@ dependencies:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
110
  version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: pry
99
127
  requirement: !ruby/object:Gem::Requirement
@@ -108,7 +136,7 @@ dependencies:
108
136
  - - ">="
109
137
  - !ruby/object:Gem::Version
110
138
  version: '0'
111
- description: 'Jarbs: They took em.'
139
+ description: 'Jarbs: They took ''em.'
112
140
  email:
113
141
  - hungerandthirst@gmail.com
114
142
  executables:
@@ -119,6 +147,7 @@ files:
119
147
  - ".gitignore"
120
148
  - Gemfile
121
149
  - Gemfile.lock
150
+ - LICENSE
122
151
  - README.md
123
152
  - Rakefile
124
153
  - bin/console
@@ -126,9 +155,11 @@ files:
126
155
  - bin/setup
127
156
  - jarbs.gemspec
128
157
  - lib/jarbs.rb
158
+ - lib/jarbs/config.rb
129
159
  - lib/jarbs/fixtures/index.js
130
160
  - lib/jarbs/function_definition.rb
131
161
  - lib/jarbs/function_generator.rb
162
+ - lib/jarbs/github_auth.rb
132
163
  - lib/jarbs/lambda.rb
133
164
  - lib/jarbs/manifest_helpers.rb
134
165
  - lib/jarbs/node_build.rb
@@ -154,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
185
  version: '0'
155
186
  requirements: []
156
187
  rubyforge_project:
157
- rubygems_version: 2.4.8
188
+ rubygems_version: 2.4.5.1
158
189
  signing_key:
159
190
  specification_version: 4
160
191
  summary: 'Jarbs: CLI Tooling for Lambda'