-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from fac/abstract-s3-pushing
Prepare for extending to use with other runtimes and asset repositories.
- Loading branch information
Showing
22 changed files
with
449 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
serverless-tools (0.1.0) | ||
serverless-tools (0.2.0) | ||
aws-sdk-lambda | ||
aws-sdk-s3 | ||
thor | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# fronzen_string_literal: true | ||
|
||
require "aws-sdk-s3" | ||
require "aws-sdk-lambda" | ||
|
||
require_relative "../git" | ||
require_relative "./s3_pusher" | ||
require_relative "./lambda_updater" | ||
require_relative "./ruby_builder" | ||
require_relative "./errors" | ||
|
||
module ServerlessTools | ||
module Deployer | ||
class FunctionDeployer | ||
attr_reader :builder, :pusher, :updater | ||
|
||
def initialize(builder:, pusher:, updater:) | ||
@builder = builder | ||
@pusher = pusher | ||
@updater = updater | ||
end | ||
|
||
def build | ||
builder.build | ||
end | ||
|
||
def push | ||
pusher.push(**builder.output) | ||
end | ||
|
||
def update | ||
updater.update(pusher.output) | ||
end | ||
|
||
def deploy | ||
build | ||
push | ||
update | ||
end | ||
|
||
def self.create_for_function(config:) | ||
send("#{config.runtime}_deployer", config) | ||
rescue NoMethodError | ||
raise RuntimeNotSupported.new(config: config) | ||
end | ||
|
||
def self.ruby_deployer(config) | ||
self.new( | ||
builder: RubyBuilder.new(config: config), | ||
pusher: S3Pusher.new(client: Aws::S3::Client.new, git: Git.new, config: config), | ||
updater: LambdaUpdater.new(client: Aws::Lambda::Client.new, config: config) | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module ServerlessTools | ||
module Deployer | ||
class LambdaUpdater | ||
def initialize(client:, config:) | ||
@client = client | ||
@config = config | ||
end | ||
|
||
def update(options) | ||
options[:function_name] = config.name | ||
|
||
response = client.update_function_code(options) | ||
|
||
puts "::set-output name=#{response[:function_name]}_status::#{response[:last_update_status]}" | ||
rescue Aws::Lambda::Errors::ServiceError => e | ||
puts "::error:: An error occured when updating #{config.name} #{e.message}" | ||
end | ||
|
||
private | ||
|
||
attr_reader :client, :config | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module ServerlessTools | ||
module Deployer | ||
class RubyBuilder | ||
def initialize(config:) | ||
@config = config | ||
end | ||
|
||
def build | ||
`bundle` | ||
`zip -r "#{local_filename}" #{config.handler_file} lib vendor/` | ||
end | ||
|
||
def output | ||
{ | ||
local_filename: local_filename, | ||
} | ||
end | ||
|
||
def local_filename | ||
"#{config.name}.zip" | ||
end | ||
|
||
private | ||
|
||
attr_reader :config | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
require "aws-sdk-s3" | ||
|
||
module ServerlessTools | ||
module Deployer | ||
class S3Pusher | ||
def initialize(client:, git:, config:) | ||
@client = client | ||
@git = git | ||
@config = config | ||
end | ||
|
||
def push(local_filename:) | ||
if object.exists? | ||
puts "Did not upload #{object.key} as it already exists!" | ||
else | ||
object.upload_file(local_filename) | ||
end | ||
output | ||
end | ||
|
||
def output | ||
return {} unless object.exists? | ||
{ | ||
s3_bucket: object.bucket.name, | ||
s3_key: object.key, | ||
} | ||
end | ||
|
||
private | ||
|
||
def object | ||
@object ||= Aws::S3::Object.new( | ||
bucket_name: config.bucket, | ||
key: s3_key, | ||
client: client | ||
) | ||
end | ||
|
||
def s3_key | ||
"#{config.repo}/deployments/#{git.sha}/#{config.name}/#{config.s3_archive_name}" | ||
end | ||
|
||
attr_reader :client, :git, :config | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module ServerlessTools | ||
VERSION = "0.1.0" | ||
VERSION = "0.2.0" | ||
end |
Oops, something went wrong.