Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Active Storage Preview Warnings #739

Merged
merged 5 commits into from
Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions hatchet.json
Expand Up @@ -76,6 +76,10 @@
"rails51": [
"schneems/rails51_webpacker"
],
"rails52": [
"sharpstone/active_storage_non_local",
"sharpstone/active_storage_local"
],
"multibuildpack": [
"sharpstone/node_multi"
],
Expand Down
4 changes: 4 additions & 0 deletions hatchet.lock
Expand Up @@ -79,6 +79,10 @@
- fc537b7091260d8cc6fdf2bc0fac7032d910a261
- - "./repos/rails51/rails51_webpacker"
- d8460fc9eeb93108b6037a3ea755ec7a111ad03c
- - "./repos/rails52/active_storage_local"
- a1b6b18e081001b407898532fb9cb061a29ceee1
- - "./repos/rails52/active_storage_non_local"
- cba59b7559f1f806684b65654228d44fcda91a82
- - "./repos/rake/asset_precompile_fail"
- 16f7834331d6bb3fc5c284130b14eb1ff74d99d5
- - "./repos/rake/asset_precompile_not_found"
Expand Down
2 changes: 1 addition & 1 deletion lib/language_pack/base.rb
Expand Up @@ -21,7 +21,7 @@ class LanguagePack::Base
DEFAULT_LEGACY_STACK = "cedar"
ROOT_DIR = File.expand_path("../../..", __FILE__)

attr_reader :build_path, :cache
attr_reader :build_path, :cache, :stack

# changes directory to the build_path
# @param [String] the path of the build dir
Expand Down
53 changes: 53 additions & 0 deletions lib/language_pack/rails5.rb
Expand Up @@ -30,4 +30,57 @@ def default_config_vars
def install_plugins
# do not install plugins, do not call super, do not warn
end

def best_practice_warnings
return unless bundler.has_gem?("activestorage")
return unless File.exist?("config/storage.yml")

warn_local_storage if local_storage?
warn_no_ffmpeg if needs_ffmpeg?
end

private
def has_ffmpeg?
run("which ffmpeg")
return $?.success?
end

def needs_ffmpeg?
!has_ffmpeg?
end

def local_storage?
out = run!('bin/rails runner "puts %Q{heroku_detecting_active_storage_config=#{Rails.application.config.active_storage.service}}"')
out =~ /heroku_detecting_active_storage_config=local/
end

def warn_local_storage
mcount("warn.activestorage.local_storage")
warn(<<-WARNING)
You set your `config.active_storage.service` to :local in production.
If you are uploading files to this app, they will not persist after the app
is restarted, on one-off dynos, or if the app has multiple dynos.
Heroku applications have an ephemeral files system. To
persist uploaded files, please use a service such as S3 and update your Rails
configuration.

For more information can be found in this article:
https://devcenter.heroku.com/articles/active-storage-on-heroku

WARNING
end

def warn_no_ffmpeg
mcount("warn.activestorage.no_binaries.stack-#{stack}")
mcount("warn.activestorage.no_binaries.all")
warn(<<-WARNING)
We detected that some binary dependencies required to
use all the preview features of Active Storage are not
present on this system.

For more information please see:
https://devcenter.heroku.com/articles/active-storage-on-heroku

WARNING
end
end
25 changes: 23 additions & 2 deletions spec/hatchet/rails5_spec.rb
@@ -1,10 +1,31 @@
require_relative '../spec_helper'

describe "Rails 5.x" do

describe "Rails 5" do
it "works" do
Hatchet::Runner.new("rails5").deploy do |app, heroku|
expect(app.run("rails -v")).to match("")
end
end

describe "active storage" do
it "non-local storage warnings" do
Hatchet::Runner.new("active_storage_non_local").deploy do |app, heroku|
expect(app.output).to match('binary dependencies required')
expect(app.output).to_not match('config.active_storage.service')
end
end

it "local storage warnings" do
Hatchet::Runner.new(
"active_storage_local",
buildpacks: [
# "https://github.com/heroku/heroku-buildpack-activestorage-preview",
Hatchet::App.default_buildpack
]
).deploy do |app, heroku|
expect(app.output).to match('binary dependencies required')
expect(app.output).to match('config.active_storage.service')
end
end
end
end