diff --git a/Gemfile b/Gemfile index 53aae9ab..4d944ed4 100644 --- a/Gemfile +++ b/Gemfile @@ -15,16 +15,13 @@ gem 'friendly_id', '~> 5.5.0' gem 'nilify_blanks', '~> 1.4' gem 'solid_cable' gem 'solid_queue' +gem 'solid_cache' # frontend gem 'haml-rails', '~> 2.0' gem 'turbo-rails', '~> 2.0' gem 'view_component' -# TO BE REMOVED -gem 'redis' -gem 'hiredis', '~> 0.6.3' - # functionality gem 'stringex', '~> 2.8', require: 'stringex_lite' gem 'http', '~> 5.0' diff --git a/Gemfile.lock b/Gemfile.lock index 4223fada..0b338cf5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -179,7 +179,6 @@ GEM haml (>= 4.0.6) railties (>= 5.1) hashie (5.0.0) - hiredis (0.6.3) http (5.2.0) addressable (~> 2.8) base64 (~> 0.1) @@ -377,10 +376,6 @@ GEM rdoc (6.7.0) psych (>= 4.0.0) redcarpet (3.6.0) - redis (5.3.0) - redis-client (>= 0.22.0) - redis-client (0.22.2) - connection_pool regexp_parser (2.9.2) reline (0.5.11) io-console (~> 0.5) @@ -469,6 +464,10 @@ GEM activejob (>= 7.2) activerecord (>= 7.2) railties (>= 7.2) + solid_cache (1.0.6) + activejob (>= 7.2) + activerecord (>= 7.2) + railties (>= 7.2) solid_queue (1.0.1) activejob (>= 7.1) activerecord (>= 7.1) @@ -559,7 +558,6 @@ DEPENDENCIES flamegraph friendly_id (~> 5.5.0) haml-rails (~> 2.0) - hiredis (~> 0.6.3) http (~> 5.0) ipaddress! kaminari @@ -582,7 +580,6 @@ DEPENDENCIES rails-patterns rails-pg-extras redcarpet - redis rgl rouge rspec-rails @@ -592,6 +589,7 @@ DEPENDENCIES silencer simple_form (~> 5.3) solid_cable + solid_cache solid_queue sqlite3 stackprof diff --git a/Makefile b/Makefile index 64b65e6e..a2641d05 100644 --- a/Makefile +++ b/Makefile @@ -35,8 +35,10 @@ console: .makerc-vars ## Open rails console logs: .makerc-vars ## Tail all logs $(SUDO_COMMAND) docker compose -f docker/$(DEPLOY_ENVIRONMENT)/docker-compose.yml logs -f --tail=100 -clear-redis: .makerc-vars ## Clear rails cache (by flushing redis) - $(SUDO_COMMAND) docker compose -f docker/$(DEPLOY_ENVIRONMENT)/docker-compose.yml exec redis redis-cli flushdb +clear-redis: clear-cache # dummy until migrated + +clear-cache: .makerc-vars ## Clear rails cache + $(SUDO_COMMAND) docker compose -f docker/$(DEPLOY_ENVIRONMENT)/docker-compose.yml exec web bin/rails r 'Rails.cache.clear' import-db: $(SUDO_COMMAND) docker compose -f docker/$(DEPLOY_ENVIRONMENT)/docker-compose.yml up -d postgresql --wait @@ -50,4 +52,4 @@ CURRENT_VERSION: .makerc-vars: @echo "\033[93m[*] Configuration file missing, running configurator\033[0m" @python3 scripts/generate_config.py - @if [ -f ".makerc-vars" ]; then echo "\033[92m[*] Config file created, please rerun the task!\033[0m"; false; else echo "\033[91m[*] Config file was not created, please rerun the task!\033[0m"; false; fi \ No newline at end of file + @if [ -f ".makerc-vars" ]; then echo "\033[92m[*] Config file created, please rerun the task!\033[0m"; false; else echo "\033[91m[*] Config file was not created, please rerun the task!\033[0m"; false; fi diff --git a/README.md b/README.md index 53f6f956..deccaae6 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,6 @@ Providentia is a [Ruby on Rails](https://github.com/rails/rails) based web appli Can be switched to any OpenID Connect provider -- ~~Redis~~[Garnet](https://github.com/microsoft/garnet) for caching and session storage - [PostgreSQL](https://www.postgresql.org/) - [Rails](https://github.com/rails/rails) app - [Caddy](https://github.com/caddyserver/caddy) reverse proxy diff --git a/config/cache.yml b/config/cache.yml new file mode 100644 index 00000000..25358872 --- /dev/null +++ b/config/cache.yml @@ -0,0 +1,17 @@ +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: + database: cache + <<: *default + +test: + <<: *default + +production: + database: cache + <<: *default diff --git a/config/environments/development.rb b/config/environments/development.rb index 0567f0c0..4b9b2deb 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -29,7 +29,7 @@ config.action_controller.perform_caching = false end - config.cache_store = :redis_cache_store, { url: ENV.fetch('REDIS_URL') { 'redis://localhost:6379/1' } } + config.cache_store = :solid_cache_store # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local diff --git a/config/environments/production.rb b/config/environments/production.rb index e3488312..77a2fe5a 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -49,15 +49,7 @@ config.active_support.report_deprecations = false # Replace the default in-process memory cache store with a durable alternative. - # config.cache_store = :mem_cache_store - config.cache_store = :redis_cache_store, { - url: ENV.fetch('REDIS_URL') { 'redis://localhost:6379/0' }, - - connect_timeout: 30, - read_timeout: 0.2, - write_timeout: 0.2, - reconnect_attempts: 1 - } + config.cache_store = :solid_cache_store # Replace the default in-process and non-durable queuing backend for Active Job. config.active_job.queue_adapter = :solid_queue diff --git a/db/cache_schema.rb b/db/cache_schema.rb new file mode 100644 index 00000000..c513a30b --- /dev/null +++ b/db/cache_schema.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +ActiveRecord::Schema[7.2].define(version: 1) do + create_table 'solid_cache_entries', force: :cascade do |t| + t.binary 'key', limit: 1024, null: false + t.binary 'value', limit: 536870912, null: false + t.datetime 'created_at', null: false + t.integer 'key_hash', limit: 8, null: false + t.integer 'byte_size', limit: 4, null: false + t.index ['byte_size'], name: 'index_solid_cache_entries_on_byte_size' + t.index ['key_hash', 'byte_size'], name: 'index_solid_cache_entries_on_key_hash_and_byte_size' + t.index ['key_hash'], name: 'index_solid_cache_entries_on_key_hash', unique: true + end +end diff --git a/docker/dev/docker-compose.yml b/docker/dev/docker-compose.yml index 93b7cac3..b37e1b4f 100644 --- a/docker/dev/docker-compose.yml +++ b/docker/dev/docker-compose.yml @@ -68,23 +68,9 @@ services: - KEYCLOAK_AVAILABILITYCHECK_TIMEOUT=30s - IMPORT_FILES='/config/*' - redis: - image: "redis:alpine" - volumes: - - "redis:/data" - - garnet: - image: "ghcr.io/microsoft/garnet" - ulimits: - memlock: -1 - volumes: - - garnetdata:/data - web: depends_on: - "postgresql" - - "redis" - - "garnet" build: context: ../../ dockerfile: Dockerfile @@ -114,7 +100,6 @@ services: VITE_RUBY_PORT: 80 VITE_RUBY_SKIP_PROXY: true DATABASE_URL: postgres://providentia:secret@postgresql/providentia?pool=5 - REDIS_URL: redis://garnet:6379/0 OIDC_ISSUER: http://keycloak.localhost/realms/Providentia OIDC_CLIENT_ID: Providentia OIDC_CLIENT_SECRET: 00000000-0000-0000-0000-000000000000 @@ -173,7 +158,5 @@ services: volumes: caddy_data: - redis: postgres_providentia: postgres_keycloak: - garnetdata: diff --git a/docker/prod/docker-compose.yml b/docker/prod/docker-compose.yml index 9876b9e0..56f9b3da 100644 --- a/docker/prod/docker-compose.yml +++ b/docker/prod/docker-compose.yml @@ -28,16 +28,9 @@ services: env_file: - db.env - redis: - image: "redis:alpine" - restart: unless-stopped - volumes: - - "redis:/data" - web: depends_on: - "db" - - "redis" build: context: ../../ dockerfile: Dockerfile @@ -90,6 +83,5 @@ services: - IMPORT_FILES='/config/*' volumes: - redis: {} caddy_data: {} providentia_db: {}