minimal_pipeline 0.0.14 → 0.0.15
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/lib/minimal_pipeline/cloudformation.rb +20 -6
- data/lib/minimal_pipeline/lambda.rb +37 -0
- data/lib/minimal_pipeline/s3.rb +55 -0
- data/lib/minimal_pipeline.rb +2 -0
- metadata +7 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e76400b44e1460894c1aae21f2867d60117808e7153b8e161eaafb628baa0020
|
4
|
+
data.tar.gz: a3a6c7f83608687e40abd6ac5d8a8f7b25d8f62c01486c101f18203db864b6b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e047416e23ad0e5971a63128e79c409a738130c80150c0fecb8f38177a1fb18346045a0d3753c3c836d7f81d16a1a1cc8541ff9e1ccb8f15302acb2ca4973fe
|
7
|
+
data.tar.gz: 20c2103990e6f3294b12d0443ed5bc664c430d0c60d9aedcc5c19e5511745c9b4f7ab2c81551ba3271272f256c90f1d80dc15722a0f9ea27c39ac8a5bf7b0bb7
|
@@ -49,6 +49,7 @@ class MinimalPipeline
|
|
49
49
|
@client = Aws::CloudFormation::Client.new(region: region)
|
50
50
|
@wait_max_attempts = wait_max_attempts
|
51
51
|
@wait_delay = wait_delay
|
52
|
+
@outputs = {}
|
52
53
|
end
|
53
54
|
|
54
55
|
# Converts a parameter Hash into a CloudFormation friendly structure
|
@@ -69,16 +70,29 @@ class MinimalPipeline
|
|
69
70
|
# @param output [String] The name of the output to fetch the value of
|
70
71
|
# @return [String] The value of the output for the CloudFormation stack
|
71
72
|
def stack_output(stack, output)
|
72
|
-
|
73
|
+
outputs = stack_outputs(stack)
|
74
|
+
message = "#{stack.upcase} stack does not have a(n) '#{output}' output!"
|
75
|
+
raise message unless outputs.key?(output)
|
73
76
|
|
74
|
-
|
77
|
+
outputs[output]
|
78
|
+
end
|
79
|
+
|
80
|
+
# Retrieves all CloudFormation stack outputs
|
81
|
+
#
|
82
|
+
# @param stack [String] The name of the CloudFormation stack
|
83
|
+
# @return [Hash] Key value pairs of stack outputs
|
84
|
+
def stack_outputs(stack)
|
85
|
+
response = @client.describe_stacks(stack_name: stack)
|
86
|
+
raise "#{stack.upcase} stack does not exist!" if response.stacks.empty?
|
75
87
|
|
76
|
-
|
77
|
-
|
78
|
-
|
88
|
+
@outputs[stack] ||= {}
|
89
|
+
if @outputs[stack].empty?
|
90
|
+
response.stacks.first.outputs.each do |output|
|
91
|
+
@outputs[stack][output.output_key] = output.output_value
|
92
|
+
end
|
79
93
|
end
|
80
94
|
|
81
|
-
|
95
|
+
@outputs[stack]
|
82
96
|
end
|
83
97
|
|
84
98
|
# Creates or Updates a CloudFormation stack. Checks to see if the stack
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'zip'
|
4
|
+
require 'aws-sdk'
|
5
|
+
|
6
|
+
class MinimalPipeline
|
7
|
+
# Here is an example of how to use this class to prepare zipfiles for lambda.
|
8
|
+
#
|
9
|
+
# ```
|
10
|
+
# lambda = MinimalPipeline::Lambda.new
|
11
|
+
# s3 = MinimalPipeline::S3.new
|
12
|
+
#
|
13
|
+
# # Prepare zip file
|
14
|
+
# lambda.prepare_zipfile('foo.py', 'lambda.zip')
|
15
|
+
#
|
16
|
+
# # Upload file to S3
|
17
|
+
# s3.upload('bucket_name', 'lambda.zip')
|
18
|
+
# ```
|
19
|
+
class Lambda
|
20
|
+
# Zips up lambda code in preparation for upload
|
21
|
+
#
|
22
|
+
# @param input [String] The path to a file or directory to zip up
|
23
|
+
# @param zipefile_name [String] The path to the resulting zip file
|
24
|
+
def prepare_zipfile(input, zipfile_name)
|
25
|
+
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
|
26
|
+
if File.directory?(zipfile)
|
27
|
+
input_filenames = Dir.entries(input) - %w[. ..]
|
28
|
+
input_filenames.each do |filename|
|
29
|
+
zipfile.add(filename, File.join(input, filename))
|
30
|
+
end
|
31
|
+
else
|
32
|
+
zipfile.add(File.basename(input), input)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aws-sdk'
|
4
|
+
|
5
|
+
class MinimalPipeline
|
6
|
+
# Here is an example of how to use this class to interact with S3.
|
7
|
+
#
|
8
|
+
# ```
|
9
|
+
# s3 = MinimalPipeline::S3.new
|
10
|
+
#
|
11
|
+
# # Upload file
|
12
|
+
# s3.upload('bucket_name', 'foo.txt')
|
13
|
+
#
|
14
|
+
# # Download file
|
15
|
+
# s3.download('bucket_name', 'foo.txt')
|
16
|
+
# ```
|
17
|
+
#
|
18
|
+
# You will need the following environment variables to be present:
|
19
|
+
# * `AWS_REGION` or `region`
|
20
|
+
class S3
|
21
|
+
# Initializes a `S3` client
|
22
|
+
# Requires environment variables `AWS_REGION` or `region` to be set.
|
23
|
+
def initialize
|
24
|
+
raise 'You must set env variable AWS_REGION or region.' \
|
25
|
+
if ENV['AWS_REGION'].nil? && ENV['region'].nil?
|
26
|
+
|
27
|
+
region = ENV['AWS_REGION'] || ENV['region']
|
28
|
+
@s3 = Aws::S3::Resource.new(region: region)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Downloads a file from S3 to local disk
|
32
|
+
#
|
33
|
+
# @param bucket_name [String] The name of S3 bucket to download from
|
34
|
+
# @param file [String] The path to the file on disk to download to
|
35
|
+
# @param key [String] The name of the key of the object in S3
|
36
|
+
# This defaults to the file param
|
37
|
+
def download(bucket_name, file, key = nil)
|
38
|
+
key ||= file
|
39
|
+
object = @s3.bucket(bucket_name, key)
|
40
|
+
object.upload_file(file)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Uploads a file from local disk to S3
|
44
|
+
#
|
45
|
+
# @param bucket_name [String] The name of S3 bucket to upload to
|
46
|
+
# @param file [String] The path to the file on disk to be uploaded
|
47
|
+
# @param key [String] The name of the key to store the file as in the bucket
|
48
|
+
# This defaults to the file param
|
49
|
+
def upload(bucket_name, file, key = nil)
|
50
|
+
key ||= file
|
51
|
+
object = @s3.bucket(bucket_name, key)
|
52
|
+
object.download_file(file)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/minimal_pipeline.rb
CHANGED
@@ -14,5 +14,7 @@ class MinimalPipeline
|
|
14
14
|
autoload(:Crossing, 'minimal_pipeline/crossing')
|
15
15
|
autoload(:Docker, 'minimal_pipeline/docker')
|
16
16
|
autoload(:Keystore, 'minimal_pipeline/keystore')
|
17
|
+
autoload(:Lambda, 'minimal_pipeline/lambda')
|
17
18
|
autoload(:Packer, 'minimal_pipeline/packer')
|
19
|
+
autoload(:S3, 'minimal_pipeline/s3')
|
18
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minimal_pipeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mayowa Aladeojebi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-10-
|
12
|
+
date: 2018-10-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|
@@ -82,33 +82,19 @@ dependencies:
|
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: 1.6.3
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
|
-
name:
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
87
|
-
requirements:
|
88
|
-
- - ">="
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: '0'
|
91
|
-
type: :runtime
|
92
|
-
prerelease: false
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
- - ">="
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '0'
|
98
|
-
- !ruby/object:Gem::Dependency
|
99
|
-
name: rubocop
|
85
|
+
name: zip
|
100
86
|
requirement: !ruby/object:Gem::Requirement
|
101
87
|
requirements:
|
102
88
|
- - '='
|
103
89
|
- !ruby/object:Gem::Version
|
104
|
-
version: 0.
|
90
|
+
version: 2.0.2
|
105
91
|
type: :runtime
|
106
92
|
prerelease: false
|
107
93
|
version_requirements: !ruby/object:Gem::Requirement
|
108
94
|
requirements:
|
109
95
|
- - '='
|
110
96
|
- !ruby/object:Gem::Version
|
111
|
-
version: 0.
|
97
|
+
version: 2.0.2
|
112
98
|
description: Helper gem to orchestrate pipeline tasks
|
113
99
|
email:
|
114
100
|
- mayowa.aladeojebi@stelligent.com
|
@@ -122,7 +108,9 @@ files:
|
|
122
108
|
- lib/minimal_pipeline/crossing.rb
|
123
109
|
- lib/minimal_pipeline/docker.rb
|
124
110
|
- lib/minimal_pipeline/keystore.rb
|
111
|
+
- lib/minimal_pipeline/lambda.rb
|
125
112
|
- lib/minimal_pipeline/packer.rb
|
113
|
+
- lib/minimal_pipeline/s3.rb
|
126
114
|
homepage: https://github.com/stelligent/minimal-pipeline-gem
|
127
115
|
licenses:
|
128
116
|
- 0BSD
|