lono 7.2.3 → 7.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/lono/app_file/build.rb +14 -1
- data/lib/lono/app_file/build/lambda_layer.rb +20 -0
- data/lib/lono/app_file/build/lambda_layer/ruby_packager.rb +180 -0
- data/lib/lono/app_file/registry.rb +5 -3
- data/lib/lono/app_file/registry/item.rb +9 -4
- data/lib/lono/template/post_processor.rb +5 -5
- data/lib/lono/template/strategy/dsl/builder/helpers/s3_helper.rb +5 -3
- data/lib/lono/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50634682d0b2bd1142fa36acb73b537e1fcceabde68d7ea88da24621c17b2267
|
4
|
+
data.tar.gz: 53a2e8a25610f8f039cdee8c6cb71ab15b24732642d0453a61ace628fb925ca4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a700f987afc86bdf10ffc561e0f9027d7ce7aa661b852395a6ff734d272f06a655f24ff4f44aff316b3cb0c225ce64affccab258bde7ac58c0393ce47eff09b5
|
7
|
+
data.tar.gz: 1ad6215fc323bd75bd88c085761fe96131d9e71e531cf40ee0d2940cf8f10483c97cb86984c382cf1c3b6ee1522edc60782275a514713b4fc05c5d6627bf184c
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
|
5
5
|
|
6
|
+
## [7.3.0]
|
7
|
+
- #54 introduce lambda layer concept
|
8
|
+
|
6
9
|
## [7.2.3]
|
7
10
|
- #53 improve configset lookup path lookup
|
8
11
|
- cleanup starter blueprint
|
data/lib/lono/app_file/build.rb
CHANGED
@@ -15,8 +15,21 @@ module Lono::AppFile
|
|
15
15
|
def build_all
|
16
16
|
clean_output
|
17
17
|
copy_to_output
|
18
|
+
build_layers
|
19
|
+
compress_output
|
20
|
+
end
|
21
|
+
|
22
|
+
def build_layers
|
23
|
+
layer_items = Registry.layers
|
24
|
+
layer_items.each do |item|
|
25
|
+
LambdaLayer.new(@blueprint, item).build
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def compress_output
|
18
30
|
Registry.items.each do |item|
|
19
|
-
|
31
|
+
# type can be lambda_layer or file
|
32
|
+
if item.type == "lambda_layer" || item.directory?
|
20
33
|
zip_directory(item)
|
21
34
|
elsif item.file?
|
22
35
|
zip_file(item)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Lono::AppFile::Build
|
2
|
+
class LambdaLayer
|
3
|
+
def initialize(blueprint, registry_item)
|
4
|
+
@blueprint, @registry_item = blueprint, registry_item
|
5
|
+
end
|
6
|
+
|
7
|
+
def build
|
8
|
+
lang = @registry_item.options[:lang]
|
9
|
+
unless lang =~ /ruby/
|
10
|
+
puts "WARN: Currently only support ruby lambda layers".color(:yellow)
|
11
|
+
return
|
12
|
+
end
|
13
|
+
|
14
|
+
klass_name = "Lono::AppFile::Build::LambdaLayer::#{lang.camelize}Packager"
|
15
|
+
klass = klass_name.constantize
|
16
|
+
packager = klass.new(@blueprint, @registry_item)
|
17
|
+
packager.build
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
class Lono::AppFile::Build::LambdaLayer
|
2
|
+
# Based on jets
|
3
|
+
class RubyPackager
|
4
|
+
def initialize(blueprint, registry_item)
|
5
|
+
@blueprint, @registry_item = blueprint, registry_item
|
6
|
+
|
7
|
+
@registry_name = @registry_item.name.sub(/\/$/,'')
|
8
|
+
@app_root = "#{Lono.blueprint_root}/app/files/#{@registry_name}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def build
|
12
|
+
return unless gemfile_exist?
|
13
|
+
|
14
|
+
bundle_install
|
15
|
+
package
|
16
|
+
end
|
17
|
+
|
18
|
+
# We consolidate all gems to opt
|
19
|
+
def package
|
20
|
+
setup_bundle_config(output_area)
|
21
|
+
# copy_cache_gems # TODO: might not need this cache
|
22
|
+
consolidate_gems_to_opt
|
23
|
+
end
|
24
|
+
|
25
|
+
# Also restructure the folder from:
|
26
|
+
# vendor/gems/ruby/2.5.0
|
27
|
+
# To:
|
28
|
+
# ruby/gems/2.5.0
|
29
|
+
#
|
30
|
+
# For Lambda Layer structure
|
31
|
+
def consolidate_gems_to_opt
|
32
|
+
src = "#{cache_area}/vendor/gems/ruby/#{ruby_folder}"
|
33
|
+
dest = "#{opt_area}/ruby/gems/#{ruby_folder}"
|
34
|
+
rsync_and_link(src, dest)
|
35
|
+
end
|
36
|
+
|
37
|
+
def rsync_and_link(src, dest)
|
38
|
+
FileUtils.mkdir_p(dest)
|
39
|
+
# Trailing slashes are required
|
40
|
+
sh "rsync -a --links #{src}/ #{dest}/"
|
41
|
+
|
42
|
+
# create symlink in output path not the cache path
|
43
|
+
symlink_dest = "#{output_area}/vendor/gems/ruby/#{ruby_folder}"
|
44
|
+
puts "symlink_dest #{symlink_dest}"
|
45
|
+
FileUtils.rm_rf(symlink_dest) # blow away original 2.5.0 folder
|
46
|
+
|
47
|
+
# Create symlink that will point to the gems in the Lambda Layer:
|
48
|
+
# stage/opt/ruby/gems/2.5.0 -> /opt/ruby/gems/2.5.0
|
49
|
+
FileUtils.mkdir_p(File.dirname(symlink_dest))
|
50
|
+
FileUtils.ln_sf("/opt/ruby/gems/#{ruby_folder}", symlink_dest)
|
51
|
+
end
|
52
|
+
|
53
|
+
def ruby_folder
|
54
|
+
major, minor, _ = RUBY_VERSION.split('.')
|
55
|
+
[major, minor, '0'].join('.') # 2.5.1 => 2.5.0
|
56
|
+
end
|
57
|
+
|
58
|
+
# Installs gems on the current target system: both compiled and non-compiled.
|
59
|
+
# If user is on a macosx machine, macosx gems will be installed.
|
60
|
+
# If user is on a linux machine, linux gems will be installed.
|
61
|
+
#
|
62
|
+
# Copies Gemfile* to /tmp/jets/demo/cache folder and installs
|
63
|
+
# gems with bundle install from there.
|
64
|
+
#
|
65
|
+
# We take the time to copy Gemfile and bundle into a separate directory
|
66
|
+
# because it gets left around to act as a 'cache'. So, when the builds the
|
67
|
+
# project gets built again not all the gems from get installed from the
|
68
|
+
# beginning.
|
69
|
+
def bundle_install
|
70
|
+
puts "Bundling: running bundle install in cache area: #{cache_area}."
|
71
|
+
|
72
|
+
copy_gemfiles(@app_root)
|
73
|
+
|
74
|
+
# Uncomment out to always remove the cache/vendor/gems to debug
|
75
|
+
# FileUtils.rm_rf("#{cache_area}/vendor/gems")
|
76
|
+
|
77
|
+
# Remove .bundle folder so .bundle/config doesnt affect how Jets packages gems.
|
78
|
+
# Not using BUNDLE_IGNORE_CONFIG=1 to allow home ~/.bundle/config to affect bundling though.
|
79
|
+
# This is useful if you have private gems sources that require authentication. Example:
|
80
|
+
#
|
81
|
+
# bundle config gems.myprivatesource.com user:pass
|
82
|
+
#
|
83
|
+
|
84
|
+
FileUtils.rm_rf("#{cache_area}/.bundle")
|
85
|
+
require "bundler" # dynamically require bundler so user can use any bundler
|
86
|
+
setup_bundle_config(cache_area)
|
87
|
+
Bundler.with_unbundled_env do
|
88
|
+
sh "cd #{cache_area} && env bundle install"
|
89
|
+
end
|
90
|
+
|
91
|
+
remove_bundled_with("#{cache_area}/Gemfile.lock")
|
92
|
+
|
93
|
+
# Copy the Gemfile.lock back to the project in case it was updated.
|
94
|
+
# For example we add the jets-rails to the Gemfile.
|
95
|
+
copy_back_gemfile_lock
|
96
|
+
|
97
|
+
puts 'Bundle install success.'
|
98
|
+
end
|
99
|
+
|
100
|
+
# Remove the BUNDLED WITH line since we don't control the bundler gem version on AWS Lambda
|
101
|
+
# And this can cause issues with require 'bundler/setup'
|
102
|
+
def remove_bundled_with(gemfile_lock)
|
103
|
+
lines = IO.readlines(gemfile_lock)
|
104
|
+
|
105
|
+
# amount is the number of lines to remove
|
106
|
+
new_lines, capture, count, amount = [], true, 0, 2
|
107
|
+
lines.each do |l|
|
108
|
+
capture = false if l.include?('BUNDLED WITH')
|
109
|
+
if capture
|
110
|
+
new_lines << l
|
111
|
+
end
|
112
|
+
if capture == false
|
113
|
+
count += 1
|
114
|
+
capture = count > amount # renable capture
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
content = new_lines.join('')
|
119
|
+
IO.write(gemfile_lock, content)
|
120
|
+
end
|
121
|
+
|
122
|
+
def copy_back_gemfile_lock
|
123
|
+
src = "#{cache_area}/Gemfile.lock"
|
124
|
+
dest = "#{@app_root}/Gemfile.lock"
|
125
|
+
FileUtils.cp(src, dest)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Clean up extra unneeded files to reduce package size
|
129
|
+
def copy_gemfiles(app_root)
|
130
|
+
FileUtils.mkdir_p(cache_area)
|
131
|
+
FileUtils.cp("#{app_root}/Gemfile", "#{cache_area}/Gemfile")
|
132
|
+
|
133
|
+
gemfile_lock = "#{app_root}/Gemfile.lock"
|
134
|
+
dest = "#{cache_area}/Gemfile.lock"
|
135
|
+
return unless File.exist?(gemfile_lock)
|
136
|
+
|
137
|
+
FileUtils.cp(gemfile_lock, dest)
|
138
|
+
end
|
139
|
+
|
140
|
+
def setup_bundle_config(dir)
|
141
|
+
text =<<-EOL
|
142
|
+
---
|
143
|
+
BUNDLE_FROZEN: "true"
|
144
|
+
BUNDLE_PATH: "vendor/gems"
|
145
|
+
BUNDLE_WITHOUT: "development:test"
|
146
|
+
EOL
|
147
|
+
bundle_config = "#{dir}/.bundle/config"
|
148
|
+
FileUtils.mkdir_p(File.dirname(bundle_config))
|
149
|
+
IO.write(bundle_config, text)
|
150
|
+
end
|
151
|
+
|
152
|
+
def output_area
|
153
|
+
"#{Lono.config.output_path}/#{@blueprint}/files/#{@registry_name}"
|
154
|
+
end
|
155
|
+
|
156
|
+
def build_area
|
157
|
+
"#{Lono.config.output_path}/#{@blueprint}/lambda_layers/#{@registry_name}"
|
158
|
+
end
|
159
|
+
|
160
|
+
def cache_area
|
161
|
+
"#{build_area}/cache"
|
162
|
+
end
|
163
|
+
|
164
|
+
def opt_area
|
165
|
+
"#{build_area}/opt"
|
166
|
+
end
|
167
|
+
|
168
|
+
def gemfile_exist?
|
169
|
+
gemfile_path = "#{@app_root}/Gemfile"
|
170
|
+
File.exist?(gemfile_path)
|
171
|
+
end
|
172
|
+
|
173
|
+
def sh(command)
|
174
|
+
puts "=> #{command}"
|
175
|
+
out = `#{command}`
|
176
|
+
puts out if ENV['LONO_DEBUG_LAMBDA_LAYER']
|
177
|
+
$?.success?
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
@@ -1,13 +1,15 @@
|
|
1
1
|
module Lono::AppFile
|
2
2
|
class Registry
|
3
|
+
cattr_reader :items
|
3
4
|
@@items = []
|
5
|
+
|
4
6
|
class << self
|
5
7
|
def register(name, blueprint, options={})
|
6
|
-
@@items << Item.new(name, blueprint, options) unless @@items.detect { |i| i.name == name }
|
8
|
+
@@items << Item.new(name, blueprint, options) unless @@items.detect { |i| i.name == name && i.type == options[:type] }
|
7
9
|
end
|
8
10
|
|
9
|
-
def
|
10
|
-
@@items
|
11
|
+
def layers
|
12
|
+
@@items.select { |i| i.type == "lambda_layer" }
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -2,13 +2,18 @@ module Lono::AppFile
|
|
2
2
|
class Registry
|
3
3
|
# Holds metadata about the item in the regsitry.
|
4
4
|
class Item
|
5
|
-
attr_reader :name, :options
|
5
|
+
attr_reader :name, :options, :type
|
6
6
|
def initialize(name, blueprint, options={})
|
7
7
|
@name, @blueprint, @options = name, blueprint, options
|
8
|
+
@type = options[:type] || "file"
|
8
9
|
end
|
9
10
|
|
10
11
|
def path
|
11
|
-
|
12
|
+
if @type == "file"
|
13
|
+
"#{Lono.root}/output/#{@blueprint}/files/#{@name}"
|
14
|
+
else
|
15
|
+
"#{Lono.root}/output/#{@blueprint}/lambda_layers/#{@name}/opt"
|
16
|
+
end
|
12
17
|
end
|
13
18
|
|
14
19
|
def directory?
|
@@ -20,7 +25,7 @@ module Lono::AppFile
|
|
20
25
|
end
|
21
26
|
|
22
27
|
def s3_path
|
23
|
-
file_path = zip_file_path.sub(%r{.*/output/[\w_-]+/files/}, '') # dont use basename. there might be subfolders
|
28
|
+
file_path = zip_file_path.sub(%r{.*/output/[\w_-]+/(files|lambda_layers)/}, '') # dont use basename. there might be subfolders
|
24
29
|
"#{s3_prefix}/#{file_path}"
|
25
30
|
end
|
26
31
|
|
@@ -30,7 +35,7 @@ module Lono::AppFile
|
|
30
35
|
end
|
31
36
|
|
32
37
|
def zip_file_name
|
33
|
-
"#{File.basename(path)}-#{Lono::Md5.sum(path)}.zip"
|
38
|
+
"#{File.basename(path)}-#{@type}-#{Lono::Md5.sum(path)}.zip"
|
34
39
|
end
|
35
40
|
|
36
41
|
private
|
@@ -14,15 +14,15 @@ class Lono::Template
|
|
14
14
|
def replacements
|
15
15
|
map = {}
|
16
16
|
registry_items.each do |item|
|
17
|
-
if item.
|
18
|
-
|
17
|
+
if item.type == "lambda_layer"
|
18
|
+
placeholder = "file://app/files/lambda_layer/#{item.name}"
|
19
|
+
elsif item.directory? || item.file?
|
20
|
+
placeholder = "file://app/files/file/#{item.name}"
|
19
21
|
else
|
20
22
|
puts "WARN: PostProcessor replacements Cannot find file: #{item.path}"
|
21
23
|
next
|
22
24
|
end
|
23
|
-
|
24
|
-
placeholder = "file://app/files/#{item.name}"
|
25
|
-
map[placeholder] = replacement
|
25
|
+
map[placeholder] = item.s3_path
|
26
26
|
end
|
27
27
|
map
|
28
28
|
end
|
@@ -4,10 +4,12 @@ module Lono::Template::Strategy::Dsl::Builder::Helpers
|
|
4
4
|
Lono::S3::Bucket.name
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
7
|
+
def s3_key(name, options={})
|
8
|
+
default = {type: "file"}
|
9
|
+
options.reverse_merge!(default)
|
8
10
|
Lono::AppFile::Registry.register(name, @blueprint, options)
|
9
|
-
"file://app/files/#{name}" # placeholder for post processing
|
11
|
+
"file://app/files/#{options[:type]}/#{name}" # placeholder for post processing
|
10
12
|
end
|
11
|
-
alias_method :
|
13
|
+
alias_method :file_s3_key, :s3_key
|
12
14
|
end
|
13
15
|
end
|
data/lib/lono/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lono
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -450,6 +450,8 @@ files:
|
|
450
450
|
- lib/lono/api/verify.rb
|
451
451
|
- lib/lono/app_file/base.rb
|
452
452
|
- lib/lono/app_file/build.rb
|
453
|
+
- lib/lono/app_file/build/lambda_layer.rb
|
454
|
+
- lib/lono/app_file/build/lambda_layer/ruby_packager.rb
|
453
455
|
- lib/lono/app_file/registry.rb
|
454
456
|
- lib/lono/app_file/registry/item.rb
|
455
457
|
- lib/lono/app_file/upload.rb
|