From d2efbdef029fec314982987db6b0d4cc1844114d Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Fri, 30 Mar 2018 20:39:40 +0200 Subject: [PATCH] upgrade to rails 5.2rc2 --- Dockerfile | 1 + Gemfile | 7 +- Gemfile.lock | 100 +++++++++++------- app/models/provider.rb | 2 +- config/application.rb | 1 + config/boot.rb | 1 + config/environments/production.rb | 2 + config/environments/stage.rb | 2 + .../application_controller_renderer.rb | 10 +- .../new_framework_defaults_5_2.rb | 35 ++++++ config/spring.rb | 4 +- config/storage.yml | 14 +++ ...te_active_storage_tables.active_storage.rb | 28 +++++ db/schema.rb | 44 ++++++-- docker-compose.yml | 1 + storage/.gitkeep | 0 16 files changed, 193 insertions(+), 59 deletions(-) create mode 100644 config/initializers/new_framework_defaults_5_2.rb create mode 100644 config/storage.yml create mode 100644 db/migrate/20180330175050_create_active_storage_tables.active_storage.rb create mode 100644 storage/.gitkeep diff --git a/Dockerfile b/Dockerfile index 74749ae14..1b0ace042 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,6 +53,7 @@ COPY vendor/docker/ntp.conf /etc/ntp.conf # Copy webapp folder COPY . /home/app/webapp/ RUN mkdir -p /home/app/webapp/tmp/pids && \ + mkdir -p /home/app/webapp/tmp/storage && \ mkdir -p /home/app/webapp/vendor/bundle && \ chown -R app:app /home/app/webapp && \ chmod -R 755 /home/app/webapp diff --git a/Gemfile b/Gemfile index cf9802e72..4a561f8d9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,8 @@ source 'https://rubygems.org' -gem 'rails', '~> 5.1.1' -gem 'mysql2', '~> 0.4.10' +gem 'rails', '~> 5.2.0.rc2' +gem 'bootsnap', '~> 1.2', '>= 1.2.1' +gem 'mysql2', '~> 0.4.4' gem 'dotenv' gem 'multi_json' gem 'json', '~> 1.8', '>= 1.8.5' @@ -31,6 +32,7 @@ gem 'countries', '~> 2.1', '>= 2.1.2' gem 'aasm', '~> 4.12', '>= 4.12.3' gem "facets", require: false gem 'shoryuken', '~> 3.2', '>= 3.2.2' +gem "aws-sdk-s3", require: false gem 'aws-sdk-sqs', '~> 1.3' gem 'bergamasco', '~> 0.3.10' gem 'base32-url', '~> 0.3' @@ -41,6 +43,7 @@ gem 'flipper-active_support_cache_store' gem 'rack-cors', '~> 1.0', '>= 1.0.2', :require => 'rack/cors' gem 'strip_attributes', '~> 1.8' gem 'slack-notifier', '~> 2.1' +gem 'mini_magick', '~> 4.8' group :development, :test do gem 'rspec-rails', '~> 3.5', '>= 3.5.2' diff --git a/Gemfile.lock b/Gemfile.lock index 058f08db2..169eb71bb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,25 +3,25 @@ GEM specs: aasm (4.12.3) concurrent-ruby (~> 1.0) - actioncable (5.1.6) - actionpack (= 5.1.6) + actioncable (5.2.0.rc2) + actionpack (= 5.2.0.rc2) nio4r (~> 2.0) - websocket-driver (~> 0.6.1) - actionmailer (5.1.6) - actionpack (= 5.1.6) - actionview (= 5.1.6) - activejob (= 5.1.6) + websocket-driver (>= 0.6.1) + actionmailer (5.2.0.rc2) + actionpack (= 5.2.0.rc2) + actionview (= 5.2.0.rc2) + activejob (= 5.2.0.rc2) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.1.6) - actionview (= 5.1.6) - activesupport (= 5.1.6) + actionpack (5.2.0.rc2) + actionview (= 5.2.0.rc2) + activesupport (= 5.2.0.rc2) rack (~> 2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.1.6) - activesupport (= 5.1.6) + actionview (5.2.0.rc2) + activesupport (= 5.2.0.rc2) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) @@ -31,16 +31,20 @@ GEM activemodel (>= 4.1, < 6) case_transform (>= 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3) - activejob (5.1.6) - activesupport (= 5.1.6) + activejob (5.2.0.rc2) + activesupport (= 5.2.0.rc2) globalid (>= 0.3.6) - activemodel (5.1.6) - activesupport (= 5.1.6) - activerecord (5.1.6) - activemodel (= 5.1.6) - activesupport (= 5.1.6) - arel (~> 8.0) - activesupport (5.1.6) + activemodel (5.2.0.rc2) + activesupport (= 5.2.0.rc2) + activerecord (5.2.0.rc2) + activemodel (= 5.2.0.rc2) + activesupport (= 5.2.0.rc2) + arel (>= 9.0) + activestorage (5.2.0.rc2) + actionpack (= 5.2.0.rc2) + activerecord (= 5.2.0.rc2) + marcel (~> 0.3.1) + activesupport (5.2.0.rc2) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) @@ -49,12 +53,19 @@ GEM public_suffix (>= 2.0.2, < 4.0) aggregate (0.2.2) api-pagination (4.7.0) - arel (8.0.0) + arel (9.0.0) aws-partitions (1.75.0) aws-sdk-core (3.18.1) aws-partitions (~> 1.0) aws-sigv4 (~> 1.0) jmespath (~> 1.0) + aws-sdk-kms (1.5.0) + aws-sdk-core (~> 3) + aws-sigv4 (~> 1.0) + aws-sdk-s3 (1.8.2) + aws-sdk-core (~> 3) + aws-sdk-kms (~> 1) + aws-sigv4 (~> 1.0) aws-sdk-sqs (1.3.0) aws-sdk-core (~> 3) aws-sigv4 (~> 1.0) @@ -99,10 +110,12 @@ GEM rdf-rdfxml (~> 2.0) rdf-turtle (~> 2.2) thor (~> 0.19) + bootsnap (1.2.1) + msgpack (~> 1.0) bugsnag (6.6.4) concurrent-ruby (~> 1.0) builder (3.2.3) - byebug (10.0.1) + byebug (10.0.2) cancancan (2.1.3) capybara (2.18.0) addressable @@ -247,6 +260,8 @@ GEM mini_mime (>= 0.1.1) mailgun-ruby (1.1.9) rest-client (~> 2.0) + marcel (0.3.2) + mimemagic (~> 0.3.2) maremma (3.6.2) activesupport (>= 4.2.5, < 6) addressable (>= 2.3.6) @@ -262,11 +277,14 @@ GEM mime-types (3.1) mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) + mimemagic (0.3.2) + mini_magick (4.8.0) mini_mime (1.0.0) mini_portile2 (2.3.0) minitest (5.11.3) money (6.10.1) i18n (>= 0.6.4, < 1.0) + msgpack (1.2.4) multi_json (1.13.1) multipart-post (2.0.0) mysql2 (0.4.10) @@ -293,26 +311,27 @@ GEM rack-cors (1.0.2) rack-test (1.0.0) rack (>= 1.0, < 3) - rails (5.1.6) - actioncable (= 5.1.6) - actionmailer (= 5.1.6) - actionpack (= 5.1.6) - actionview (= 5.1.6) - activejob (= 5.1.6) - activemodel (= 5.1.6) - activerecord (= 5.1.6) - activesupport (= 5.1.6) + rails (5.2.0.rc2) + actioncable (= 5.2.0.rc2) + actionmailer (= 5.2.0.rc2) + actionpack (= 5.2.0.rc2) + actionview (= 5.2.0.rc2) + activejob (= 5.2.0.rc2) + activemodel (= 5.2.0.rc2) + activerecord (= 5.2.0.rc2) + activestorage (= 5.2.0.rc2) + activesupport (= 5.2.0.rc2) bundler (>= 1.3.0) - railties (= 5.1.6) + railties (= 5.2.0.rc2) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) rails-html-sanitizer (1.0.4) loofah (~> 2.2, >= 2.2.2) - railties (5.1.6) - actionpack (= 5.1.6) - activesupport (= 5.1.6) + railties (5.2.0.rc2) + actionpack (= 5.2.0.rc2) + activesupport (= 5.2.0.rc2) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) @@ -417,7 +436,7 @@ GEM addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff - websocket-driver (0.6.5) + websocket-driver (0.7.0) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.3) xpath (3.0.0) @@ -430,6 +449,7 @@ DEPENDENCIES aasm (~> 4.12, >= 4.12.3) active_model_serializers (~> 0.10.0) api-pagination + aws-sdk-s3 aws-sdk-sqs (~> 1.3) base32-url (~> 0.3) bcrypt (~> 3.1.7) @@ -437,6 +457,7 @@ DEPENDENCIES better_errors binding_of_caller bolognese (~> 0.9, >= 0.9) + bootsnap (~> 1.2, >= 1.2.1) bugsnag (~> 6.1, >= 6.1.1) byebug cancancan (~> 2.0) @@ -465,14 +486,15 @@ DEPENDENCIES lograge (~> 0.5) mailgun-ruby (~> 1.1, >= 1.1.8) maremma (>= 3.5) + mini_magick (~> 4.8) multi_json - mysql2 (~> 0.4.10) + mysql2 (~> 0.4.4) nokogiri (~> 1.8.1) oj (~> 2.18, >= 2.18.1) premailer (~> 1.11, >= 1.11.1) pwqgen.rb (~> 0.1.0) rack-cors (~> 1.0, >= 1.0.2) - rails (~> 5.1.1) + rails (~> 5.2.0.rc2) rspec-rails (~> 3.5, >= 3.5.2) shoryuken (~> 3.2, >= 3.2.2) shoulda-matchers (~> 3.1) diff --git a/app/models/provider.rb b/app/models/provider.rb index 8ee77e1ac..e800ca8b5 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -93,7 +93,7 @@ def region_human_name end def logo_url - "#{ENV['CDN_URL']}/images/members/#{symbol.downcase}.png" + "#{ENV['CDN_URL']}/images/members/#{logo}" if logo.present? end def password_input=(value) diff --git a/config/application.rb b/config/application.rb index 38b31dea6..4a7c9e239 100644 --- a/config/application.rb +++ b/config/application.rb @@ -5,6 +5,7 @@ require "active_model/railtie" require "active_job/railtie" require "active_record/railtie" +require "active_storage/engine" require "action_controller/railtie" require "rails/test_unit/railtie" diff --git a/config/boot.rb b/config/boot.rb index 30f5120df..b9e460cef 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,4 @@ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' # Set up gems listed in the Gemfile. +require 'bootsnap/setup' # Speed up boot time by caching expensive operations. diff --git a/config/environments/production.rb b/config/environments/production.rb index 2c857283d..1c18701cc 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -47,6 +47,8 @@ # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false + config.active_storage.service = :amazon + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true diff --git a/config/environments/stage.rb b/config/environments/stage.rb index 808ffdcd6..997718fc6 100644 --- a/config/environments/stage.rb +++ b/config/environments/stage.rb @@ -51,6 +51,8 @@ # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true + config.active_storage.service = :amazon + # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb index 51639b67a..89d2efab2 100644 --- a/config/initializers/application_controller_renderer.rb +++ b/config/initializers/application_controller_renderer.rb @@ -1,6 +1,8 @@ # Be sure to restart your server when you modify this file. -# ApplicationController.renderer.defaults.merge!( -# http_host: 'example.org', -# https: false -# ) +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/config/initializers/new_framework_defaults_5_2.rb b/config/initializers/new_framework_defaults_5_2.rb new file mode 100644 index 000000000..421e5a2a3 --- /dev/null +++ b/config/initializers/new_framework_defaults_5_2.rb @@ -0,0 +1,35 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 5.2 upgrade. +# +# Once upgraded flip defaults one by one to migrate to the new default. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. + +# Make Active Record use stable #cache_key alongside new #cache_version method. +# This is needed for recyclable cache keys. +# Rails.application.config.active_record.cache_versioning = true + +# Use AES-256-GCM authenticated encryption for encrypted cookies. +# Also, embed cookie expiry in signed or encrypted cookies for increased security. +# +# This option is not backwards compatible with earlier Rails versions. +# It's best enabled when your entire app is migrated and stable on 5.2. +# +# Existing cookies will be converted on read then written with the new scheme. +# Rails.application.config.action_dispatch.use_authenticated_cookie_encryption = true + +# Use AES-256-GCM authenticated encryption as default cipher for encrypting messages +# instead of AES-256-CBC, when use_authenticated_message_encryption is set to true. +# Rails.application.config.active_support.use_authenticated_message_encryption = true + +# Add default protection from forgery to ActionController::Base instead of in +# ApplicationController. +# Rails.application.config.action_controller.default_protect_from_forgery = true + +# Store boolean values are in sqlite3 databases as 1 and 0 instead of 't' and +# 'f' after migrating old data. +# Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true + +# Use SHA-1 instead of MD5 to generate non-sensitive digests, such as the ETag header. +# Rails.application.config.active_support.use_sha1_digests = true diff --git a/config/spring.rb b/config/spring.rb index c9119b40c..9fa7863f9 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,6 +1,6 @@ -%w( +%w[ .ruby-version .rbenv-vars tmp/restart.txt tmp/caching-dev.txt -).each { |path| Spring.watch(path) } +].each { |path| Spring.watch(path) } diff --git a/config/storage.yml b/config/storage.yml new file mode 100644 index 000000000..231dfc7e0 --- /dev/null +++ b/config/storage.yml @@ -0,0 +1,14 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +amazon: + service: S3 + access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %> + secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %> + region: <%= ENV['AWS_REGION'] %> + bucket: <%= ENV['AWS_S3_BUCKET'] %> diff --git a/db/migrate/20180330175050_create_active_storage_tables.active_storage.rb b/db/migrate/20180330175050_create_active_storage_tables.active_storage.rb new file mode 100644 index 000000000..1e36f427e --- /dev/null +++ b/db/migrate/20180330175050_create_active_storage_tables.active_storage.rb @@ -0,0 +1,28 @@ +# This migration comes from active_storage (originally 20170806125915) +class CreateActiveStorageTables < ActiveRecord::Migration[5.2] + def change + add_column :allocator, :logo, :string + + 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 6a406f304..97ebaccbe 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,9 +10,30 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180330040550) do +ActiveRecord::Schema.define(version: 2018_03_30_175050) do - create_table "allocator", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT" do |t| + create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", 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", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", 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 "allocator", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t| t.string "contact_email", null: false t.string "contact_name", limit: 80, null: false t.datetime "created" @@ -35,11 +56,12 @@ t.datetime "deleted_at" t.date "joined" t.string "institution_type", limit: 191 + t.string "logo" t.index ["institution_type"], name: "index_member_institution_type" t.index ["symbol"], name: "symbol", unique: true end - create_table "allocator_prefixes", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT" do |t| + create_table "allocator_prefixes", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t| t.bigint "allocator", null: false t.bigint "prefixes", null: false t.datetime "created_at" @@ -49,7 +71,7 @@ t.index ["prefixes"], name: "FKE7FBD674AF86A1C7" end - create_table "datacentre", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT" do |t| + create_table "datacentre", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t| t.text "comments", limit: 4294967295 t.string "contact_email", null: false t.string "contact_name", limit: 80, null: false @@ -72,10 +94,10 @@ t.index ["allocator"], name: "FK6695D60546EBD781" t.index ["re3data"], name: "index_datacentre_on_re3data" t.index ["symbol"], name: "symbol", unique: true - t.index ["url"], name: "index_datacentre_on_url", length: { url: 100 } + t.index ["url"], name: "index_datacentre_on_url", length: 100 end - create_table "datacentre_prefixes", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT" do |t| + create_table "datacentre_prefixes", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t| t.bigint "datacentre", null: false t.bigint "prefixes", null: false t.datetime "created_at" @@ -87,7 +109,7 @@ t.index ["prefixes"], name: "FK13A1B3BAAF86A1C7" end - create_table "dataset", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT" do |t| + create_table "dataset", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t| t.datetime "created" t.string "doi", null: false t.binary "is_active", limit: 1, null: false @@ -110,10 +132,10 @@ t.index ["doi"], name: "doi", unique: true t.index ["last_landing_page_content_type"], name: "index_dataset_on_last_landing_page_content_type" t.index ["last_landing_page_status"], name: "index_dataset_on_last_landing_page_status" - t.index ["url"], name: "index_dataset_on_url", length: { url: 100 } + t.index ["url"], name: "index_dataset_on_url", length: 100 end - create_table "media", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT" do |t| + create_table "media", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t| t.datetime "created" t.string "media_type", limit: 80 t.datetime "updated" @@ -124,7 +146,7 @@ t.index ["dataset"], name: "FK62F6FE44D3D6B1B" end - create_table "metadata", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT" do |t| + create_table "metadata", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t| t.datetime "created" t.integer "metadata_version" t.integer "version" @@ -136,7 +158,7 @@ t.index ["dataset"], name: "FKE52D7B2F4D3D6B1B" end - create_table "prefix", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT" do |t| + create_table "prefix", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT", force: :cascade do |t| t.datetime "created" t.string "prefix", limit: 80, null: false t.integer "version" diff --git a/docker-compose.yml b/docker-compose.yml index 9438bb7b8..499d49bed 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,6 +12,7 @@ services: - ./db:/home/app/webapp/db - ./lib:/home/app/webapp/lib - ./spec:/home/app/webapp/spec + - ./storage:/home/app/webapp/storage networks: - public memcached: diff --git a/storage/.gitkeep b/storage/.gitkeep new file mode 100644 index 000000000..e69de29bb