heroku_error_pages 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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +24 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +75 -0
- data/Rakefile +12 -0
- data/heroku_error_pages.gemspec +40 -0
- data/lib/heroku_error_pages/config.rb +32 -0
- data/lib/heroku_error_pages/page_config.rb +14 -0
- data/lib/heroku_error_pages/public_asset.rb +28 -0
- data/lib/heroku_error_pages/railtie.rb +11 -0
- data/lib/heroku_error_pages/renderer.rb +33 -0
- data/lib/heroku_error_pages/version.rb +5 -0
- data/lib/heroku_error_pages.rb +63 -0
- data/lib/tasks/heroku_error_pages.rake +8 -0
- data/sig/heroku_error_pages.rbs +4 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dcbc58c8c09a48ecfc080524888410620dd4c0e56e35cb37efb29398e814d7d4
|
4
|
+
data.tar.gz: dc633286704481c7a6c1b111f0c2b0231c6528b35ed2f32574ecedb6fdc096a1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e718a4161a2ebc3d01596981fe636abc1fa7d1a49124593fac8a1d3fe1460eb70fde2a764e4f5c5a6dcfca2d754fa80b2609c558fbc1fea3fe72809619afa4ea
|
7
|
+
data.tar.gz: bd8a9ac179af8087514b18fee7fced133a79c4eed86afbfcb16669cce4b6c53266452f15b42bcf7f9ba30e37c78adda387bb313cf0861be78bb4dc7b26387574
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 3.1
|
3
|
+
NewCops: enable
|
4
|
+
SuggestExtensions: false
|
5
|
+
|
6
|
+
Style/StringLiterals:
|
7
|
+
Enabled: true
|
8
|
+
EnforcedStyle: double_quotes
|
9
|
+
|
10
|
+
Style/StringLiteralsInInterpolation:
|
11
|
+
Enabled: true
|
12
|
+
EnforcedStyle: double_quotes
|
13
|
+
|
14
|
+
Layout/LineLength:
|
15
|
+
Max: 120
|
16
|
+
|
17
|
+
Style/Documentation:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Metrics/AbcSize:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Metrics/MethodLength:
|
24
|
+
Enabled: false
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Jaco Pretorius
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# HerokuErrorPages
|
2
|
+
|
3
|
+
Heroku allows you to configure custom error pages for application/launch errors and maintenance mode. https://devcenter.heroku.com/articles/error-pages#customize-pages
|
4
|
+
|
5
|
+
This gem allows you to easily generate one or both of these pages during your Heroku deployment and store the static HTML on Amazon S3. This means your custom error pages are always using your latest stylesheets. You simply supply the template and S3 configuration variables.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
$ bundle add heroku_error_pages
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
$ gem install heroku_error_pages
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Configure the error and/or maintenance pages. For a rails application, create a file like `config/initializers/heroku_error_pages.rb`.
|
20
|
+
|
21
|
+
Sample configuration:
|
22
|
+
|
23
|
+
```
|
24
|
+
HerokuErrorPages.configure do |config|
|
25
|
+
# Required
|
26
|
+
config.s3_bucket_name = "your-s3-bucket-name"
|
27
|
+
|
28
|
+
# Optional
|
29
|
+
config.aws_access_key_id = "aws-secret-key-id" # defaults to `ENV["AWS_ACCESS_KEY_ID"]`
|
30
|
+
config.aws_secret_access_key = "aws-secret-access-key" # defaults to `ENV["AWS_SECRET_ACCESS_KEY"]`
|
31
|
+
config.aws_region = "some-region" # defaults to `us-east-1`
|
32
|
+
|
33
|
+
# at least one page must be configured
|
34
|
+
config.configure_error_page(
|
35
|
+
s3_path: 'application_error.html', # where the html will be stored in your S3 bucket
|
36
|
+
template: 'errors/show', # the Rails template to render
|
37
|
+
assigns: { # optional, any variables to assign to the template
|
38
|
+
status: :internal_server_error
|
39
|
+
},
|
40
|
+
controller: ErrorsController # optional, defaults to ActionController::Base
|
41
|
+
)
|
42
|
+
|
43
|
+
config.configure_maintenance_page(
|
44
|
+
# same options as configure_error_page
|
45
|
+
)
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
Add this to your `Procfile` to configure Heroku to deploy your custom pages as part of deployments:
|
50
|
+
|
51
|
+
```
|
52
|
+
release: bundle exec rake heroku_error_pages:deploy
|
53
|
+
```
|
54
|
+
|
55
|
+
You can verify that your error pages are being served correctly out of S3 by navigating there in your browser, eg. `https://your-s3-bucket.s3.amazonaws.com/application_error.html`. Once you are satisfied you can configure Heroku to use your custom error pages:
|
56
|
+
|
57
|
+
```
|
58
|
+
heroku config:set \
|
59
|
+
ERROR_PAGE_URL=//your-s3-bucket.s3.amazonaws.com/application_error.html \
|
60
|
+
MAINTENANCE_PAGE_URL=//your-s3-bucket.s3.amazonaws.com/your_maintenance_page.html
|
61
|
+
```
|
62
|
+
|
63
|
+
## Development
|
64
|
+
|
65
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
66
|
+
|
67
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Jaco-Pretorius/heroku_error_pages.
|
72
|
+
|
73
|
+
## License
|
74
|
+
|
75
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/heroku_error_pages/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "heroku_error_pages"
|
7
|
+
spec.version = HerokuErrorPages::VERSION
|
8
|
+
spec.authors = ["Jaco Pretorius"]
|
9
|
+
spec.email = ["me@jacopretorius.net"]
|
10
|
+
|
11
|
+
spec.summary = "Deploy your custom Heroku error pages to S3 as part of your app deployment"
|
12
|
+
spec.description = "Continuously deploy your custom Heroku error pages to S3 as part of your deployment pipeline"
|
13
|
+
spec.homepage = "https://github.com/Jaco-Pretorius/heroku_error_pages"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 3.1"
|
16
|
+
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(__dir__) do
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
# Uncomment to register a new dependency of your gem
|
34
|
+
spec.add_dependency "aws-sdk-s3", "~> 1"
|
35
|
+
spec.add_dependency "rails", ">= 6.0", "< 8.0"
|
36
|
+
|
37
|
+
# For more information and examples about making a new gem, check out our
|
38
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
39
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
40
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HerokuErrorPages
|
4
|
+
class Config
|
5
|
+
attr_accessor :aws_access_key_id, :aws_secret_access_key, :aws_region, :s3_bucket_name
|
6
|
+
attr_reader :error_page, :maintenance_page
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@aws_access_key_id = ENV.fetch("AWS_ACCESS_KEY_ID", nil)
|
10
|
+
@aws_secret_access_key = ENV.fetch("AWS_SECRET_ACCESS_KEY", nil)
|
11
|
+
@aws_region = "us-east-1"
|
12
|
+
end
|
13
|
+
|
14
|
+
def configure_error_page(s3_path:, template:, assigns: nil, controller: nil)
|
15
|
+
@error_page = PageConfig.new(
|
16
|
+
s3_path: s3_path,
|
17
|
+
template: template,
|
18
|
+
assigns: assigns,
|
19
|
+
controller: controller
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def config_maintenance_page(s3_path:, template:, assigns: nil, controller: nil)
|
24
|
+
@maintenance_page = PageConfig.new(
|
25
|
+
s3_path: s3_path,
|
26
|
+
template: template,
|
27
|
+
assigns: assigns,
|
28
|
+
controller: controller
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HerokuErrorPages
|
4
|
+
class PageConfig
|
5
|
+
attr_accessor :s3_path, :template, :assigns, :controller
|
6
|
+
|
7
|
+
def initialize(s3_path:, template:, assigns:, controller:)
|
8
|
+
@s3_path = s3_path
|
9
|
+
@template = template
|
10
|
+
@assigns = assigns || {}
|
11
|
+
@controller = controller || ActionController::Base
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HerokuErrorPages
|
4
|
+
class PublicAsset
|
5
|
+
class << self
|
6
|
+
def all
|
7
|
+
Dir.glob(Rails.public_path.join("*", "**")).map do |absolute_path|
|
8
|
+
new(absolute_path)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :absolute_path
|
14
|
+
|
15
|
+
def initialize(absolute_path)
|
16
|
+
@absolute_path = absolute_path
|
17
|
+
end
|
18
|
+
|
19
|
+
def relative_path
|
20
|
+
@relative_path ||= Pathname.new(absolute_path).relative_path_from(Rails.public_path).to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
def mime_type
|
24
|
+
extension = File.extname(absolute_path).strip.downcase[1..]
|
25
|
+
Mime::Type.lookup_by_extension(extension)&.to_s
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HerokuErrorPages
|
4
|
+
class Renderer
|
5
|
+
class << self
|
6
|
+
def render_html(page_config)
|
7
|
+
new(page_config.template, page_config.assigns, page_config.controller).html
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(template, assigns, controller)
|
12
|
+
@template = template
|
13
|
+
@assigns = assigns
|
14
|
+
@controller = controller
|
15
|
+
end
|
16
|
+
|
17
|
+
def html
|
18
|
+
@html ||= generate_html
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :template, :assigns, :controller
|
24
|
+
|
25
|
+
def generate_html
|
26
|
+
controller = Class.new(controller) do
|
27
|
+
self.asset_host = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
controller.render(template: template, assigns: assigns)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "heroku_error_pages/version"
|
4
|
+
require_relative "heroku_error_pages/config"
|
5
|
+
require_relative "heroku_error_pages/page_config"
|
6
|
+
require_relative "heroku_error_pages/railtie"
|
7
|
+
require_relative "heroku_error_pages/renderer"
|
8
|
+
require_relative "heroku_error_pages/public_asset"
|
9
|
+
|
10
|
+
module HerokuErrorPages
|
11
|
+
class << self
|
12
|
+
def config
|
13
|
+
@config ||= Config.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def configure
|
17
|
+
yield config
|
18
|
+
end
|
19
|
+
|
20
|
+
def deploy
|
21
|
+
raise "No custom pages were configured" unless config.error_page || config.maintenance_page
|
22
|
+
|
23
|
+
s3_client = Aws::S3::Client.new(
|
24
|
+
credentials: Aws::Credentials.new(
|
25
|
+
config.aws_access_key_id,
|
26
|
+
config.aws_secret_access_key
|
27
|
+
),
|
28
|
+
region: config.aws_region
|
29
|
+
)
|
30
|
+
|
31
|
+
deploy_page(config.error_page, s3_client)
|
32
|
+
deploy_page(config.maintenance_page, s3_client)
|
33
|
+
deploy_public_assets(s3_client)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def deploy_page(page_config, s3_client)
|
39
|
+
return if page_config.nil?
|
40
|
+
|
41
|
+
s3_object = Aws::S3::Object.new(config.s3_bucket_name, page_config.s3_path, client: s3_client)
|
42
|
+
s3_object.put(
|
43
|
+
acl: "public-read",
|
44
|
+
body: Renderer.render_html(page_config),
|
45
|
+
content_type: "text/html"
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def deploy_public_assets(s3_client)
|
50
|
+
PublicAsset.all.each do |public_asset|
|
51
|
+
s3_absolute_path = "#{config.s3_bucket_name}/#{public_asset.relative_path}"
|
52
|
+
Rails.logger.info "Uploading #{public_asset.absolute_path} to #{s3_absolute_path}"
|
53
|
+
|
54
|
+
s3_object = Aws::S3::Object.new(config.s3_bucket_name, public_asset.relative_path, client: s3_client)
|
55
|
+
s3_object.upload_file(
|
56
|
+
public_asset.absolute_path,
|
57
|
+
acl: "public-read",
|
58
|
+
content_type: public_asset.mime_type
|
59
|
+
)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: heroku_error_pages
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jaco Pretorius
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-04-18 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: aws-sdk-s3
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '1'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '1'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rails
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6.0'
|
33
|
+
- - "<"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '8.0'
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '6.0'
|
43
|
+
- - "<"
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '8.0'
|
46
|
+
description: Continuously deploy your custom Heroku error pages to S3 as part of your
|
47
|
+
deployment pipeline
|
48
|
+
email:
|
49
|
+
- me@jacopretorius.net
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- ".rspec"
|
55
|
+
- ".rubocop.yml"
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- heroku_error_pages.gemspec
|
61
|
+
- lib/heroku_error_pages.rb
|
62
|
+
- lib/heroku_error_pages/config.rb
|
63
|
+
- lib/heroku_error_pages/page_config.rb
|
64
|
+
- lib/heroku_error_pages/public_asset.rb
|
65
|
+
- lib/heroku_error_pages/railtie.rb
|
66
|
+
- lib/heroku_error_pages/renderer.rb
|
67
|
+
- lib/heroku_error_pages/version.rb
|
68
|
+
- lib/tasks/heroku_error_pages.rake
|
69
|
+
- sig/heroku_error_pages.rbs
|
70
|
+
homepage: https://github.com/Jaco-Pretorius/heroku_error_pages
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata:
|
74
|
+
allowed_push_host: https://rubygems.org
|
75
|
+
homepage_uri: https://github.com/Jaco-Pretorius/heroku_error_pages
|
76
|
+
source_code_uri: https://github.com/Jaco-Pretorius/heroku_error_pages
|
77
|
+
rubygems_mfa_required: 'true'
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '3.1'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubygems_version: 3.6.6
|
93
|
+
specification_version: 4
|
94
|
+
summary: Deploy your custom Heroku error pages to S3 as part of your app deployment
|
95
|
+
test_files: []
|