webpacker_uploader 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbdb29fdfafeddb7feb884a38b52e8805a42551a9d6562a74b011b9673926cd1
4
- data.tar.gz: 925e5c75c02b4b227b243a2a016de589e18b9072421ff20f4cc632a72834a74e
3
+ metadata.gz: 613e7597be0786ab1a3acf5d460eafeb42d1b94816250c64f36e38c13d2f9138
4
+ data.tar.gz: '01864d7e0ce27b5ca6030bb52383255c9af63789b006c8a8a199c9e78b17b380'
5
5
  SHA512:
6
- metadata.gz: d5ac3ffbf041da9ec25dbc52e7dd8c6e63ee501a5a3eff6355efbf37124089d29c4ba6720b88310b5e083749aea1ac7c8be1a9c5692fb0eecfa6931a202cc8d5
7
- data.tar.gz: 9d16ddae2c7ca1efcbc0f1f4dbb4c5002c0b28281f652ff92e2a0bc28d849c7bb9828ee9e26121c157cdcc9d0221c78983d8c093865da35cacfe2433b9bcc30f
6
+ metadata.gz: 9d6d102186314e943265aeaad56830c9b0404f52490640ab6e735c2a68b6923bc96b71cf24aeaf00c7d878fc7aebe07ee1f8c997965dfe0176fab12fc0cfd4f2
7
+ data.tar.gz: 1d22a604f388a94944504a5552f3b3928acf62b23ed21fc0b0570388fee1526c7bb12ac5ebacc0ce12b81ed5ed409ae59d41738b5fe9a99729c3d8061daee25c
@@ -16,7 +16,8 @@ jobs:
16
16
  ruby: [
17
17
  2.5,
18
18
  2.6,
19
- 2.7
19
+ 2.7,
20
+ 3.0
20
21
  ]
21
22
  steps:
22
23
  - uses: actions/checkout@v2
data/.rubocop.yml CHANGED
@@ -1,13 +1,10 @@
1
1
  require: rubocop-performance
2
+
2
3
  AllCops:
3
4
  TargetRubyVersion: 2.5
4
5
  # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
5
6
  # to ignore them, so only the ones explicitly set in this file are enabled.
6
7
  DisabledByDefault: true
7
- Exclude:
8
- - 'lib/install/templates/**'
9
- - 'vendor/**/*'
10
- - 'node_modules/**/*'
11
8
 
12
9
  # Prefer &&/|| over and/or.
13
10
  Style/AndOr:
