assets_deployer 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3a2fbff0dd0f4fdce8796030dd461a21e2a1effa
4
+ data.tar.gz: 9ee83f5080b956a53032e594486ab05a999b28b5
5
+ SHA512:
6
+ metadata.gz: 002dd5e527556600c58275694d40914f52ff907502eb160041dbacf2c74ada3853713b9598b1f61e521c8805468b5c5861dec1f96ed3ba30b1c6c74c76ac7e1d
7
+ data.tar.gz: 116a41aba91823a3b28b9819f16abebc223d9488e5a350d00cd9222d2be23853f271fefe4c0e7993656ec4f7582036f68bdcf2fa5be9c2a2b3e9c715ef19f1c4
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Shota Iguchi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # AssetsDeployer
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'assets_deployer'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install assets_deployer
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'bundler/gem_tasks'
@@ -0,0 +1,24 @@
1
+ require 'mime/types'
2
+
3
+ module AssetsDeployer
4
+ class AssetFile
5
+ attr_reader :prefix
6
+
7
+ def initialize(prefix, path)
8
+ @prefix = prefix
9
+ @path = path
10
+ end
11
+
12
+ def key
13
+ [prefix, File.basename(@path)].join('/')
14
+ end
15
+
16
+ def body
17
+ File.new(@path)
18
+ end
19
+
20
+ def content_type
21
+ MIME::Types.type_for(@path).first.to_s
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ module AssetsDeployer
2
+ class Configuration
3
+ attr_accessor :storage,
4
+ :assets_root_path,
5
+ :assets_prefixes
6
+
7
+ class StorageConfiguration < Struct.new(:platform, :name, :credentials, :options)
8
+ def initialize
9
+ self.credentials = {}
10
+ self.options = {}
11
+ end
12
+ end
13
+
14
+ def storage
15
+ @storage ||= StorageConfiguration.new
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,25 @@
1
+ require 'assets_deployer/asset_file'
2
+
3
+ module AssetsDeployer
4
+ class Deployer
5
+ def initialize(storage:, root_path:, prefixes:)
6
+ @storage = storage
7
+ @root_path = root_path
8
+ @prefixes = prefixes
9
+ end
10
+
11
+ def run
12
+ @storage.upload(files)
13
+ end
14
+
15
+ private
16
+
17
+ def files
18
+ @files ||= @prefixes.flat_map do |prefix|
19
+ Dir.glob(@root_path.join(prefix).join('**', '**')).map do |path|
20
+ AssetFile.new(prefix, path) if Pathname.new(path).file?
21
+ end
22
+ end.compact
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ module AssetsDeployer
2
+ class Engine < Rails::Engine
3
+ engine_name 'assets_deployer'
4
+ end
5
+ end
@@ -0,0 +1,58 @@
1
+ require 'aws-sdk'
2
+
3
+ module AssetsDeployer
4
+ module Storage
5
+ class AwsS3 < Base
6
+ def initialize(credentials:, region: nil, bucket: nil, prefix_key: nil)
7
+ @credentials = credentials
8
+ @bucket = bucket
9
+ @prefix_key = prefix_key
10
+ @region = region
11
+ end
12
+
13
+ def upload(files)
14
+ files.each do |file|
15
+ client.put_object(
16
+ bucket: @bucket,
17
+ key: [@prefix_key, file.key].compact.join('/'),
18
+ body: file.body,
19
+ content_type: file.content_type
20
+ )
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def client
27
+ @client ||= Aws::S3::Client.new(client_options)
28
+ end
29
+
30
+ def client_options
31
+ hash = {}
32
+ hash[:credentials] = credentials
33
+ hash[:region] = region if !region.nil? && !region.empty?
34
+ hash
35
+ end
36
+
37
+ def credentials
38
+ if access_key_id && secret_access_key
39
+ Aws::Credentials.new(access_key_id, secret_access_key)
40
+ else
41
+ Aws::InstanceProfileCredentials.new
42
+ end
43
+ end
44
+
45
+ def access_key_id
46
+ @credentials[:access_key_id] || ENV['AWS_ACCESS_KEY_ID']
47
+ end
48
+
49
+ def secret_access_key
50
+ @credentials[:secret_access_key] || ENV['AWS_SECRET_ACCESS_KEY']
51
+ end
52
+
53
+ def region
54
+ @region || ENV['AWS_REGION']
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,9 @@
1
+ module AssetsDeployer
2
+ module Storage
3
+ class Base
4
+ def upload
5
+ raise NotImplementedError
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,30 @@
1
+ require 'assets_deployer/storage/base'
2
+ require 'assets_deployer/storage/aws_s3'
3
+
4
+ module AssetsDeployer
5
+ class StorageBuilder
6
+ class InvalidStorageError < StandardError
7
+ end
8
+
9
+ def initialize(platform:, name:, credentials:, options:)
10
+ @platform = platform
11
+ @name = name
12
+ @credentials = credentials
13
+ @options = options
14
+ end
15
+
16
+ def build
17
+ case [@platform, @name]
18
+ when ['AWS', 'S3']
19
+ Storage::AwsS3.new(
20
+ credentials: @credentials,
21
+ bucket: @options[:bucket],
22
+ prefix_key: @options[:prefix_key],
23
+ region: @options[:region]
24
+ )
25
+ else
26
+ raise InvalidStorageError
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module AssetsDeployer
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,31 @@
1
+ require 'assets_deployer/deployer'
2
+ require 'assets_deployer/configuration'
3
+ require 'assets_deployer/storage_builder'
4
+
5
+ module AssetsDeployer
6
+ def self.run
7
+ deployer = Deployer.new(storage: storage, root_path: config.assets_root_path, prefixes: config.assets_prefixes)
8
+ deployer.run
9
+ end
10
+
11
+ def self.config
12
+ @config ||= Configuration.new
13
+ end
14
+
15
+ def self.configure
16
+ yield config
17
+ end
18
+
19
+ def self.storage
20
+ builder = StorageBuilder.new(
21
+ platform: config.storage.platform,
22
+ name: config.storage.name,
23
+ credentials: config.storage.credentials,
24
+ options: config.storage.options
25
+ )
26
+
27
+ builder.build
28
+ end
29
+ end
30
+
31
+ require 'assets_deployer/engine' if defined?(Rails)
@@ -0,0 +1,5 @@
1
+ namespace :assets do
2
+ task deploy: :environment do
3
+ AssetsDeployer.run
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: assets_deployer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shota Iguchi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aws-sdk
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - shota-iguchi@cookpad.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - MIT-LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - lib/assets_deployer.rb
66
+ - lib/assets_deployer/asset_file.rb
67
+ - lib/assets_deployer/configuration.rb
68
+ - lib/assets_deployer/deployer.rb
69
+ - lib/assets_deployer/engine.rb
70
+ - lib/assets_deployer/storage/aws_s3.rb
71
+ - lib/assets_deployer/storage/base.rb
72
+ - lib/assets_deployer/storage_builder.rb
73
+ - lib/assets_deployer/version.rb
74
+ - lib/tasks/assets.rake
75
+ homepage:
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.6.11
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Rails assets deployer
99
+ test_files: []