diff --git a/.gitignore b/.gitignore index a21a562..644767f 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,5 @@ debshots-workspace.code-workspace !/app/assets/builds/.keep /node_modules + +/config/credentials/development.key diff --git a/Dockerfile b/Dockerfile index 05eac30..0900b9d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ WORKDIR /rails # Install base packages RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y curl libjemalloc2 libvips libpq-dev nodejs && \ + apt-get install --no-install-recommends -y curl libjemalloc2 libvips libpq-dev nodejs telnet && \ rm -rf /var/lib/apt/lists /var/cache/apt/archives # Set production environment diff --git a/Gemfile b/Gemfile index be73b9a..5733f85 100644 --- a/Gemfile +++ b/Gemfile @@ -1,23 +1,23 @@ -source "https://rubygems.org" +source 'https://rubygems.org' # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" -gem "rails", "~> 8.0.2" +gem 'rails', '~> 8.0.2' # The modern asset pipeline for Rails [https://github.com/rails/propshaft] -gem "propshaft" +gem 'propshaft' # Use sqlite3 as the database for Active Record -gem "sqlite3", ">= 2.1" +gem 'sqlite3', '>= 2.1' # Use the Puma web server [https://github.com/puma/puma] -gem "puma", ">= 5.0" +gem 'puma', '>= 5.0' # Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails] -gem "jsbundling-rails" +gem 'jsbundling-rails' # Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] # gem "turbo-rails" # Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] # gem "stimulus-rails" # Bundle and process CSS [https://github.com/rails/cssbundling-rails] -gem "cssbundling-rails" +gem 'cssbundling-rails' # Build JSON APIs with ease [https://github.com/rails/jbuilder] -gem "jbuilder" +gem 'jbuilder' # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] # gem "bcrypt", "~> 3.1.7" @@ -26,9 +26,9 @@ gem "jbuilder" gem 'shrine', '~> 3.0' # Use the database-backed adapters for Rails.cache, Active Job, and Action Cable -gem "solid_cache" -gem "solid_queue" -gem "solid_cable" +gem 'solid_cable' +gem 'solid_cache' +gem 'solid_queue' # To create variants (different sizes) of screenshot images gem 'fastimage' @@ -36,38 +36,38 @@ gem 'image_processing' gem 'mini_magick' # Reduces boot times through caching; required in config/boot.rb -gem "bootsnap", require: false +gem 'bootsnap', require: false # Deploy this application anywhere as a Docker container [https://kamal-deploy.org] -gem "kamal", require: false +gem 'kamal', require: false # Add HTTP asset caching/compression and X-Sendfile acceleration to Puma [https://github.com/basecamp/thruster/] -gem "thruster", require: false +gem 'thruster', require: false # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] # gem "image_processing", "~> 1.2" group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem - gem "debug", platforms: %i[ mri windows ], require: "debug/prelude" + gem 'debug', platforms: %i[mri windows], require: 'debug/prelude' # Static analysis for security vulnerabilities [https://brakemanscanner.org/] - gem "brakeman", require: false + gem 'brakeman', require: false # Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/] - gem "rubocop-rails-omakase", require: false + gem 'rubocop-rails-omakase', require: false end group :development do # Use console on exceptions pages [https://github.com/rails/web-console] # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. - gem "web-console" gem 'listen', '~> 3.5' + gem 'web-console' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring - #gem 'better_errors' - #gem 'binding_of_caller' - #gem 'spring' - #gem 'spring-watcher-listen', '~> 2.0.0' + # gem 'better_errors' + # gem 'binding_of_caller' + # gem 'spring' + # gem 'spring-watcher-listen', '~> 2.0.0' gem 'rails-erd' @@ -102,8 +102,8 @@ end group :test do # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] - gem "capybara" - gem "selenium-webdriver" + gem 'capybara' + gem 'selenium-webdriver' end # TODO… https://github.com/galetahub/simple-captcha @@ -134,7 +134,7 @@ gem 'font-awesome-rails' # gem "recaptcha", require: "recaptcha/rails" -#gem 'sprockets-rails' +# gem 'sprockets-rails' # gem "activemodel-serializers-xml" @@ -159,6 +159,6 @@ gem 'gravtastic' gem 'bzip2-ffi' -#gem "dartsass-rails", "~> 0.5.1" +# gem "dartsass-rails", "~> 0.5.1" gem 'rails-healthcheck' diff --git a/Gemfile.lock b/Gemfile.lock index 95289b0..7b923d8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -124,6 +124,9 @@ GEM responders warden (~> 1.2.3) dotenv (3.1.7) + dotenv-rails (3.1.7) + dotenv (= 3.1.7) + railties (>= 6.1) down (5.4.2) addressable (~> 2.8) drb (2.2.1) @@ -480,7 +483,7 @@ GEM activejob (>= 7.2) activerecord (>= 7.2) railties (>= 7.2) - solid_queue (1.1.3) + solid_queue (1.1.4) activejob (>= 7.1) activerecord (>= 7.1) concurrent-ruby (>= 1.3.1) @@ -572,6 +575,7 @@ DEPENDENCIES cssbundling-rails debug devise + dotenv-rails factory_bot_rails fastimage font-awesome-rails diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..64bb49d Binary files /dev/null and b/bun.lockb differ diff --git a/config/cable.yml b/config/cable.yml index 4aee18b..b9adc5a 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -2,16 +2,16 @@ # and seeing results in the browser, you must do so from the web console (running inside the dev process), # not a terminal started via bin/rails console! Add "console" to any action or any ERB template view # to make the web console appear. -# development: -# adapter: async +development: + adapter: async -# test: -# adapter: test +test: + adapter: test -# production: -# adapter: solid_cable -# connects_to: -# database: -# writing: cable -# polling_interval: 0.1.seconds -# message_retention: 1.day +production: + adapter: solid_cable + connects_to: + database: + writing: cable + polling_interval: 0.1.seconds + message_retention: 1.day diff --git a/config/cache.yml b/config/cache.yml new file mode 100644 index 0000000..19d4908 --- /dev/null +++ b/config/cache.yml @@ -0,0 +1,16 @@ +default: &default + store_options: + # Cap age of oldest cache entry to fulfill retention policies + # max_age: <%= 60.days.to_i %> + max_size: <%= 256.megabytes %> + namespace: <%= Rails.env %> + +development: + <<: *default + +test: + <<: *default + +production: + database: cache + <<: *default diff --git a/config/credentials/development.yml.enc b/config/credentials/development.yml.enc new file mode 100644 index 0000000..0a31a02 --- /dev/null +++ b/config/credentials/development.yml.enc @@ -0,0 +1 @@ +p4iCDmwxjQ5zC6i3QVNCnlW++oxVLD0AKnflI6lsRBQ1bLTcBA3+8EFI9itIiv7WUJYF+0xGz1bqNq8e9Kk+tEq7C1GVgbuS3xEjG2I0Kt1GbTjvl0aeCd7WHR5xWHlCIXmZVhO/OL4SNc876WYpQqwWRwHkPND0QGAmfWOgy2H14V6LVYh1d7fhPdSYBr4b6oPMMQW6fqAjQ8Oq5TVUznRiRLQfFhAYz2DklMAoASjhAWK39U76JWYqu8VCq08+3V/geXYtQfcsvQ1twq08RFcJbZsCG7slOI8fPW5Oq2dCpw==--mvh3V6FOm1I5+pal--y0AKTyuXuwhXl6iMcT29tw== \ No newline at end of file diff --git a/config/database.yml b/config/database.yml index 1305327..3f840e1 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,39 +1,46 @@ -# SQLite. Versions 3.8.0 and up are supported. -# gem install sqlite3 -# -# Ensure the SQLite 3 gem is defined in your Gemfile -# gem 'sqlite3' +default: &default + adapter: postgresql + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + timeout: 5000 + +production: +# Store production database in the storage/ directory, which by default +# is mounted as a persistent Docker volume in config/deploy.yml. + primary: + <<: *default + # database: storage/production.sqlite3 + url: <%= Rails.application.credentials.db.url %> + pool: 10 + cache: + <<: *default + database: storage/production_cache.sqlite3 + migrations_paths: db/cache_migrate + queue: + <<: *default + database: storage/production_queue.sqlite3 + migrations_paths: db/queue_migrate + cable: + <<: *default + database: storage/production_cable.sqlite3 + migrations_paths: db/cable_migrate + development: + <<: *default adapter: postgresql database: debshots_dev username: debshots_dev password: GonwannEn0 host: localhost - pool: 5 - timeout: 5000 +# SQLite. Versions 3.8.0 and up are supported. +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +# # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: - adapter: postgresql - database: debshots_test - username: debshots_test - password: GonwannEn0 - host: localhost - pool: 5 - timeout: 5000 - -# production: -# adapter: postgresql -# database: debshots -# # username: debshots -# # password: GonwannEn0 -# # host: localhost -# pool: 10 -# timeout: 5000 -production: - url: <%= ENV['DATABASE_URL'] %> - adapter: postgresql - pool: 10 - timeout: 5000 + <<: *default + database: storage/test.sqlite3 diff --git a/config/environments/production.rb b/config/environments/production.rb index 0cfc950..9d2857c 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,4 +1,4 @@ -require "active_support/core_ext/integer/time" +require 'active_support/core_ext/integer/time' Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -16,7 +16,7 @@ Rails.application.configure do config.action_controller.perform_caching = true # Cache assets for far-future expiry since they are all digest stamped. - config.public_file_server.headers = { "cache-control" => "public, max-age=#{1.year.to_i}" } + config.public_file_server.headers = { 'cache-control' => "public, max-age=#{1.year.to_i}" } # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.asset_host = "http://assets.example.com" @@ -34,14 +34,14 @@ Rails.application.configure do # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } # Log to STDOUT with the current request id as a default log tag. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] config.logger = ActiveSupport::TaggedLogging.logger(STDOUT) # Change to "debug" to log everything (including potentially personally-identifiable information!) - config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") + config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info') # Prevent health checks from clogging up the logs. - config.silence_healthcheck_path = "/up" + config.silence_healthcheck_path = '/up' # Don't log any deprecations. config.active_support.report_deprecations = false @@ -53,13 +53,12 @@ Rails.application.configure do config.active_job.queue_adapter = :solid_queue config.solid_queue.connects_to = { database: { writing: :queue } } config.action_mailer.smtp_settings = { - # TODO: make configurable through ENV variables - address: 'dokku2.workaround.org', - port: 25, + address: Rails.application.credentials.smtp.server, + port: 25, enable_starttls_auto: false } config.action_mailer.default_url_options = { - host: "screenshots.debian.net", + host: 'screenshots.debian.net', protocol: 'https' } @@ -68,7 +67,7 @@ Rails.application.configure do # config.action_mailer.raise_delivery_errors = false # Set host to be used by links generated in mailer templates. - config.action_mailer.default_url_options = { host: "example.com" } + config.action_mailer.default_url_options = { host: 'example.com' } # Specify outgoing SMTP server. Remember to add smtp/* credentials via rails credentials:edit. # config.action_mailer.smtp_settings = { @@ -89,8 +88,8 @@ Rails.application.configure do config.package_sources = [ { description: 'Debian Unstable (Sid)', type: 'apt', url: 'http://ftp.de.debian.org/debian/dists/sid', - architectures: ['i386' ,'amd64'] - #components: ['main','restricted','universe','multiverse'] + architectures: %w[i386 amd64] + # components: ['main','restricted','universe','multiverse'] } ] @@ -107,7 +106,7 @@ Rails.application.configure do # Only use :id for inspections in production. # Needed (at least) for devise.rb to determine the oauth2 callback URL config.base_url = ENV['DEBSHOTS_BASE_URL'] || 'http://localhost:3000' - config.active_record.attributes_for_inspect = [ :id ] + config.active_record.attributes_for_inspect = [:id] # Enable DNS rebinding protection and other `Host` header attacks. # config.hosts = [ diff --git a/db/schema.rb b/db/schema.rb index 73d2029..3aaa19f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,9 +10,9 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_11_26_173151) do +ActiveRecord::Schema[8.0].define(version: 2023_11_26_173151) do # These are extensions that must be enabled in order to support this database - enable_extension "plpgsql" + enable_extension "pg_catalog.plpgsql" create_table "action_mailbox_inbound_emails", force: :cascade do |t| t.integer "status", default: 0, null: false @@ -87,7 +87,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_11_26_173151) do t.datetime "updated_at", precision: nil t.integer "visits", default: 0 t.index "(((setweight(to_tsvector('english'::regconfig, COALESCE((name)::text, ''::text)), 'A'::\"char\") || setweight(to_tsvector('english'::regconfig, COALESCE((description)::text, ''::text)), 'B'::\"char\")) || setweight(to_tsvector('english'::regconfig, COALESCE(long_description, ''::text)), 'C'::\"char\")))", name: "packages_fts", using: :gin - t.index ["name"], name: "packages_name_key", unique: true + t.unique_constraint ["name"], name: "packages_name_key" end create_table "screenshots", id: :serial, force: :cascade do |t|