jets_gem_layer 0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -2
- data/README.md +14 -8
- data/lib/jets_gem_layer/task_helper.rb +58 -7
- data/lib/jets_gem_layer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ffa9ee29edcc0f6fbf65c9ed6d08d78dc4f2dc643e07e4a048de79755dd99f2
|
4
|
+
data.tar.gz: 6840363fc62be04e9bb9eef361bcc9b0e5449f2d9e549028d6844539ea4b2da1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0250221f208eebf1890cf773cda696448e4f2b2bc31101bc8ab35dd47a2111a0fb8057e9f123e2dbdaed59acfb468c82c0a2f10aa654e2a4dd01f66097c7f37f
|
7
|
+
data.tar.gz: 03bd04e7b73924eeb858bc26822482887303b8402b85033768c37995777428d8bf498c5fd5110626a66016cf30c05c3d344e3f1e1c248a3e9b1338a1bffe7b81
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -14,7 +14,7 @@ is correctly set for your project.
|
|
14
14
|
|
15
15
|
## Installation
|
16
16
|
|
17
|
-
1. Jets Pro would typically be disabled when using this gem so as to not generate
|
17
|
+
1. Jets Pro would typically be disabled when using this gem so as to not generate duplicative Lambda Layers.
|
18
18
|
|
19
19
|
```ruby
|
20
20
|
# config/application.rb
|
@@ -55,10 +55,12 @@ JetsGemLayer.load_tasks
|
|
55
55
|
3. After running `bundle install`, run `rake -T` and you should see this Gem's tasks available for use.
|
56
56
|
```
|
57
57
|
➜ rake -T
|
58
|
-
rake gem_layer:build_and_publish
|
59
|
-
rake gem_layer:build
|
60
|
-
rake gem_layer:publish
|
61
|
-
rake gem_layer:clean
|
58
|
+
rake gem_layer:build_and_publish # Build, publish, and clean (will be a no-op if already published)
|
59
|
+
rake gem_layer:build # Build the gem layer zip file
|
60
|
+
rake gem_layer:publish # Publish the built gem laye zip to AWS
|
61
|
+
rake gem_layer:clean # Clean up the gem's tmp files
|
62
|
+
rake gem_layer:cleanup_published # Deletes all prior versions of the lamda layer from AWS
|
63
|
+
rake gem_layer:delete_all_published # Deletes all versions of the lamda layer from AWS
|
62
64
|
```
|
63
65
|
|
64
66
|
## Configuration
|
@@ -72,9 +74,13 @@ specific to your Gemfile. For example, to build the `mysql2` gem you will need t
|
|
72
74
|
Dependencies will be installed within the build container and copied into the published Lambda Layer.
|
73
75
|
|
74
76
|
## Deployment
|
75
|
-
Within your project directory (example for development environment):
|
76
|
-
1.
|
77
|
-
|
77
|
+
Within your project directory (example for development environment) or through your CI/CD platform:
|
78
|
+
1. `JETS_ENV=development JETS_AGREE=no rake gem_layer:build_and_publish`
|
79
|
+
* If needed, builds and publishes a new gem layer version based on the current Jets namespace, Gemfile.lock and Gemfile
|
80
|
+
2. `JETS_ENV=development JETS_AGREE=no jets deploy`
|
81
|
+
* Deploy your application
|
82
|
+
3. `JETS_ENV=development JETS_AGREE=no rake gem_layer:cleanup_published`
|
83
|
+
* After a successful deploy, you may run this to cleanup the old gem layer version(s) no longer in use
|
78
84
|
|
79
85
|
## Acknowledgements
|
80
86
|
A big thank you to the authors of [Lambda Layer Cake](https://github.com/loganb/lambda-layer-cake), which served as a reference.
|
@@ -38,12 +38,18 @@ module JetsGemLayer
|
|
38
38
|
install_build
|
39
39
|
install_publish
|
40
40
|
install_clean
|
41
|
+
install_cleanup_published
|
42
|
+
install_delete_all_published
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
44
46
|
def install_build_and_publish
|
45
|
-
desc 'Build and publish a gem layer version'
|
47
|
+
desc 'Build and publish a gem layer version, if necessary'
|
46
48
|
task :build_and_publish do
|
49
|
+
if published?
|
50
|
+
puts "#{layer_name} already published for #{layer_version_description}. Not doing anything!"
|
51
|
+
break
|
52
|
+
end
|
47
53
|
Rake::Task['gem_layer:build'].invoke
|
48
54
|
Rake::Task['gem_layer:publish'].invoke
|
49
55
|
Rake::Task['gem_layer:clean'].invoke
|
@@ -51,7 +57,7 @@ module JetsGemLayer
|
|
51
57
|
end
|
52
58
|
|
53
59
|
def install_build
|
54
|
-
desc 'Build
|
60
|
+
desc 'Build a gem layer zip file'
|
55
61
|
task :build do
|
56
62
|
Rake::Task['gem_layer:clean'].invoke
|
57
63
|
build_layer
|
@@ -60,19 +66,33 @@ module JetsGemLayer
|
|
60
66
|
end
|
61
67
|
|
62
68
|
def install_publish
|
63
|
-
desc 'Publish
|
69
|
+
desc 'Publish the already built layer zip file'
|
64
70
|
task :publish do
|
65
71
|
publish_layer
|
66
72
|
end
|
67
73
|
end
|
68
74
|
|
69
75
|
def install_clean
|
70
|
-
desc 'Clean tmp files'
|
76
|
+
desc 'Clean jets_gem_layer tmp files'
|
71
77
|
task :clean do
|
72
78
|
FileUtils.rm_r(working_dir) if File.exist?(working_dir)
|
73
79
|
end
|
74
80
|
end
|
75
81
|
|
82
|
+
def install_cleanup_published
|
83
|
+
desc 'Delete old layer versions from AWS (for use after deployment)'
|
84
|
+
task :cleanup_published do
|
85
|
+
cleanup_published
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def install_delete_all_published
|
90
|
+
desc 'Delete all published versions of the gem layer from AWS'
|
91
|
+
task :delete_all_published do
|
92
|
+
delete_all_published
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
76
96
|
def build_layer
|
77
97
|
FileUtils.mkdir_p(inputs_dir)
|
78
98
|
FileUtils.cp(INPUT_FILES.existing, inputs_dir)
|
@@ -84,7 +104,7 @@ module JetsGemLayer
|
|
84
104
|
begin
|
85
105
|
Dir.chdir(outputs_dir)
|
86
106
|
system(*%W[zip -r #{File.join(working_dir, "#{layer_name}.zip")} lib ruby], out: File::NULL) or raise
|
87
|
-
puts 'Layer zipped successfully
|
107
|
+
puts 'Layer zipped successfully!'
|
88
108
|
ensure
|
89
109
|
Dir.chdir(pwd)
|
90
110
|
end
|
@@ -96,7 +116,7 @@ module JetsGemLayer
|
|
96
116
|
description: layer_version_description,
|
97
117
|
content: { zip_file: File.read(zip_file_path) }
|
98
118
|
)
|
99
|
-
puts "#{layer_name} published for #{layer_version_description}
|
119
|
+
puts "#{layer_name} published for #{layer_version_description}!"
|
100
120
|
end
|
101
121
|
|
102
122
|
private
|
@@ -173,7 +193,38 @@ module JetsGemLayer
|
|
173
193
|
end
|
174
194
|
|
175
195
|
def published_layer_version
|
176
|
-
@published_layer_version ||= aws_lambda.list_layer_versions(
|
196
|
+
@published_layer_version ||= aws_lambda.list_layer_versions(layer_name:, max_items: 1).layer_versions.first
|
197
|
+
end
|
198
|
+
|
199
|
+
# paginate through all layer versions to get them all (but it's unlikely there will be more than 1 page)
|
200
|
+
def all_layer_versions
|
201
|
+
all_versions = []
|
202
|
+
marker = nil
|
203
|
+
loop do
|
204
|
+
page = aws_lambda.list_layer_versions(layer_name:, max_items: 50, marker:)
|
205
|
+
all_versions.concat page.layer_versions
|
206
|
+
marker = page.next_marker
|
207
|
+
break if marker.nil?
|
208
|
+
end
|
209
|
+
all_versions
|
210
|
+
end
|
211
|
+
|
212
|
+
def cleanup_published
|
213
|
+
all_layer_versions.each_with_index do |layer_version, i|
|
214
|
+
next if i.zero? # skips the current version
|
215
|
+
|
216
|
+
aws_lambda.delete_layer_version(layer_name:, version_number: layer_version.version)
|
217
|
+
puts "Deleted #{layer_version.layer_version_arn}"
|
218
|
+
end
|
219
|
+
puts 'Deleted all prior versions!'
|
220
|
+
end
|
221
|
+
|
222
|
+
def delete_all_published
|
223
|
+
all_layer_versions.each do |layer_version|
|
224
|
+
aws_lambda.delete_layer_version(layer_name:, version_number: layer_version.version)
|
225
|
+
puts "Deleted #{layer_version.layer_version_arn}"
|
226
|
+
end
|
227
|
+
puts 'Deleted all published versions!'
|
177
228
|
end
|
178
229
|
end
|
179
230
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jets_gem_layer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DocGo Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jets
|