From cf8646eef58ee6ff6ef70e6c175e161e85091ea4 Mon Sep 17 00:00:00 2001 From: msdundar Date: Wed, 8 Aug 2018 02:18:47 +0300 Subject: [PATCH 1/4] Initialize active_storage tables --- ...te_active_storage_tables.active_storage.rb | 26 +++++++++++++++++++ db/schema.rb | 23 +++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20180807230631_create_active_storage_tables.active_storage.rb diff --git a/db/migrate/20180807230631_create_active_storage_tables.active_storage.rb b/db/migrate/20180807230631_create_active_storage_tables.active_storage.rb new file mode 100644 index 000000000..360e0d1b7 --- /dev/null +++ b/db/migrate/20180807230631_create_active_storage_tables.active_storage.rb @@ -0,0 +1,26 @@ +# This migration comes from active_storage (originally 20170806125915) +class CreateActiveStorageTables < ActiveRecord::Migration[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 + end + end +end diff --git a/db/schema.rb b/db/schema.rb index a1ea2ffa9..07b75c1a6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_08_03_203638) do +ActiveRecord::Schema.define(version: 2018_08_07_230631) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -35,6 +35,27 @@ t.datetime "updated_at", null: false end + create_table "active_storage_attachments", 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", 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 "addresses", force: :cascade do |t| t.integer "type", default: 4, null: false t.string "phone_number", default: "", null: false From 71f0bfffc6fc6e42563eda26f723c82477cb7395 Mon Sep 17 00:00:00 2001 From: msdundar Date: Wed, 8 Aug 2018 02:19:06 +0300 Subject: [PATCH 2/4] Add minio credentials to credentials.yml.enc From 9b01a4d6689eac6d543f0ad742c3cd27488fd3ed Mon Sep 17 00:00:00 2001 From: msdundar Date: Wed, 8 Aug 2018 03:06:21 +0300 Subject: [PATCH 3/4] Ignore /storage folder from git --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7b2093c40..500ba0bba 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ .byebug_history .vagrant*/ .env +/storage/* # never remove! config/master.key \ No newline at end of file From b4b4b2c428caa7f8ae5e1a8eee224e7fecae41f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Serhat=20D=C3=BCndar?= Date: Wed, 8 Aug 2018 03:16:15 +0300 Subject: [PATCH 4/4] Configure minio as storage of production Fixes #171. --- Gemfile | 3 +++ Gemfile.lock | 19 ++++++++++++++++++- config/environments/production.rb | 2 +- config/storage.yml | 21 +++++++++++---------- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index 3fed47413..c23a69fb0 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,9 @@ gem 'sidekiq' # active-record gem 'ancestry' +# active-storage +gem 'aws-sdk-s3', require: false + # authentication gem 'devise' diff --git a/Gemfile.lock b/Gemfile.lock index 83d06c68b..307e486bf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -53,6 +53,21 @@ GEM io-like (~> 0.3.0) arel (9.0.0) ast (2.4.0) + aws-eventstream (1.0.1) + aws-partitions (1.97.0) + aws-sdk-core (3.24.0) + aws-eventstream (~> 1.0) + aws-partitions (~> 1.0) + aws-sigv4 (~> 1.0) + jmespath (~> 1.0) + aws-sdk-kms (1.7.0) + aws-sdk-core (~> 3) + aws-sigv4 (~> 1.0) + aws-sdk-s3 (1.17.0) + aws-sdk-core (~> 3, >= 3.21.2) + aws-sdk-kms (~> 1) + aws-sigv4 (~> 1.0) + aws-sigv4 (1.0.3) axiom-types (0.1.1) descendants_tracker (~> 0.0.4) ice_nine (~> 0.11.0) @@ -142,6 +157,7 @@ GEM jbuilder (2.7.0) activesupport (>= 4.2.0) multi_json (>= 1.2) + jmespath (1.4.0) json (2.1.0) kwalify (0.7.2) launchy (2.4.3) @@ -337,6 +353,7 @@ PLATFORMS DEPENDENCIES ancestry + aws-sdk-s3 bcrypt (~> 3.1.7) bootsnap (>= 1.1.0) brakeman @@ -383,4 +400,4 @@ RUBY VERSION ruby 2.5.1p57 BUNDLED WITH - 1.16.2 + 1.16.3 diff --git a/config/environments/production.rb b/config/environments/production.rb index f81d42569..dc06f8a5f 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -41,7 +41,7 @@ # 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 + config.active_storage.service = :minio # Mount Action Cable outside main process or domain # config.action_cable.mount_path = nil diff --git a/config/storage.yml b/config/storage.yml index d32f76e8f..c3439ed79 100644 --- a/config/storage.yml +++ b/config/storage.yml @@ -1,24 +1,25 @@ test: service: Disk - root: <%= Rails.root.join("tmp/storage") %> + root: <%= Rails.root.join('tmp/storage') %> local: service: Disk - root: <%= Rails.root.join("storage") %> + 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 +minio: + service: S3 + access_key_id: <%= Rails.application.credentials.minio[:access_key] %> + secret_access_key: <%= Rails.application.credentials.minio[:secret_key] %> + region: us-east-1 # required for aws GEMs, can not be nil + bucket: nokul + endpoint: https://s3.omu.sh + force_path_style: true # use https://domain.com/bucket, instead of bucket.domain.com # Remember not to checkin your GCS keyfile to a repository # google: # service: GCS # project: your_project -# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# 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)