Add support for ActiveStorage (PR #852)
This commit is contained in:
parent
7574f4eb07
commit
19efd68c5f
10 changed files with 122 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,6 +7,7 @@ tmp
|
||||||
public/assets
|
public/assets
|
||||||
public/system
|
public/system
|
||||||
public/uploads
|
public/uploads
|
||||||
|
storage
|
||||||
vendor/bundle
|
vendor/bundle
|
||||||
|
|
||||||
# no configuration
|
# no configuration
|
||||||
|
|
|
@ -39,6 +39,7 @@ RUN export DATABASE_URL=mysql2://localhost/temp?encoding=utf8 && \
|
||||||
mariadb -e "CREATE DATABASE temp" && \
|
mariadb -e "CREATE DATABASE temp" && \
|
||||||
cp config/app_config.yml.SAMPLE config/app_config.yml && \
|
cp config/app_config.yml.SAMPLE config/app_config.yml && \
|
||||||
cp config/database.yml.MySQL_SAMPLE config/database.yml && \
|
cp config/database.yml.MySQL_SAMPLE config/database.yml && \
|
||||||
|
cp config/storage.yml.SAMPLE config/storage.yml && \
|
||||||
bundle exec rake db:setup assets:precompile && \
|
bundle exec rake db:setup assets:precompile && \
|
||||||
rm -Rf tmp/* && \
|
rm -Rf tmp/* && \
|
||||||
/etc/init.d/mysql stop && \
|
/etc/init.d/mysql stop && \
|
||||||
|
@ -56,6 +57,8 @@ USER nobody
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
|
VOLUME /usr/src/app/storage
|
||||||
|
|
||||||
# cleanup, and by default start web process from Procfile
|
# cleanup, and by default start web process from Procfile
|
||||||
ENTRYPOINT ["./docker-entrypoint.sh"]
|
ENTRYPOINT ["./docker-entrypoint.sh"]
|
||||||
CMD ["./proc-start", "web"]
|
CMD ["./proc-start", "web"]
|
||||||
|
|
|
@ -31,6 +31,9 @@ Rails.application.configure do
|
||||||
config.cache_store = :null_store
|
config.cache_store = :null_store
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Store uploaded files on the local file system (see config/storage.yml for options)
|
||||||
|
config.active_storage.service = :local
|
||||||
|
|
||||||
# Don't care if the mailer can't send.
|
# Don't care if the mailer can't send.
|
||||||
config.action_mailer.raise_delivery_errors = false
|
config.action_mailer.raise_delivery_errors = false
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,9 @@ Rails.application.configure do
|
||||||
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
|
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
|
||||||
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
|
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
|
||||||
|
|
||||||
|
# Store uploaded files on the local file system (see config/storage.yml for options)
|
||||||
|
config.active_storage.service = :local
|
||||||
|
|
||||||
# Mount Action Cable outside main process or domain
|
# Mount Action Cable outside main process or domain
|
||||||
# config.action_cable.mount_path = nil
|
# config.action_cable.mount_path = nil
|
||||||
# config.action_cable.url = 'wss://example.com/cable'
|
# config.action_cable.url = 'wss://example.com/cable'
|
||||||
|
|
|
@ -31,6 +31,10 @@ Rails.application.configure do
|
||||||
|
|
||||||
# Disable request forgery protection in test environment.
|
# Disable request forgery protection in test environment.
|
||||||
config.action_controller.allow_forgery_protection = false
|
config.action_controller.allow_forgery_protection = false
|
||||||
|
|
||||||
|
# Store uploaded files on the local file system in a temporary directory
|
||||||
|
config.active_storage.service = :test
|
||||||
|
|
||||||
config.action_mailer.perform_caching = false
|
config.action_mailer.perform_caching = false
|
||||||
|
|
||||||
# Tell Action Mailer not to deliver emails to the real world.
|
# Tell Action Mailer not to deliver emails to the real world.
|
||||||
|
|
15
config/initializers/active_storage_foodcoop_path.rb
Normal file
15
config/initializers/active_storage_foodcoop_path.rb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
require 'active_storage/service/disk_service'
|
||||||
|
|
||||||
|
module FoodsoftActiveStorageDiskService
|
||||||
|
def self.included(base) # :nodoc:
|
||||||
|
base.class_eval do
|
||||||
|
def path_for(key)
|
||||||
|
File.join root, FoodsoftConfig.scope, folder_for(key), key
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ActiveSupport.on_load(:after_initialize) do
|
||||||
|
ActiveStorage::Service::DiskService.include FoodsoftActiveStorageDiskService
|
||||||
|
end
|
34
config/storage.yml.SAMPLE
Normal file
34
config/storage.yml.SAMPLE
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
test:
|
||||||
|
service: Disk
|
||||||
|
root: <%= Rails.root.join("tmp/storage") %>
|
||||||
|
|
||||||
|
local:
|
||||||
|
service: Disk
|
||||||
|
root: <%= Rails.root.join("storage") %>
|
||||||
|
|
||||||
|
# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
|
||||||
|
# amazon:
|
||||||
|
# service: S3
|
||||||
|
# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
|
||||||
|
# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
|
||||||
|
# region: us-east-1
|
||||||
|
# bucket: your_own_bucket
|
||||||
|
|
||||||
|
# Remember not to checkin your GCS keyfile to a repository
|
||||||
|
# google:
|
||||||
|
# service: GCS
|
||||||
|
# project: your_project
|
||||||
|
# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
|
||||||
|
# bucket: your_own_bucket
|
||||||
|
|
||||||
|
# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
|
||||||
|
# microsoft:
|
||||||
|
# service: AzureStorage
|
||||||
|
# storage_account_name: your_account_name
|
||||||
|
# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
|
||||||
|
# container: your_container_name
|
||||||
|
|
||||||
|
# mirror:
|
||||||
|
# service: Mirror
|
||||||
|
# primary: local
|
||||||
|
# mirrors: [ amazon, google, microsoft ]
|
|
@ -0,0 +1,27 @@
|
||||||
|
# This migration comes from active_storage (originally 20170806125915)
|
||||||
|
class CreateActiveStorageTables < ActiveRecord::Migration[4.2][5.2]
|
||||||
|
def change
|
||||||
|
create_table :active_storage_blobs do |t|
|
||||||
|
t.string :key, null: false
|
||||||
|
t.string :filename, null: false
|
||||||
|
t.string :content_type
|
||||||
|
t.text :metadata
|
||||||
|
t.bigint :byte_size, null: false
|
||||||
|
t.string :checksum, null: false
|
||||||
|
t.datetime :created_at, null: false
|
||||||
|
|
||||||
|
t.index [:key], unique: true
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table :active_storage_attachments do |t|
|
||||||
|
t.string :name, null: false
|
||||||
|
t.references :record, null: false, polymorphic: true, index: false
|
||||||
|
t.references :blob, null: false
|
||||||
|
|
||||||
|
t.datetime :created_at, null: false
|
||||||
|
|
||||||
|
t.index [:record_type, :record_id, :name, :blob_id], name: "index_active_storage_attachments_uniqueness", unique: true
|
||||||
|
t.foreign_key :active_storage_blobs, column: :blob_id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
21
db/schema.rb
21
db/schema.rb
|
@ -12,6 +12,27 @@
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2021_02_05_090257) do
|
ActiveRecord::Schema.define(version: 2021_02_05_090257) do
|
||||||
|
|
||||||
|
create_table "active_storage_attachments", id: :integer, force: :cascade do |t|
|
||||||
|
t.string "name", null: false
|
||||||
|
t.string "record_type", null: false
|
||||||
|
t.bigint "record_id", null: false
|
||||||
|
t.bigint "blob_id", null: false
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
|
||||||
|
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "active_storage_blobs", id: :integer, force: :cascade do |t|
|
||||||
|
t.string "key", null: false
|
||||||
|
t.string "filename", null: false
|
||||||
|
t.string "content_type"
|
||||||
|
t.text "metadata"
|
||||||
|
t.bigint "byte_size", null: false
|
||||||
|
t.string "checksum", null: false
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
|
||||||
|
end
|
||||||
|
|
||||||
create_table "article_categories", id: :integer, force: :cascade do |t|
|
create_table "article_categories", id: :integer, force: :cascade do |t|
|
||||||
t.string "name", default: "", null: false
|
t.string "name", default: "", null: false
|
||||||
t.string "description"
|
t.string "description"
|
||||||
|
|
|
@ -33,6 +33,7 @@ namespace :foodsoft do
|
||||||
setup_app_config
|
setup_app_config
|
||||||
setup_development
|
setup_development
|
||||||
setup_database
|
setup_database
|
||||||
|
setup_storage
|
||||||
start_mailcatcher
|
start_mailcatcher
|
||||||
puts yellow "All done! Your foodsoft setup should be running smoothly."
|
puts yellow "All done! Your foodsoft setup should be running smoothly."
|
||||||
start_server
|
start_server
|
||||||
|
@ -43,6 +44,7 @@ namespace :foodsoft do
|
||||||
puts yellow "This task will help you get your foodcoop running in development via docker."
|
puts yellow "This task will help you get your foodcoop running in development via docker."
|
||||||
setup_app_config
|
setup_app_config
|
||||||
setup_development
|
setup_development
|
||||||
|
setup_storage
|
||||||
setup_run_rake_db_setup
|
setup_run_rake_db_setup
|
||||||
puts yellow "All done! Your foodsoft setup should be running smoothly via docker."
|
puts yellow "All done! Your foodsoft setup should be running smoothly via docker."
|
||||||
end
|
end
|
||||||
|
@ -112,6 +114,15 @@ def setup_development
|
||||||
reminder(file)
|
reminder(file)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def setup_storage
|
||||||
|
file = 'config/storage.yml'
|
||||||
|
return nil if skip?(file)
|
||||||
|
|
||||||
|
puts yellow "Copying #{file}..."
|
||||||
|
%x(cp -p #{Rails.root.join("#{file}.SAMPLE")} #{Rails.root.join(file)})
|
||||||
|
reminder(file)
|
||||||
|
end
|
||||||
|
|
||||||
def start_mailcatcher
|
def start_mailcatcher
|
||||||
return nil if ENV['MAILCATCHER_PORT'] # skip when it has an existing Docker container
|
return nil if ENV['MAILCATCHER_PORT'] # skip when it has an existing Docker container
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue