diff --git a/Dockerfile b/Dockerfile index 25f4f1a..0d216b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,17 @@ -# -# Stage for builder base -# -FROM ruby:3.1.4-slim-bookworm +# ベースステージ +FROM ruby:3.1.4-slim-bookworm AS base ENV DEBIAN_FRONTEND noninteractive ENV APPROOT="/opt/app" ENV RAILS_LOG_TO_STDOUT="1" -ENV RAILS_ENV="development" RUN apt-get -y update && \ apt-get -y upgrade && \ - apt-get -y install build-essential libpq-dev libpq5 libvips42 curl ffmpeg && \ - apt-get clean + apt-get -y install --no-install-recommends build-essential libpq-dev libpq5 libvips42 curl ffmpeg && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* -RUN curl -L -O https://github.com/yt-dlp/yt-dlp/releases/download/2023.07.06/yt-dlp_linux && \ +RUN curl -L -O https://github.com/yt-dlp/yt-dlp/releases/download/2024.08.06/yt-dlp_linux && \ mv yt-dlp_linux yt-dlp && \ chmod +x yt-dlp && \ mv yt-dlp /usr/local/bin/yt-dlp @@ -23,6 +21,42 @@ WORKDIR ${APPROOT} COPY Gemfile ${APPROOT} COPY Gemfile.lock ${APPROOT} +# テスト用のステージ +FROM base AS test +RUN apt-get update && \ + apt-get install -y wget gnupg --no-install-recommends && \ + wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - && \ + sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' && \ + apt-get update && apt-get install -y google-chrome-stable --no-install-recommends && \ + rm -rf /var/lib/apt/lists/* +ENV RAILS_ENV="test" RUN gem install bundler && bundle install +CMD rails about + +# 開発用のステージ +FROM base AS development +ENV RAILS_ENV="development" +RUN gem install bundler && bundle install +CMD rails about + +# ビルド用のステージ +FROM base AS build +ENV RAILS_ENV="production" +ARG REDIS_URL +RUN gem install bundler && bundle install --without development test +COPY . ${APPROOT} +RUN SECRET_KEY_BASE=$(rails secret) rails assets:precompile + +# 本番用のステージ +FROM ruby:3.1.4-slim-bookworm AS production +ENV APPROOT="/opt/app" +ENV RAILS_ENV="production" +ENV RAILS_LOG_TO_STDOUT="1" +ARG REDIS_URL +WORKDIR ${APPROOT} +COPY --from=build ${APPROOT} ${APPROOT} +COPY --from=build /usr/local/bundle /usr/local/bundle +COPY --from=build /usr/local/bin/yt-dlp /usr/local/bin/yt-dlp +RUN apt-get update && apt-get -y --no-install-recommends install libpq5 ffmpeg libvips42 && apt-get clean && rm -rf /var/lib/apt/lists/* CMD rails about diff --git a/Dockerfile.production b/Dockerfile.production deleted file mode 100644 index 9f4767d..0000000 --- a/Dockerfile.production +++ /dev/null @@ -1,31 +0,0 @@ -# -# Stage for builder base -# -FROM ruby:3.1.4-slim-bookworm - -ENV DEBIAN_FRONTEND noninteractive -ENV APPROOT="/opt/app" -ENV RAILS_LOG_TO_STDOUT="1" -ENV RAILS_ENV="production" -ARG REDIS_URL - -RUN apt-get -y update && \ - apt-get -y upgrade && \ - apt-get -y install build-essential libpq-dev libpq5 libvips42 curl ffmpeg && \ - apt-get clean - -RUN curl -L -O https://github.com/yt-dlp/yt-dlp/releases/download/2023.07.06/yt-dlp_linux && \ - mv yt-dlp_linux yt-dlp && \ - chmod +x yt-dlp && \ - mv yt-dlp /usr/local/bin/yt-dlp - -WORKDIR ${APPROOT} - -COPY Gemfile ${APPROOT} -COPY Gemfile.lock ${APPROOT} - -RUN gem install bundler && bundle install -COPY . ${APPROOT} -RUN SECRET_KEY_BASE=$(rails secret) rails assets:precompile - -CMD rails about diff --git a/Gemfile b/Gemfile index d35bcae..a9f12fb 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby "3.1.4" # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" -gem "rails", "7.0.4.3" +gem "rails", "7.1" # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] gem "sprockets-rails" @@ -13,7 +13,7 @@ gem "sprockets-rails" gem "pg", "~> 1.1" # Use the Puma web server [https://github.com/puma/puma] -gem "puma", "~> 5.0" +gem "puma", "~> 6.0" # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] gem "importmap-rails" @@ -72,6 +72,5 @@ end group :test do # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] gem "capybara" - gem "selenium-webdriver" - gem "webdrivers" + gem "cuprite" end diff --git a/Gemfile.lock b/Gemfile.lock index 01ea7a5..08cb3db 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,115 +1,138 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.0.4.3) - actionpack (= 7.0.4.3) - activesupport (= 7.0.4.3) + actioncable (7.1.0) + actionpack (= 7.1.0) + activesupport (= 7.1.0) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.4.3) - actionpack (= 7.0.4.3) - activejob (= 7.0.4.3) - activerecord (= 7.0.4.3) - activestorage (= 7.0.4.3) - activesupport (= 7.0.4.3) + zeitwerk (~> 2.6) + actionmailbox (7.1.0) + actionpack (= 7.1.0) + activejob (= 7.1.0) + activerecord (= 7.1.0) + activestorage (= 7.1.0) + activesupport (= 7.1.0) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.4.3) - actionpack (= 7.0.4.3) - actionview (= 7.0.4.3) - activejob (= 7.0.4.3) - activesupport (= 7.0.4.3) + actionmailer (7.1.0) + actionpack (= 7.1.0) + actionview (= 7.1.0) + activejob (= 7.1.0) + activesupport (= 7.1.0) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp - rails-dom-testing (~> 2.0) - actionpack (7.0.4.3) - actionview (= 7.0.4.3) - activesupport (= 7.0.4.3) - rack (~> 2.0, >= 2.2.0) + rails-dom-testing (~> 2.2) + actionpack (7.1.0) + actionview (= 7.1.0) + activesupport (= 7.1.0) + nokogiri (>= 1.8.5) + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.4.3) - actionpack (= 7.0.4.3) - activerecord (= 7.0.4.3) - activestorage (= 7.0.4.3) - activesupport (= 7.0.4.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.0) + actionpack (= 7.1.0) + activerecord (= 7.1.0) + activestorage (= 7.1.0) + activesupport (= 7.1.0) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.4.3) - activesupport (= 7.0.4.3) + actionview (7.1.0) + activesupport (= 7.1.0) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.4.3) - activesupport (= 7.0.4.3) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.1.0) + activesupport (= 7.1.0) globalid (>= 0.3.6) - activemodel (7.0.4.3) - activesupport (= 7.0.4.3) - activerecord (7.0.4.3) - activemodel (= 7.0.4.3) - activesupport (= 7.0.4.3) - activestorage (7.0.4.3) - actionpack (= 7.0.4.3) - activejob (= 7.0.4.3) - activerecord (= 7.0.4.3) - activesupport (= 7.0.4.3) + activemodel (7.1.0) + activesupport (= 7.1.0) + activerecord (7.1.0) + activemodel (= 7.1.0) + activesupport (= 7.1.0) + timeout (>= 0.4.0) + activestorage (7.1.0) + actionpack (= 7.1.0) + activejob (= 7.1.0) + activerecord (= 7.1.0) + activesupport (= 7.1.0) marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (7.0.4.3) + activesupport (7.1.0) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) minitest (>= 5.1) + mutex_m tzinfo (~> 2.0) - addressable (2.8.5) - public_suffix (>= 2.0.2, < 6.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) annotate (3.2.0) activerecord (>= 3.2, < 8.0) rake (>= 10.4, < 14.0) + base64 (0.2.0) + bigdecimal (3.1.8) bindex (0.8.1) - bootsnap (1.16.0) + bootsnap (1.18.4) msgpack (~> 1.2) - builder (3.2.4) - capybara (3.39.2) + builder (3.3.0) + capybara (3.40.0) addressable matrix mini_mime (>= 0.1.3) - nokogiri (~> 1.8) + nokogiri (~> 1.11) rack (>= 1.6.0) rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - concurrent-ruby (1.2.2) + concurrent-ruby (1.3.3) + connection_pool (2.4.1) crass (1.0.6) - date (3.3.3) - debug (1.8.0) - irb (>= 1.5.0) - reline (>= 0.3.1) - erubi (1.12.0) - ffi (1.15.5) + cuprite (0.15.1) + capybara (~> 3.0) + ferrum (~> 0.15.0) + date (3.3.4) + debug (1.9.2) + irb (~> 1.10) + reline (>= 0.3.8) + drb (2.2.1) + erubi (1.13.0) + ferrum (0.15) + addressable (~> 2.5) + concurrent-ruby (~> 1.1) + webrick (~> 1.7) + websocket-driver (~> 0.7) + ffi (1.17.0-x86_64-darwin) + ffi (1.17.0-x86_64-linux-gnu) globalid (1.2.1) activesupport (>= 6.1) - i18n (1.14.1) + i18n (1.14.5) concurrent-ruby (~> 1.0) - image_processing (1.12.2) + image_processing (1.13.0) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) - importmap-rails (1.2.1) + importmap-rails (2.0.1) actionpack (>= 6.0.0) + activesupport (>= 6.0.0) railties (>= 6.0.0) - io-console (0.6.0) - irb (1.8.1) - rdoc - reline (>= 0.3.8) - jbuilder (2.11.5) + io-console (0.7.2) + irb (1.14.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + jbuilder (2.12.0) actionview (>= 5.0.0) activesupport (>= 5.0.0) - loofah (2.21.3) + logger (1.6.0) + loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -117,57 +140,63 @@ GEM net-imap net-pop net-smtp - marcel (1.0.2) + marcel (1.0.4) matrix (0.4.2) - method_source (1.0.0) - mini_magick (4.12.0) + mini_magick (4.13.2) mini_mime (1.1.5) - minitest (5.20.0) + minitest (5.24.1) mono_logger (1.1.2) msgpack (1.7.2) multi_json (1.15.0) - mustermann (3.0.0) + mustermann (3.0.2) ruby2_keywords (~> 0.0.1) - net-imap (0.3.7) + mutex_m (0.2.0) + net-imap (0.4.14) date net-protocol net-pop (0.1.2) net-protocol - net-protocol (0.2.1) + net-protocol (0.2.2) timeout - net-smtp (0.4.0) + net-smtp (0.5.0) net-protocol - nio4r (2.5.9) - nokogiri (1.15.4-x86_64-darwin) + nio4r (2.7.3) + nokogiri (1.16.7-x86_64-darwin) racc (~> 1.4) - nokogiri (1.15.4-x86_64-linux) + nokogiri (1.16.7-x86_64-linux) racc (~> 1.4) - pg (1.5.4) - psych (5.1.0) + pg (1.5.7) + psych (5.1.2) stringio - public_suffix (5.0.3) - puma (5.6.7) + public_suffix (6.0.1) + puma (6.4.2) nio4r (~> 2.0) - racc (1.7.1) - rack (2.2.8) - rack-protection (3.1.0) - rack (~> 2.2, >= 2.2.4) + racc (1.8.1) + rack (3.1.7) + rack-protection (4.0.0) + base64 (>= 0.1.0) + rack (>= 3.0.0, < 4) + rack-session (2.0.0) + rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rails (7.0.4.3) - actioncable (= 7.0.4.3) - actionmailbox (= 7.0.4.3) - actionmailer (= 7.0.4.3) - actionpack (= 7.0.4.3) - actiontext (= 7.0.4.3) - actionview (= 7.0.4.3) - activejob (= 7.0.4.3) - activemodel (= 7.0.4.3) - activerecord (= 7.0.4.3) - activestorage (= 7.0.4.3) - activesupport (= 7.0.4.3) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails (7.1.0) + actioncable (= 7.1.0) + actionmailbox (= 7.1.0) + actionmailer (= 7.1.0) + actionpack (= 7.1.0) + actiontext (= 7.1.0) + actionview (= 7.1.0) + activejob (= 7.1.0) + activemodel (= 7.1.0) + activerecord (= 7.1.0) + activestorage (= 7.1.0) + activesupport (= 7.1.0) bundler (>= 1.15.0) - railties (= 7.0.4.3) + railties (= 7.1.0) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -175,55 +204,52 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.0.4.3) - actionpack (= 7.0.4.3) - activesupport (= 7.0.4.3) - method_source + railties (7.1.0) + actionpack (= 7.1.0) + activesupport (= 7.1.0) + irb + rackup (>= 1.0.0) rake (>= 12.2) - thor (~> 1.0) - zeitwerk (~> 2.5) - rake (13.0.6) - rdoc (6.5.0) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rake (13.2.1) + rdoc (6.7.0) psych (>= 4.0.0) redis (4.8.1) redis-namespace (1.11.0) redis (>= 4) - regexp_parser (2.8.1) - reline (0.3.8) + regexp_parser (2.9.2) + reline (0.5.9) io-console (~> 0.5) resque (2.6.0) mono_logger (~> 1.0) multi_json (~> 1.0) redis-namespace (~> 1.6) sinatra (>= 0.9.2) - rexml (3.2.6) - ruby-vips (2.1.4) + ruby-vips (2.2.2) ffi (~> 1.12) + logger ruby2_keywords (0.0.5) - rubyzip (2.3.2) - selenium-webdriver (4.12.0) - rexml (~> 3.2, >= 3.2.5) - rubyzip (>= 1.2.2, < 3.0) - websocket (~> 1.0) - sinatra (3.1.0) + sinatra (4.0.0) mustermann (~> 3.0) - rack (~> 2.2, >= 2.2.4) - rack-protection (= 3.1.0) + rack (>= 3.0.0, < 4) + rack-protection (= 4.0.0) + rack-session (>= 2.0.0, < 3) tilt (~> 2.0) sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) + sprockets-rails (3.5.2) + actionpack (>= 6.1) + activesupport (>= 6.1) sprockets (>= 3.0.0) - stimulus-rails (1.2.2) + stimulus-rails (1.3.3) railties (>= 6.0.0) - stringio (3.0.8) - thor (1.2.2) - tilt (2.3.0) - timeout (0.4.0) - turbo-rails (1.4.0) + stringio (3.1.1) + thor (1.3.1) + tilt (2.4.0) + timeout (0.4.1) + turbo-rails (2.0.6) actionpack (>= 6.0.0) activejob (>= 6.0.0) railties (>= 6.0.0) @@ -234,17 +260,13 @@ GEM activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) - webdrivers (5.2.0) - nokogiri (~> 1.6) - rubyzip (>= 1.3.0) - selenium-webdriver (~> 4.0) - websocket (1.2.10) + webrick (1.8.1) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.11) + zeitwerk (2.6.17) PLATFORMS x86_64-darwin-21 @@ -254,25 +276,24 @@ DEPENDENCIES annotate bootsnap capybara + cuprite debug image_processing (~> 1.2) importmap-rails jbuilder pg (~> 1.1) - puma (~> 5.0) - rails (= 7.0.4.3) + puma (~> 6.0) + rails (= 7.1) redis (~> 4.0) resque - selenium-webdriver sprockets-rails stimulus-rails turbo-rails tzinfo-data web-console - webdrivers RUBY VERSION ruby 3.1.4p223 BUNDLED WITH - 2.3.21 + 2.5.17 diff --git a/README.md b/README.md index bbd7ab3..2df384e 100644 --- a/README.md +++ b/README.md @@ -60,56 +60,50 @@ https://demo.ytdlor.or6.jp/ ## デバッグ -**必要なソフトウェアのインストール** +**起動** ```sh -brew install youtube-dl -brew install redis +./docker_compose up --build ``` -**gemsのインストール** +ブラウザから http://localhost:3000/ にアクセスする -```sh -cd ytdlor -bundle -``` -**Redisの起動** +**テストの実行** + +- すべてのテストを実行する ```sh -brew services start redis +./docker_compose --profile test run --rm --build test rails test ``` -**ワーカーの起動** +- test:system のみ実行する ```sh -./workers.sh +./docker_compose --profile test run --rm --build test rails test:system ``` -**Railsプロセスの起動** +- テストのログを見る ```sh -rails s +tail -f log/test.log ``` -起動したら http://localhost:3000/ でアクセスできる -**テストの実行** +**gemのアップデート** -```sh -rails test:system -``` - -テストのログを見るには、 +- すべての gem のバージョンをアップデートする ```sh -tail -f log/test.log +./docker_compose run --rm web bundle update +./docker_compose build ``` -**docker composeの動作確認** +- capybara gem のバージョンをアップデートする ```sh -RAILS_MASTER_KEY="$(cat config/credentials/production.key)" docker compose up +./docker_compose run --rm web bundle update capybara +./docker_compose build ``` **solargraphのセットアップ** diff --git a/app/controllers/archives_controller.rb b/app/controllers/archives_controller.rb index 2c7c8fd..f29361b 100644 --- a/app/controllers/archives_controller.rb +++ b/app/controllers/archives_controller.rb @@ -1,5 +1,6 @@ class ArchivesController < ApplicationController - before_action :set_archive, only: %i[ show edit update destroy ] + #before_action :set_archive, only: %i[ show edit update destroy ] + before_action :set_archive, only: %i[ show edit ] # GET /archives or /archives.json def index diff --git a/bin/setup b/bin/setup index ec47b79..3cd5a9d 100755 --- a/bin/setup +++ b/bin/setup @@ -5,7 +5,7 @@ require "fileutils" APP_ROOT = File.expand_path("..", __dir__) def system!(*args) - system(*args) || abort("\n== Command #{args} failed ==") + system(*args, exception: true) end FileUtils.chdir APP_ROOT do diff --git a/config/application.rb b/config/application.rb index d25d2c7..75133cd 100644 --- a/config/application.rb +++ b/config/application.rb @@ -11,6 +11,11 @@ class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 7.0 + # Please, add to the `ignore` list any other `lib` subdirectories that do + # not contain `.rb` files, or that should not be reloaded or eager loaded. + # Common ones are `templates`, `generators`, or `middleware`, for example. + config.autoload_lib(ignore: %w(assets tasks)) + # Configuration for the application, engines, and railties goes here. # # These settings can be overridden in specific environments using the files diff --git a/config/environments/development.rb b/config/environments/development.rb index 50334b8..c33db6b 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -6,7 +6,7 @@ # In the development environment your application's code is reloaded any time # it changes. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. - config.cache_classes = false + config.enable_reloading = true # Do not eager load code on boot. config.eager_load = false @@ -56,6 +56,9 @@ # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true + # Highlight code that enqueued background job in logs. + config.active_job.verbose_enqueue_logs = true + # Suppress logger output for asset requests. config.assets.quiet = true @@ -68,6 +71,9 @@ # Uncomment if you wish to allow Action Cable access from any origin. # config.action_cable.disable_request_forgery_protection = true + # Raise error when a before_action's only/except options reference missing actions + config.action_controller.raise_on_missing_callback_actions = true + # Use Resque as ActiveJob Adapter config.active_job.queue_adapter = :resque diff --git a/config/environments/production.rb b/config/environments/production.rb index ee95ab4..7e083a2 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -4,7 +4,7 @@ # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. - config.cache_classes = true + config.enable_reloading = false # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers @@ -16,13 +16,12 @@ config.consider_all_requests_local = false config.action_controller.perform_caching = true - # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] - # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # Ensures that a master key has been made available in ENV["RAILS_MASTER_KEY"], config/master.key, or an environment + # key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files). # config.require_master_key = true - # Disable serving static files from the `/public` folder by default since - # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? + # Enable static file serving from the `/public` folder (turn off if using NGINX/Apache for it). + config.public_file_server.enabled = true # Compress CSS using a preprocessor. # config.assets.css_compressor = :sass @@ -45,22 +44,33 @@ # config.action_cable.url = "wss://example.com/cable" # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] + # Assume all access to the app is happening through a SSL-terminating reverse proxy. + # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies. + # config.assume_ssl = true + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - # config.force_ssl = true + #config.force_ssl = true + config.force_ssl = false - # Include generic and useful information about system operation, but avoid logging too much - # information to avoid inadvertent exposure of personally identifiable information (PII). - config.log_level = :info + # Log to STDOUT by default + config.logger = ActiveSupport::Logger.new(STDOUT) + .tap { |logger| logger.formatter = ::Logger::Formatter.new } + .then { |logger| ActiveSupport::TaggedLogging.new(logger) } # Prepend all log lines with the following tags. config.log_tags = [ :request_id ] + # Info include generic and useful information about system operation, but avoids logging too much + # information to avoid inadvertent exposure of personally identifiable information (PII). If you + # want to log everything, set the level to "debug". + config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") + # Use a different cache store in production. # config.cache_store = :mem_cache_store # Use a real queuing backend for Active Job (and separate queues per environment). config.active_job.queue_adapter = :resque - #config.active_job.queue_name_prefix = "ytdlor_production" + # config.active_job.queue_name_prefix = "ytdlor_production" config.action_mailer.perform_caching = false @@ -75,23 +85,14 @@ # Don't log any deprecations. config.active_support.report_deprecations = false - # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = ::Logger::Formatter.new - - # Use a different logger for distributed setups. - # require "syslog/logger" - # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") - - if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new(STDOUT) - logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) - end - # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false - # ActiveStorageのURLの期限切れを伸ばす - # - 動画の再生が5分で途切れる問題のワークアラウンド - config.active_storage.service_urls_expire_in = 24.hour + # Enable DNS rebinding protection and other `Host` header attacks. + # config.hosts = [ + # "example.com", # Allow requests from example.com + # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com` + # ] + # Skip DNS rebinding protection for the default health check endpoint. + # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } end diff --git a/config/environments/test.rb b/config/environments/test.rb index 6ea4d1e..0dda9f9 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -8,12 +8,13 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - # Turn false under Spring and add config.action_view.cache_template_loading = true. - config.cache_classes = true + # While tests run files are not watched, reloading is not necessary. + config.enable_reloading = false - # Eager loading loads your whole application. When running a single test locally, - # this probably isn't necessary. It's a good idea to do in a continuous integration - # system, or in some way before deploying your code. + # Eager loading loads your entire application. When running a single test locally, + # this is usually not necessary, and can slow down your test suite. However, it's + # recommended that you enable it in continuous integration systems to ensure eager + # loading is working properly before deploying your code. config.eager_load = ENV["CI"].present? # Configure public file server for tests with Cache-Control for performance. @@ -28,7 +29,7 @@ config.cache_store = :null_store # Raise exceptions instead of rendering exception templates. - config.action_dispatch.show_exceptions = false + config.action_dispatch.show_exceptions = :rescuable # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false @@ -57,4 +58,7 @@ # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true + + # Raise error when a before_action's only/except options reference missing actions + config.action_controller.raise_on_missing_callback_actions = true end diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index 54f47cf..b3076b3 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -16,9 +16,9 @@ # # policy.report_uri "/csp-violation-report-endpoint" # end # -# # Generate session nonces for permitted importmap and inline scripts +# # Generate session nonces for permitted importmap, inline scripts, and inline styles. # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } -# config.content_security_policy_nonce_directives = %w(script-src) +# config.content_security_policy_nonce_directives = %w(script-src style-src) # # # Report violations without enforcing the policy. # # config.content_security_policy_report_only = true diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index adc6568..41551f6 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,8 +1,8 @@ # Be sure to restart your server when you modify this file. -# Configure parameters to be filtered from the log file. Use this to limit dissemination of -# sensitive information. See the ActiveSupport::ParameterFilter documentation for supported -# notations and behaviors. +# Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. +# Use this to limit dissemination of sensitive information. +# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. Rails.application.config.filter_parameters += [ :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn ] diff --git a/config/initializers/new_framework_defaults_7_0.rb b/config/initializers/new_framework_defaults_7_0.rb new file mode 100644 index 0000000..0f8d420 --- /dev/null +++ b/config/initializers/new_framework_defaults_7_0.rb @@ -0,0 +1,148 @@ +# Be sure to restart your server when you modify this file. +# +# This file eases your Rails 7.0 framework defaults upgrade. +# +# Uncomment each configuration one by one to switch to the new default. +# Once your application is ready to run with all new defaults, you can remove +# this file and set the `config.load_defaults` to `7.0`. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. +# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html + +# `button_to` view helper will render `