data/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
4
+
5
+ ## [Unreleased]
6
+
7
+ ## [[0.2.0]](https://github.com/tlatsas/webpacker_uploader/releases/tag/v0.2.0) - 2021-02-09
8
+
9
+ ### Added
10
+
11
+ - Make file exclusion list configurable. ([#3](https://github.com/tlatsas/webpacker_uploader/pull/3), [@estebanz01](https://github.com/estebanz01))
12
+ - Support prefixing remote S3 paths. ([#2](https://github.com/tlatsas/webpacker_uploader/pull/2), [@estebanz01](https://github.com/estebanz01))
13
+ - AWS provider: Add support for EC2 instance profile credentials. ([#2](https://github.com/tlatsas/webpacker_uploader/pull/2), [@estebanz01](https://github.com/estebanz01))
14
+
15
+ ## [[0.1.0]](https://github.com/tlatsas/webpacker_uploader/releases/tag/v0.1.0) - 2020-10-01
16
+
17
+ ### Added
18
+
19
+ - Initial release. ([@tlatsas](https://github.com/tlatsas))
data/Gemfile.lock CHANGED
@@ -59,13 +59,15 @@ GEM
59
59
  mime-types (3.3.1)
60
60
  mime-types-data (~> 3.2015)
61
61
  mime-types-data (3.2020.0512)
62
- mini_portile2 (2.4.0)
62
+ mini_portile2 (2.5.0)
63
63
  minitest (5.14.2)
64
- nokogiri (1.10.10)
65
- mini_portile2 (~> 2.4.0)
64
+ nokogiri (1.11.1)
65
+ mini_portile2 (~> 2.5.0)
66
+ racc (~> 1.4)
66
67
  parallel (1.19.2)
67
68
  parser (2.7.1.4)
68
69
  ast (~> 2.4.1)
70
+ racc (1.5.2)
69
71
  rack (2.2.3)
70
72
  rack-proxy (0.6.5)
71
73
  rack
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # WebpackerUploader
2
2
 
3
+ [![Ruby tests](https://img.shields.io/github/workflow/status/tlatsas/webpacker_uploader/Ruby%20tests?style=flat-square)](https://github.com/tlatsas/webpacker_uploader/actions)
4
+ [![RuboCop](https://img.shields.io/github/workflow/status/tlatsas/webpacker_uploader/RuboCop?label=rubocop&style=flat-square)](https://github.com/tlatsas/webpacker_uploader/actions)
5
+ [![Gem](https://img.shields.io/gem/v/webpacker_uploader?style=flat-square)](https://rubygems.org/gems/webpacker_uploader)
6
+
3
7
  Webpacker uploader provides an easy way to upload your assets to AWS S3.
4
8
  It knows which files to upload by reading the `manifest.json` file.
5
9
 
@@ -31,19 +35,83 @@ gem "aws-sdk-s3", require: false
31
35
  ## Usage
32
36
 
33
37
  ```ruby
34
- require 'webpacker_uploader'
35
- require 'webpacker_uploader/providers/aws'
38
+ require "webpacker_uploader"
39
+ require "webpacker_uploader/providers/aws"
40
+
41
+ provider_options = {
42
+ credentials: { profile_name: "staging" },
43
+ region: "eu-central-1",
44
+ bucket: "application-assets-20200929124523451600000001"
45
+ }
46
+
47
+ provider = WebpackerUploader::Providers::Aws.new(provider_options)
48
+ WebpackerUploader.upload!(provider)
49
+ ```
36
50
 
37
- provider_options = {
38
- credentials: { profile_name: "staging" },
39
- region: "eu-central-1",
40
- bucket: "application-assets-20200929124523451600000001"
41
- }
51
+ Currently, the only provider implemented is the AWS S3 provider.
52
+
53
+ ### AWS S3 provider
54
+
55
+ The AWS S3 provider credentials can be configured in three ways.
56
+ Passing a named profile name:
57
+
58
+ ```ruby
59
+ provider_options = {
60
+ credentials: { profile_name: "staging" },
61
+ region: "eu-central-1",
62
+ bucket: "application-assets-20200929124523451600000001"
63
+ }
42
64
 
43
- provider = WebpackerUploader::Providers::Aws.new(provider_options)
44
- WebpackerUploader.upload!(provider)
65
+ provider = WebpackerUploader::Providers::Aws.new(provider_options)
45
66
  ```
46
67
 
68
+ passing the access and the secret keys directly:
69
+
70
+ ```ruby
71
+ provider_options = {
72
+ credentials: { access_key_id: "AKIAIOSFODNN7EXAMPLE", secret_access_key: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY" },
73
+ region: "eu-central-1",
74
+ bucket: "application-assets-20200929124523451600000001"
75
+ }
76
+
77
+ provider = WebpackerUploader::Providers::Aws.new(provider_options)
78
+ ```
79
+
80
+ or using an EC2 instance profile:
81
+
82
+ ```ruby
83
+ provider_options = {
84
+ credentials: { instance_profile: true },
85
+ region: "eu-central-1",
86
+ bucket: "application-assets-20200929124523451600000001"
87
+ }
88
+
89
+ provider = WebpackerUploader::Providers::Aws.new(provider_options)
90
+ ```
91
+
92
+ ### Ignore files
93
+
94
+ The uploader can be configured to skip certain files based on the file extension.
95
+ By default `.map` files are excluded. This can be configured through the `ignored_extensions` attribute.
96
+ In order to upload everything pass an empty array.
97
+
98
+ ```ruby
99
+ # skip uploading images
100
+ WebpackerUploader.ignored_extensions = [".png", ".jpg", ".webp"]
101
+ WebpackerUploader.upload!(provider)
102
+ ```
103
+
104
+ ### Prefix remote files
105
+
106
+ Uploaded files can be prefixed by setting the `prefix` parameter during upload:
107
+
108
+ ```ruby
109
+ WebpackerUploader.upload!(provider, prefix: "assets")
110
+ ```
111
+
112
+ This will prefix all remote file paths with `assets` so instead of storing `packs/application-dd6b1cd38bfa093df600.css` it
113
+ will store `assets/packs/application-dd6b1cd38bfa093df600.css`.
114
+
47
115
  ## Development
48
116
 
49
117
  After checking out the repo, run `bin/setup` to install dependencies.
@@ -15,9 +15,10 @@ module WebpackerUploader
15
15
  @instance ||= WebpackerUploader::Instance.new
16
16
  end
17
17
 
18
- delegate :logger, :logger=, :upload!, to: :instance
18
+ delegate :logger, :logger=, :upload!, :ignored_extensions, :ignored_extensions=, to: :instance
19
19
  end
20
20
 
21
21
  require "webpacker_uploader/instance"
22
22
  require "webpacker_uploader/manifest"
23
+ require "webpacker_uploader/mime"
23
24
  require "webpacker_uploader/version"
@@ -1,36 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "mime-types"
4
-
5
3
  class WebpackerUploader::Instance
6
- # TODO make this configurable
7
- IGNORE_EXTENSION = %w[.map].freeze
8
- public_constant :IGNORE_EXTENSION
9
-
10
4
  cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }
5
+ cattr_accessor(:ignored_extensions) { %w[.map] }
11
6
 
12
7
  def manifest
13
8
  @manifest ||= WebpackerUploader::Manifest.new
14
9
  end
15
10
 
16
- def upload!(provider)
17
- manifest.assets.each do |name, path|
18
- path = path[1..-1]
11
+ def upload!(provider, prefix: nil)
12
+ if ignored_extensions.nil?
13
+ raise ArgumentError, "Ignored extensions should be specified as an array"
14
+ end
15
+
16
+ manifest.assets.each do |name, js_path|
17
+ path = js_path[1..-1]
18
+
19
+ remote_path =
20
+ if prefix.nil?
21
+ path
22
+ else
23
+ "#{prefix}/#{path}"
24
+ end
25
+
19
26
  file_path = Rails.root.join("public", path)
20
27
 
21
- if name.end_with?(*IGNORE_EXTENSION)
22
- logger.info("Skipping: #{file_path}")
28
+ if name.end_with?(*ignored_extensions)
29
+ logger.info("Skipping #{file_path}")
23
30
  else
24
- logger.info("Processing: #{file_path}")
25
- provider.upload!(path, file_path, content_type_for(path)) unless name.end_with?(*IGNORE_EXTENSION)
31
+ content_type = WebpackerUploader::Mime.mime_type(path)
32
+ logger.info("Processing #{file_path} as #{content_type}")
33
+
34
+ provider.upload!(remote_path, file_path, content_type)
26
35
  end
27
36
  end
28
37
  end
29
-
30
- private
31
-
32
- def content_type_for(file)
33
- fallback = MIME::Types.type_for(file).first.content_type
34
- Rack::Mime.mime_type(File.extname(file), fallback)
35
- end
36
38
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mime-types"
4
+
5
+ module WebpackerUploader::Mime
6
+ def mime_type(file_path)
7
+ fallback = MIME::Types.type_for(file_path).first&.content_type || "application/octet-stream"
8
+ Rack::Mime.mime_type(File.extname(file_path), fallback)
9
+ end
10
+ module_function :mime_type
11
+ end
@@ -25,6 +25,8 @@ module WebpackerUploader
25
25
  def credentials(options)
26
26
  if options[:profile_name].present?
27
27
  ::Aws::SharedCredentials.new(profile_name: options[:profile_name])
28
+ elsif options.key?(:instance_profile) && options[:instance_profile]
29
+ ::Aws::InstanceProfileCredentials.new
28
30
  else
29
31
  ::Aws::Credentials.new(options[:access_key_id], options[:secret_access_key])
30
32
  end
@@ -1,3 +1,3 @@
1
1
  module WebpackerUploader
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webpacker_uploader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tasos Latsas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-01 00:00:00.000000000 Z
11
+ date: 2021-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: webpacker
@@ -91,6 +91,7 @@ files:
91
91
  - ".github/workflows/ruby.yml"
92
92
  - ".gitignore"
93
93
  - ".rubocop.yml"
94
+ - CHANGELOG.md
94
95
  - CONTRIBUTING.md
95
96
  - Gemfile
96
97
  - Gemfile.lock
@@ -102,6 +103,7 @@ files:
102
103
  - lib/webpacker_uploader.rb
103
104
  - lib/webpacker_uploader/instance.rb
104
105
  - lib/webpacker_uploader/manifest.rb
106
+ - lib/webpacker_uploader/mime.rb
105
107
  - lib/webpacker_uploader/providers/aws.rb
106
108
  - lib/webpacker_uploader/version.rb
107
109
  - webpacker_uploader.gemspec
@@ -110,7 +112,7 @@ licenses:
110
112
  - MIT
111
113
  metadata:
112
114
  homepage_uri: https://github.com/tlatsas/webpacker_uploader
113
- source_code_uri: https://github.com/tlatsas/webpacker_uploader/tree/v0.1.0
115
+ source_code_uri: https://github.com/tlatsas/webpacker_uploader/tree/v0.2.0
114
116
  post_install_message:
115
117
  rdoc_options: []
116
118
  require_paths:
@@ -126,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
128
  - !ruby/object:Gem::Version
127
129
  version: '0'
128
130
  requirements: []
129
- rubygems_version: 3.1.2
131
+ rubygems_version: 3.1.4
130
132
  signing_key:
131
133
  specification_version: 4
132
134
  summary: Uploads manifest.json file contents to the cloud