rumbda-alt 0.0.1
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 +7 -0
- data/bin/rumbda +24 -0
- data/lambda/bundler-config +3 -0
- data/lambda/index.js +36 -0
- data/lambda/ruby_wrapper.sh +13 -0
- data/lib/rumbda/build.rb +134 -0
- data/lib/rumbda/init.rb +48 -0
- data/lib/rumbda/version.rb +3 -0
- data/lib/rumbda.rb +6 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d42f3916b295b4cf8a1b3b36475405f5e899ed7b
|
4
|
+
data.tar.gz: 7cd0459282e1591495436c156075804835775e22
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 651b93fe084f8a61484b8ce3c23f77d8f34af18750ee31363e865cf8a9eee8aa06df8e0f4e51792d427f0e8ae33f780c3e2ce5ea36b249f302eacd7d4f71a866
|
7
|
+
data.tar.gz: 714092113f599ec13eee3348d85f945ad8707b616ca5c312b57788ce44cc6073e7f5e917c616e9ea65bf8b7e0d8b16d149f0e4963324aa7ff8587ba45d6ea340
|
data/bin/rumbda
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rumbda'
|
4
|
+
|
5
|
+
class RumbdaCLI < Thor
|
6
|
+
desc 'build', 'Builds the zip file for lambda.'
|
7
|
+
method_option 'cleanup', type: :boolean, aliases: '-c'
|
8
|
+
def build
|
9
|
+
Rumbda::Build.run(FileUtils.pwd, options)
|
10
|
+
end
|
11
|
+
|
12
|
+
desc 'init', 'Sets up the current directory as a rumbda project (creates `source/main.rb`, `.ruby-version`, `Gemfile`, and `.gitignore`).'
|
13
|
+
def init
|
14
|
+
Rumbda::Init.run(FileUtils.pwd)
|
15
|
+
end
|
16
|
+
|
17
|
+
map '-v' => :version, '--version' => :version
|
18
|
+
desc '-v (--version)', 'Outputs the version of rumbda.'
|
19
|
+
def version
|
20
|
+
puts Rumbda::VERSION
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
RumbdaCLI.start(ARGV)
|
data/lambda/index.js
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
/* const exec = require('child_process').exec;
|
2
|
+
|
3
|
+
exports.handler = function(event, context) {
|
4
|
+
const child = exec('./ruby_wrapper ' + "'" + JSON.stringify(event) + "'", (result) => {
|
5
|
+
// Resolve with result of process
|
6
|
+
context.done(result);
|
7
|
+
});
|
8
|
+
|
9
|
+
// Log process stdout and stderr
|
10
|
+
child.stdout.on('data', console.log);
|
11
|
+
child.stderr.on('data', console.error);
|
12
|
+
}
|
13
|
+
*/
|
14
|
+
|
15
|
+
|
16
|
+
var spawn = require('child_process').spawn;
|
17
|
+
|
18
|
+
var invokeRubyApp = "./ruby_wrapper";
|
19
|
+
|
20
|
+
exports.handler = function(event, context) {
|
21
|
+
console.log("Starting process: " + invokeRubyApp);
|
22
|
+
var child = spawn(invokeRubyApp, [JSON.stringify(event, null, 2), JSON.stringify(context, null, 2)]);
|
23
|
+
|
24
|
+
child.stdout.on('data', function (data) { console.log("stdout:\n"+data); });
|
25
|
+
child.stderr.on('data', function (data) { console.log("stderr:\n"+data); });
|
26
|
+
|
27
|
+
child.on('close', function (code) {
|
28
|
+
if(code === 0) {
|
29
|
+
context.succeed("Process completed: " + invokeRubyApp);
|
30
|
+
} else {
|
31
|
+
context.fail("Process \"" + invokeRubyApp + "\" exited with code: " + code);
|
32
|
+
}
|
33
|
+
});
|
34
|
+
}
|
35
|
+
|
36
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
set -e
|
3
|
+
|
4
|
+
# Figure out where this script is located.
|
5
|
+
SELFDIR="`dirname \"$0\"`"
|
6
|
+
SELFDIR="`cd \"$SELFDIR\" && pwd`"
|
7
|
+
|
8
|
+
# Tell Bundler where the Gemfile and gems are.
|
9
|
+
export BUNDLE_GEMFILE="$SELFDIR/vendor/Gemfile"
|
10
|
+
unset BUNDLE_IGNORE_CONFIG
|
11
|
+
|
12
|
+
# Run the actual app using the bundled Ruby interpreter, with Bundler activated.
|
13
|
+
exec "$SELFDIR/ruby/bin/ruby" -rbundler/setup "$SELFDIR/source/main.rb" "$@"
|
data/lib/rumbda/build.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
module Rumbda
|
2
|
+
class Build
|
3
|
+
TRAVELING_RUBY_VERSION = '20150715-2.2.2'.freeze
|
4
|
+
LINUX_VERSION = 'linux-x86_64'.freeze
|
5
|
+
TEMP_DIRECTORY_NAME = 'tmp_rumbda'.freeze
|
6
|
+
|
7
|
+
# TODO: fix using . or .. for dir_to_build
|
8
|
+
def self.run(dir_to_build, options)
|
9
|
+
check_for_files(dir_to_build)
|
10
|
+
|
11
|
+
temp_dir = File.join(FileUtils.pwd, TEMP_DIRECTORY_NAME)
|
12
|
+
dest_source_code_dir = File.join(temp_dir, 'source')
|
13
|
+
|
14
|
+
vendor_dir = File.join(temp_dir, 'vendor')
|
15
|
+
|
16
|
+
FileUtils.mkdir_p(dest_source_code_dir)
|
17
|
+
FileUtils.mkdir_p(vendor_dir)
|
18
|
+
FileUtils.cp_r(Dir.glob(File.join(dir_to_build, 'source', '*')), dest_source_code_dir)
|
19
|
+
FileUtils.cp_r(File.join(dir_to_build, 'Gemfile'), dest_source_code_dir)
|
20
|
+
FileUtils.cp_r(File.join(dir_to_build, 'Gemfile.lock'), dest_source_code_dir)
|
21
|
+
FileUtils.mv(File.join(dest_source_code_dir, 'Gemfile'), vendor_dir)
|
22
|
+
FileUtils.mv(File.join(dest_source_code_dir, 'Gemfile.lock'), vendor_dir)
|
23
|
+
|
24
|
+
Dir.chdir(TEMP_DIRECTORY_NAME) do
|
25
|
+
bundle_install(vendor_dir)
|
26
|
+
|
27
|
+
if Dir.exist?('ruby')
|
28
|
+
puts "Found traveling ruby in #{TEMP_DIRECTORY_NAME}, skipping download."
|
29
|
+
else
|
30
|
+
download_traveling_ruby(TRAVELING_RUBY_VERSION, LINUX_VERSION)
|
31
|
+
unpack_traveling_ruby(TRAVELING_RUBY_VERSION, LINUX_VERSION, 'ruby')
|
32
|
+
end
|
33
|
+
|
34
|
+
copy_bundler_config(
|
35
|
+
File.expand_path(File.join('..', '..', '..', 'lambda', 'bundler-config'), __FILE__),
|
36
|
+
File.join(vendor_dir, '.bundle')
|
37
|
+
)
|
38
|
+
|
39
|
+
copy_wrapper_script(
|
40
|
+
File.expand_path(File.join('..', '..', '..', 'lambda', 'ruby_wrapper.sh'), __FILE__),
|
41
|
+
'ruby_wrapper'
|
42
|
+
)
|
43
|
+
|
44
|
+
FileUtils.cp(
|
45
|
+
File.expand_path(File.join('..', '..', '..', 'lambda', 'index.js'), __FILE__),
|
46
|
+
'index.js'
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
create_zip_file(TEMP_DIRECTORY_NAME, 'index.zip')
|
51
|
+
|
52
|
+
FileUtils.rm_rf(TEMP_DIRECTORY_NAME) if options['cleanup']
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.create_zip_file(source, destination)
|
56
|
+
puts 'Creating zip file.'
|
57
|
+
Dir.chdir(source) do
|
58
|
+
success = system("zip -rq #{File.join('..', destination)} *")
|
59
|
+
abort('Creating zip failed, exiting.') unless success
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.copy_bundler_config(source, destination)
|
64
|
+
puts 'Copying bundler config.'
|
65
|
+
FileUtils.mkdir_p(destination)
|
66
|
+
FileUtils.cp(source, destination)
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.copy_wrapper_script(source, destination)
|
70
|
+
puts 'Copying wrapper script.'
|
71
|
+
FileUtils.cp(source, destination)
|
72
|
+
FileUtils.chmod(0755, destination)
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.bundle_install(dir_with_gemfile)
|
76
|
+
puts 'Installing bundle.'
|
77
|
+
Bundler.with_clean_env do
|
78
|
+
success = system(
|
79
|
+
"cd #{dir_with_gemfile} && " \
|
80
|
+
'env BUNDLE_IGNORE_CONFIG=1 bundle install --path . --without development'
|
81
|
+
)
|
82
|
+
|
83
|
+
abort('Bundle install failed, exiting.') unless success
|
84
|
+
end
|
85
|
+
|
86
|
+
puts 'Bundle install success.'
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.download_traveling_ruby(version, target)
|
90
|
+
puts "Downloading traveling ruby from #{traveling_ruby_url(version, target)}."
|
91
|
+
|
92
|
+
File.open(traveling_ruby_tar_file(version, target), 'wb') do |saved_file|
|
93
|
+
# the following "open" is provided by open-uri
|
94
|
+
open(traveling_ruby_url(version, target), 'rb') do |read_file|
|
95
|
+
saved_file.write(read_file.read)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
puts 'Download complete.'
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.unpack_traveling_ruby(version, target, destination)
|
103
|
+
puts 'Unpacking traveling ruby.'
|
104
|
+
|
105
|
+
FileUtils.mkdir_p(destination)
|
106
|
+
|
107
|
+
success = system("tar -xzf #{traveling_ruby_tar_file(version, target)} -C #{destination}")
|
108
|
+
abort('Unpacking traveling ruby failed') unless success
|
109
|
+
puts 'Unpacking traveling ruby successful.'
|
110
|
+
|
111
|
+
puts 'Removing tar.'
|
112
|
+
FileUtils.rm_rf(traveling_ruby_tar_file(version, target))
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.traveling_ruby_url(version, target)
|
116
|
+
"https://d6r77u77i8pq3.cloudfront.net/releases/traveling-ruby-#{version}-#{target}.tar.gz"
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.traveling_ruby_tar_file(version, target)
|
120
|
+
"traveling-ruby-#{version}-#{target}.tar.gz"
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.check_for_files(dir_to_build)
|
124
|
+
main_rb = File.join(dir_to_build, 'source', 'main.rb')
|
125
|
+
abort("Must have file #{main_rb}") unless File.exist?(main_rb)
|
126
|
+
|
127
|
+
gemfile = File.join(dir_to_build, 'Gemfile')
|
128
|
+
abort("Must have file #{gemfile}") unless File.exist?(gemfile)
|
129
|
+
|
130
|
+
gemfile_lock = File.join(dir_to_build, 'Gemfile.lock')
|
131
|
+
abort("Must have file #{gemfile_lock}") unless File.exist?(gemfile_lock)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
data/lib/rumbda/init.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module Rumbda
|
2
|
+
GEMFILE_CONTENTS = <<-HEREDOC
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# add runtime dependencies here, they will be included in the index.zip
|
6
|
+
|
7
|
+
# This is the aws ruby sdk provides a ruby client for interacting with AWS apis.
|
8
|
+
# gem 'aws-sdk'
|
9
|
+
|
10
|
+
# DO NOT REMOVE; bundler version MUST match the version that the traveling ruby uses, which is currently 1.9.9.
|
11
|
+
gem 'bundler', '= 1.9.9'
|
12
|
+
|
13
|
+
# gems in the development group will not be included in the index.zip
|
14
|
+
group :development do
|
15
|
+
gem 'rumbda'
|
16
|
+
end
|
17
|
+
HEREDOC
|
18
|
+
RUBY_VERSION_FILE_CONTENTS = '2.2.2'.freeze
|
19
|
+
GITIGNORE_FILE_CONTENTS = "tmp_rumbda\nindex.zip".freeze
|
20
|
+
|
21
|
+
class Init
|
22
|
+
def self.run(directory)
|
23
|
+
source_dir = File.join(directory, 'source')
|
24
|
+
FileUtils.mkdir(source_dir)
|
25
|
+
puts "Created: #{source_dir}"
|
26
|
+
|
27
|
+
main_rb = File.join(source_dir, 'main.rb')
|
28
|
+
FileUtils.touch(main_rb)
|
29
|
+
puts "Created: #{main_rb}"
|
30
|
+
|
31
|
+
ruby_version_file = File.join(directory, '.ruby-version')
|
32
|
+
FileUtils.touch(ruby_version_file)
|
33
|
+
File.open(ruby_version_file, 'a') { |f| f.puts RUBY_VERSION_FILE_CONTENTS }
|
34
|
+
puts "Created: #{ruby_version_file}"
|
35
|
+
|
36
|
+
gitignore_file = File.join(directory, '.gitignore')
|
37
|
+
FileUtils.touch(gitignore_file)
|
38
|
+
File.open(gitignore_file, 'a') { |f| f.puts GITIGNORE_FILE_CONTENTS }
|
39
|
+
puts "Created: #{gitignore_file}"
|
40
|
+
|
41
|
+
gemfile = File.join(directory, 'Gemfile')
|
42
|
+
FileUtils.touch(gemfile)
|
43
|
+
File.open(gemfile, 'a') do |f|
|
44
|
+
f.puts GEMFILE_CONTENTS
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/rumbda.rb
ADDED
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rumbda-alt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kleaver
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.19'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.19'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.9.9
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.9.9
|
41
|
+
description: Run ruby scripts on aws lambda.
|
42
|
+
email: []
|
43
|
+
executables:
|
44
|
+
- rumbda
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- bin/rumbda
|
49
|
+
- lambda/bundler-config
|
50
|
+
- lambda/index.js
|
51
|
+
- lambda/ruby_wrapper.sh
|
52
|
+
- lib/rumbda.rb
|
53
|
+
- lib/rumbda/build.rb
|
54
|
+
- lib/rumbda/init.rb
|
55
|
+
- lib/rumbda/version.rb
|
56
|
+
homepage: https://github.com/kleaver/rumbda
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.4.8
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Easily run ruby on lambda!
|
80
|
+
test_files: []
|