rumbda 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f5229a3f1c9dbabbd4baf34d7b4cd76e2865f0a1
4
+ data.tar.gz: ab764a0cb99c5abb131efd9441c54bda1118633d
5
+ SHA512:
6
+ metadata.gz: 12ee1574e3a7ada150d150c93f07c3879792dc59e0c5bfe92fda95a15eddeb399070aa1841019d10119e63b461227680aa95b3d9f6675f1a279f7369211d9dfd
7
+ data.tar.gz: 14c96fc7c03407f8f66e7ca60f2a0ff937785476b2b05ea3094a606befc24bd490a9d86843a866d4d4730f35c29da1021e05d6310212231a2683bd1fb920d984
@@ -0,0 +1,21 @@
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(dir_to_build = FileUtils.pwd)
9
+ Rumbda::Build.run(dir_to_build, options)
10
+ end
11
+
12
+ private
13
+
14
+ map '-v' => :version, '--version' => :version
15
+ desc '-v (--version)', 'Outputs the version of rumbda.'
16
+ def version
17
+ puts Rumbda::VERSION
18
+ end
19
+ end
20
+
21
+ RumbdaCLI.start(ARGV)
@@ -0,0 +1,3 @@
1
+ BUNDLE_PATH: .
2
+ BUNDLE_WITHOUT: development
3
+ BUNDLE_DISABLE_SHARED_GEMS: '1'
@@ -0,0 +1,10 @@
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
+ context.done(result);
6
+ });
7
+
8
+ child.stdout.on('data', console.log);
9
+ child.stderr.on('data', console.error);
10
+ };
@@ -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" "$@"
@@ -0,0 +1,7 @@
1
+ require 'thor'
2
+ require 'highline/import'
3
+ require 'open-uri'
4
+ require 'bundler'
5
+ require 'fileutils'
6
+ require 'bundler/setup'
7
+ Dir[File.join(__dir__, 'rumbda', '**', '*.rb')].each { |file| require file }
@@ -0,0 +1,135 @@
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, '*')) - [temp_dir], dest_source_code_dir)
19
+ FileUtils.mv(File.join(dest_source_code_dir, 'Gemfile'), vendor_dir)
20
+ FileUtils.mv(File.join(dest_source_code_dir, 'Gemfile.lock'), vendor_dir)
21
+
22
+ Dir.chdir(TEMP_DIRECTORY_NAME) do
23
+ bundle_install(vendor_dir)
24
+
25
+ if Dir.exist?('ruby')
26
+ puts "Found traveling ruby in #{TEMP_DIRECTORY_NAME}, skipping download."
27
+ else
28
+ download_traveling_ruby(TRAVELING_RUBY_VERSION, LINUX_VERSION)
29
+ unpack_traveling_ruby(TRAVELING_RUBY_VERSION, LINUX_VERSION, 'ruby')
30
+ end
31
+
32
+ copy_bundler_config(
33
+ File.expand_path(File.join('..', '..', '..', 'lambda', 'bundler-config'), __FILE__),
34
+ File.join(vendor_dir, '.bundle')
35
+ )
36
+
37
+ copy_wrapper_script(
38
+ File.expand_path(File.join('..', '..', '..', 'lambda', 'ruby_wrapper.sh'), __FILE__),
39
+ 'ruby_wrapper'
40
+ )
41
+
42
+ FileUtils.cp(
43
+ File.expand_path(File.join('..', '..', '..', 'lambda', 'index.js'), __FILE__),
44
+ 'index.js'
45
+ )
46
+ end
47
+
48
+ create_zip_file(TEMP_DIRECTORY_NAME, 'index.zip')
49
+
50
+ FileUtils.rm_rf(TEMP_DIRECTORY_NAME) if options['cleanup']
51
+ end
52
+
53
+ def self.create_zip_file(source, destination)
54
+ puts 'Creating zip file.'
55
+ Dir.chdir(source) do
56
+ success = system("zip -rq #{File.join('..', destination)} *")
57
+ abort('Creating zip failed, exiting.') unless success
58
+ end
59
+ end
60
+
61
+ def self.copy_bundler_config(source, destination)
62
+ puts 'Copying bundler config.'
63
+ FileUtils.mkdir_p(destination)
64
+ FileUtils.cp(source, destination)
65
+ end
66
+
67
+ def self.copy_wrapper_script(source, destination)
68
+ puts 'Copying wrapper script.'
69
+ FileUtils.cp(source, destination)
70
+ FileUtils.chmod(0755, destination)
71
+ end
72
+
73
+ def self.bundle_install(dir_with_gemfile)
74
+ puts 'Installing bundle.'
75
+ Bundler.with_clean_env do
76
+ success = system(
77
+ "cd #{dir_with_gemfile} && " \
78
+ 'env BUNDLE_IGNORE_CONFIG=1 bundle install --path . --without development'
79
+ )
80
+
81
+ abort('Bundle install failed, exiting.') unless success
82
+ end
83
+
84
+ puts 'Bundle install success.'
85
+ end
86
+
87
+ def self.download_traveling_ruby(version, target)
88
+ puts "Downloading traveling ruby from #{traveling_ruby_url(version, target)}."
89
+
90
+ File.open(traveling_ruby_tar_file(version, target), 'wb') do |saved_file|
91
+ # the following "open" is provided by open-uri
92
+ open(traveling_ruby_url(version, target), 'rb') do |read_file|
93
+ saved_file.write(read_file.read)
94
+ end
95
+ end
96
+
97
+ puts 'Download complete.'
98
+ end
99
+
100
+ def self.unpack_traveling_ruby(version, target, destination)
101
+ puts 'Unpacking traveling ruby.'
102
+
103
+ FileUtils.mkdir_p(destination)
104
+
105
+ success = system("tar -xzf #{traveling_ruby_tar_file(version, target)} -C #{destination}")
106
+ abort('Unpacking traveling ruby failed') unless success
107
+ puts 'Unpacking traveling ruby successful.'
108
+
109
+ puts 'Removing tar.'
110
+ FileUtils.rm_rf(traveling_ruby_tar_file(version, target))
111
+ end
112
+
113
+ def self.traveling_ruby_url(version, target)
114
+ "https://d6r77u77i8pq3.cloudfront.net/releases/traveling-ruby-#{version}-#{target}.tar.gz"
115
+ end
116
+
117
+ def self.traveling_ruby_tar_file(version, target)
118
+ "traveling-ruby-#{version}-#{target}.tar.gz"
119
+ end
120
+
121
+ def self.check_for_files(dir_to_build)
122
+ unless File.exist?(File.join(dir_to_build, 'main.rb'))
123
+ abort("Must have a file named 'main.rb' in #{dir_to_build}")
124
+ end
125
+
126
+ unless File.exist?(File.join(dir_to_build, 'Gemfile'))
127
+ abort("Must have a file named 'Gemfile' in #{dir_to_build}")
128
+ end
129
+
130
+ unless File.exist?(File.join(dir_to_build, 'Gemfile.lock'))
131
+ abort("Must have a file named 'Gemfile.lock' in #{dir_to_build}")
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,3 @@
1
+ module Rumbda
2
+ VERSION = '0.1.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rumbda
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kleaver
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-01 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: A command line tool to build zip files for running ruby 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/version.rb
55
+ homepage: https://github.com/kleaver/rumbda
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.4.5
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Easily run ruby on lambda!
79
+ test_files: []
80
+ has_rdoc: