The server cannot process the request due to a client error. Please check the request and try again. If you’re the application owner check the logs for more information.
+diff --git a/.dockerignore b/.dockerignore index c45413d6..ba082fac 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,23 +1,40 @@ -.DS_Store -.bin -.git -.gitignore -.bundleignore -.bundle -.byebug_history -.rspec -tmp -log -test -config/credentials.yml.enc -config/master.key -public/packs -public/packs-test -node_modules -yarn-error.log - -# Ignore CI service files. -/.github +# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files. + +# Ignore git directory. +/.git/ +/.gitignore + +# Ignore bundler config. +/.bundle + +# Ignore all environment files. +/.env* + +# Ignore all default key files. +/config/master.key +/config/credentials/*.key + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore pidfiles, but keep the directory. +/tmp/pids/* +!/tmp/pids/.keep + +# Ignore storage (uploaded files in development and any SQLite databases). +/storage/* +!/storage/.keep +/tmp/storage/* +!/tmp/storage/.keep + +# Ignore assets. +/node_modules/ +/app/assets/builds/* +!/app/assets/builds/.keep +/public/assets # Ignore development files /.devcontainer @@ -25,3 +42,5 @@ yarn-error.log # Ignore Docker-related files /.dockerignore /Dockerfile* + +.rspec diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..8dc43234 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +# See https://git-scm.com/docs/gitattributes for more about git attribute files. + +# Mark the database schema as having been generated. +db/schema.rb linguist-generated + +# Mark any vendored files as having been vendored. +vendor/* linguist-vendored +config/credentials/*.yml.enc diff=rails_credentials +config/credentials.yml.enc diff=rails_credentials diff --git a/.gitignore b/.gitignore index 65c38ef0..a2dcaa6e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,54 +1,48 @@ # See https://help.github.com/articles/ignoring-files for more about ignoring files. # -# If you find yourself ignoring temporary files generated by your text editor -# or operating system, you probably want to add a global ignore instead: -# git config --global core.excludesfile '~/.gitignore_global' +# Temporary files generated by your text editor or operating system +# belong in git's global ignore instead: +# `$XDG_CONFIG_HOME/git/ignore` or `~/.config/git/ignore` # Ignore bundler config. /.bundle -# Ignore the default SQLite database. -/db/*.sqlite3 -/db/*.sqlite3-journal -/db/*.sqlite3-* +# Ignore all environment files. +/.env* # Ignore all logfiles and tempfiles. /log/* /tmp/* +!/log/.keep +!/tmp/.keep -# Ignore uploaded files in development. +# Ignore pidfiles, but keep the directory. +/tmp/pids/* +!/tmp/pids/ +!/tmp/pids/.keep + +# Ignore storage (uploaded files in development and any SQLite databases). /storage/* +!/storage/.keep +/tmp/storage/* +!/tmp/storage/ +!/tmp/storage/.keep /public/assets -.byebug_history # Ignore master key for decrypting credentials and more. /config/master.key -/config/credentials.yml.enc - -/public/packs -/public/packs-test -/node_modules -.pnp.* -.yarn/* - -spec/examples.txt - -.env -.envrc +config/credentials.yml.enc +## custom docker/**/*.env -/app/assets/builds/* -!/app/assets/builds/.keep - CURRENT_VERSION +.makerc-vars # Vite Ruby +.yarn /public/vite* node_modules # Vite uses dotenv and suggests to ignore local-only env files. See # https://vitejs.dev/guide/env-and-mode.html#env-files *.local - -.env -.makerc-vars diff --git a/Dockerfile b/Dockerfile index 63c1a50f..1e3f37b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,115 +1,132 @@ -# jemalloc builder -FROM ruby:3.3.6-alpine AS builder_jemalloc +# syntax=docker/dockerfile:1 +# check=error=true -RUN apk add build-base -RUN wget -O - https://github.com/jemalloc/jemalloc/releases/download/5.3.0/jemalloc-5.3.0.tar.bz2 | tar -xj && \ - cd jemalloc-5.3.0 && \ - ./configure && \ - make && \ - make install - -# ruby builder image -FROM ruby:3.3.6-alpine AS builder - -RUN apk add --no-cache --update build-base \ - linux-headers \ - git \ - postgresql-dev \ - tzdata \ - less \ - sudo -RUN gem install bundler --no-document - -COPY Gemfile Gemfile.lock /srv/ -WORKDIR /srv -# RUN bundle config --global frozen 1 && bundle install --no-binstubs --without development test --jobs $(nproc) --retry 3 -RUN bundle config --global frozen 1 && bundle install --no-binstubs --jobs $(nproc) --retry 3 - -FROM ruby:3.3.6-alpine AS development +ARG RUBY_VERSION=3.3.6 +# BASE IMAGE +FROM ruby:$RUBY_VERSION-alpine AS base ARG CONTAINER_USER_ID ARG CONTAINER_GROUP_ID ARG CONTAINER_USER_NAME +ENV CONTAINER_USER_NAME=${CONTAINER_USER_NAME:-app} \ + CONTAINER_USER_ID=${CONTAINER_USER_ID:-1000} \ + CONTAINER_GROUP_ID=${CONTAINER_GROUP_ID:-1000} \ + APP_PATH="/srv/app" -ENV APP_PATH /srv/app -ENV RAILS_LOG_TO_STDOUT true -ENV CONTAINER_USER_NAME=${CONTAINER_USER_NAME:-app} -ENV CONTAINER_USER_ID=${CONTAINER_USER_ID:-1000} -ENV CONTAINER_GROUP_ID=${CONTAINER_GROUP_ID:-1000} +RUN mkdir -p $APP_PATH +WORKDIR $APP_PATH +RUN apk add --no-cache --update bash -RUN apk add --no-cache --update build-base \ - linux-headers \ - git \ - curl \ - postgresql-client \ +# DEV BUILDER IMAGE +FROM base AS builder_development +COPY Gemfile Gemfile.lock ./ +RUN apk add --no-cache --update \ + build-base \ postgresql-dev \ - nodejs-current \ + git +RUN bundle install --jobs $(nproc) --retry 3 && \ + rm -rf ~/.bundle/ /usr/local/bundle/ruby/*/cache /usr/local/bundle/ruby/*/bundler/gems/*/.git && \ + bundle exec bootsnap precompile --gemfile + +## DEVELOPMENT IMAGE +FROM base AS development +ENV RAILS_ENV="development" +RUN apk add --no-cache --update \ + build-base \ + git \ tzdata \ + nodejs-current \ + sqlite \ + postgresql-client \ less \ graphviz \ ttf-dejavu -RUN addgroup -S -g ${CONTAINER_GROUP_ID} $CONTAINER_USER_NAME && adduser -S -u ${CONTAINER_USER_ID} -g $CONTAINER_USER_NAME -h /home/$CONTAINER_USER_NAME -s /bin/bash $CONTAINER_USER_NAME - -# jemalloc -COPY --from=builder_jemalloc /usr/local/lib/libjemalloc.so.2 /usr/local/lib/ -ENV LD_PRELOAD=/usr/local/lib/libjemalloc.so.2 +RUN corepack enable +RUN addgroup -S -g ${CONTAINER_GROUP_ID} $CONTAINER_USER_NAME && \ + adduser -S -u ${CONTAINER_USER_ID} -g $CONTAINER_USER_NAME -h /home/$CONTAINER_USER_NAME -s /bin/bash $CONTAINER_USER_NAME # gems -COPY --from=builder --chown=${CONTAINER_USER_ID}:${CONTAINER_GROUP_ID} /usr/local/bundle/ /usr/local/bundle/ +COPY --from=builder_development --chown=${CONTAINER_USER_ID}:${CONTAINER_GROUP_ID} /usr/local/bundle /usr/local/bundle -RUN corepack enable - -RUN mkdir $APP_PATH WORKDIR $APP_PATH USER $CONTAINER_USER_NAME -CMD ["rails", "server", "-b", "0.0.0.0"] +# Entrypoint prepares the database and the rest of environment +ENTRYPOINT ["/srv/app/docker/dev/docker-entrypoint.sh"] +CMD ["./bin/rails", "server", "-b", "0.0.0.0"] -# real image -FROM ruby:3.3.6-alpine AS production -ARG CONTAINER_USER_ID -ARG CONTAINER_GROUP_ID -ARG CONTAINER_USER_NAME -ENV CONTAINER_USER_NAME=${CONTAINER_USER_NAME:-app} -ENV CONTAINER_USER_ID=${CONTAINER_USER_ID:-1000} -ENV CONTAINER_GROUP_ID=${CONTAINER_GROUP_ID:-1000} -ENV APP_PATH /srv/app -ENV RAILS_ENV production -ENV NODE_ENV production -ENV RAILS_LOG_TO_STDOUT true -ENV RAILS_SERVE_STATIC_FILES true -ENV RUBY_GC_HEAP_INIT_SLOTS 2000000 -ENV RUBY_HEAP_FREE_MIN 20000 -ENV RUBY_GC_MALLOC_LIMIT 100000000 + + + + + + + + +## JEMALLOC IMAGE +FROM base AS builder_jemalloc +RUN apk add --no-cache --update build-base +RUN wget -O - https://github.com/jemalloc/jemalloc/releases/download/5.3.0/jemalloc-5.3.0.tar.bz2 | tar -xj && \ + cd jemalloc-5.3.0 && \ + ./configure && \ + make && \ + make install + +# BUILDER IMAGE +FROM base AS builder_prod +ENV RAILS_ENV=production \ + NODE_ENV=production \ + BUNDLE_FROZEN="1" \ + BUNDLE_WITHOUT="development" RUN apk add --no-cache --update \ - postgresql-client \ + build-base \ + bash \ + git \ + tzdata \ postgresql-dev \ nodejs-current \ - tzdata \ less - -COPY --from=builder_jemalloc /usr/local/lib/libjemalloc.so.2 /usr/local/lib/ -ENV LD_PRELOAD=/usr/local/lib/libjemalloc.so.2 - RUN corepack enable -RUN addgroup -S -g ${CONTAINER_GROUP_ID} $CONTAINER_USER_NAME && adduser -S -u ${CONTAINER_USER_ID} -g $CONTAINER_USER_NAME -h /home/$CONTAINER_USER_NAME -s /bin/bash $CONTAINER_USER_NAME - -COPY --from=builder /usr/local/bundle/ /usr/local/bundle/ +COPY Gemfile Gemfile.lock ./ +RUN bundle install --no-binstubs --jobs $(nproc) --retry 3 && \ + rm -rf ~/.bundle/ /usr/local/bundle/ruby/*/cache /usr/local/bundle/ruby/*/bundler/gems/*/.git && \ + bundle exec bootsnap precompile --gemfile + +COPY . . +RUN bundle exec bootsnap precompile app/ lib/ +RUN SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile && \ + rm -r node_modules .yarn + +## PRODUCTION IMAGE +FROM base AS production +ENV RAILS_ENV=production \ + NODE_ENV=production \ + BUNDLE_WITHOUT="development" \ + RAILS_SERVE_STATIC_FILES=true \ + RUBY_GC_HEAP_INIT_SLOTS=2000000 \ + RUBY_HEAP_FREE_MIN=20000 \ + RUBY_GC_MALLOC_LIMIT=100000000 + +COPY --from=builder_prod /usr/local/bundle /usr/local/bundle +COPY --from=builder_prod $APP_PATH $APP_PATH +COPY --from=builder_jemalloc /usr/local/lib/libjemalloc.so.2 /usr/local/lib/ -RUN mkdir -p $APP_PATH -WORKDIR $APP_PATH -COPY --chown=$CONTAINER_USER_NAME:$CONTAINER_USER_NAME . $APP_PATH -ADD ./docker/prod/docker-entrypoint.sh $APP_PATH +RUN apk add --no-cache --update \ + libpq \ + tzdata -RUN chown $CONTAINER_USER_NAME:$CONTAINER_USER_NAME $APP_PATH +RUN addgroup -S -g ${CONTAINER_GROUP_ID} $CONTAINER_USER_NAME && \ + adduser -S -u ${CONTAINER_USER_ID} -g $CONTAINER_USER_NAME -h /home/$CONTAINER_USER_NAME -s /bin/bash $CONTAINER_USER_NAME && \ + chown $CONTAINER_USER_NAME:$CONTAINER_USER_NAME db log storage tmp USER $CONTAINER_USER_NAME -RUN yarn --immutable -RUN DATABASE_URL=postgresql://db SECRET_KEY_BASE=`bin/rails secret` bundle exec rails assets:precompile -CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"] \ No newline at end of file +# Entrypoint prepares the database. +ENTRYPOINT ["/srv/app/docker/prod/docker-entrypoint.sh"] +EXPOSE 3000 +CMD ["./bin/rails", "server", "-b", "0.0.0.0"] \ No newline at end of file diff --git a/Gemfile b/Gemfile index 62ddc2f0..85d89108 100644 --- a/Gemfile +++ b/Gemfile @@ -4,31 +4,31 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } # core -gem 'bootsnap', '>= 1.4.2', require: false -gem 'haml-rails', '~> 2.0' -gem 'rgl' +gem 'rails', '~> 8.0.0' gem 'pg' +gem 'sqlite3' +gem 'bootsnap', '>= 1.4.2', require: false gem 'puma' -gem 'nilify_blanks', '~> 1.4' -gem 'rails', '~> 7.2.1' gem 'oj', '~> 3.10' -gem 'pry-rails', '~> 0.3.9' gem 'rails-patterns' gem 'friendly_id', '~> 5.5.0' -gem 'view_component' -gem 'jwt' -gem 'http', '~> 5.0' -gem 'turbo-rails', '~> 2.0' -gem 'liquid', '~> 5.5' -gem 'redis' -gem 'hiredis', '~> 0.6.3' -gem 'mail', '~> 2.8' -gem 'nokogiri', '~> 1.16' -gem 'stringex', '~> 2.8', require: 'stringex_lite' +gem 'nilify_blanks', '~> 1.4' gem 'data_migrate' +gem 'solid_cable' +gem 'solid_queue' +gem 'solid_cache' + +# frontend +gem 'haml-rails', '~> 2.0' +gem 'turbo-rails', '~> 2.0' +gem 'view_component' # functionality -gem 'acts-as-taggable-on', '~> 11.0' +gem 'stringex', '~> 2.8', require: 'stringex_lite' +gem 'http', '~> 5.0' +gem 'liquid', '~> 5.5' +gem 'rgl' +gem 'acts-as-taggable-on', '~> 12.0' gem 'ipaddress', github: 'ipaddress-gem/ipaddress' gem 'simple_form', '~> 5.3' gem 'ancestry' @@ -81,4 +81,5 @@ group :development do gem 'silencer' gem 'awesome_print', '~> 1.9' + gem 'pry-rails', '~> 0.3.9' end diff --git a/Gemfile.lock b/Gemfile.lock index 9b1bce82..c80f1174 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/ipaddress-gem/ipaddress.git - revision: fb310dff8889c39f1caa457ccf354ec34fdb2d68 + revision: 50a3d73bb1dbeec24a8dd957e3bb7cf7dd207960 specs: ipaddress (0.8.3) @@ -9,66 +9,65 @@ GEM specs: action_policy (0.7.1) ruby-next-core (>= 1.0) - actioncable (7.2.2) - actionpack (= 7.2.2) - activesupport (= 7.2.2) + actioncable (8.0.0) + actionpack (= 8.0.0) + activesupport (= 8.0.0) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.2.2) - actionpack (= 7.2.2) - activejob (= 7.2.2) - activerecord (= 7.2.2) - activestorage (= 7.2.2) - activesupport (= 7.2.2) + actionmailbox (8.0.0) + actionpack (= 8.0.0) + activejob (= 8.0.0) + activerecord (= 8.0.0) + activestorage (= 8.0.0) + activesupport (= 8.0.0) mail (>= 2.8.0) - actionmailer (7.2.2) - actionpack (= 7.2.2) - actionview (= 7.2.2) - activejob (= 7.2.2) - activesupport (= 7.2.2) + actionmailer (8.0.0) + actionpack (= 8.0.0) + actionview (= 8.0.0) + activejob (= 8.0.0) + activesupport (= 8.0.0) mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.2.2) - actionview (= 7.2.2) - activesupport (= 7.2.2) + actionpack (8.0.0) + actionview (= 8.0.0) + activesupport (= 8.0.0) nokogiri (>= 1.8.5) - racc - rack (>= 2.2.4, < 3.2) + rack (>= 2.2.4) rack-session (>= 1.0.1) rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) useragent (~> 0.16) - actiontext (7.2.2) - actionpack (= 7.2.2) - activerecord (= 7.2.2) - activestorage (= 7.2.2) - activesupport (= 7.2.2) + actiontext (8.0.0) + actionpack (= 8.0.0) + activerecord (= 8.0.0) + activestorage (= 8.0.0) + activesupport (= 8.0.0) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.2.2) - activesupport (= 7.2.2) + actionview (8.0.0) + activesupport (= 8.0.0) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (7.2.2) - activesupport (= 7.2.2) + activejob (8.0.0) + activesupport (= 8.0.0) globalid (>= 0.3.6) - activemodel (7.2.2) - activesupport (= 7.2.2) - activerecord (7.2.2) - activemodel (= 7.2.2) - activesupport (= 7.2.2) + activemodel (8.0.0) + activesupport (= 8.0.0) + activerecord (8.0.0) + activemodel (= 8.0.0) + activesupport (= 8.0.0) timeout (>= 0.4.0) - activestorage (7.2.2) - actionpack (= 7.2.2) - activejob (= 7.2.2) - activerecord (= 7.2.2) - activesupport (= 7.2.2) + activestorage (8.0.0) + actionpack (= 8.0.0) + activejob (= 8.0.0) + activerecord (= 8.0.0) + activesupport (= 8.0.0) marcel (~> 1.0) - activesupport (7.2.2) + activesupport (8.0.0) base64 benchmark (>= 0.3) bigdecimal @@ -80,8 +79,9 @@ GEM minitest (>= 5.1) securerandom (>= 0.3) tzinfo (~> 2.0, >= 2.0.5) - acts-as-taggable-on (11.0.0) - activerecord (>= 7.0, < 8.0) + uri (>= 0.13.1) + acts-as-taggable-on (12.0.0) + activerecord (>= 7.1, < 8.1) zeitwerk (>= 2.4, < 3.0) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) @@ -97,7 +97,7 @@ GEM thread_safe (~> 0.3, >= 0.3.1) base64 (0.2.0) bcrypt (3.1.20) - benchmark (0.3.0) + benchmark (0.4.0) bigdecimal (3.1.8) bindata (2.5.0) bindex (0.8.1) @@ -106,7 +106,7 @@ GEM brakeman (6.2.2) racc builder (3.3.0) - bullet (7.2.0) + bullet (8.0.0) activesupport (>= 3.0.0) uniform_notifier (~> 1.11) bundler-audit (0.9.2) @@ -119,14 +119,14 @@ GEM concurrent-ruby (1.3.4) connection_pool (2.4.1) crass (1.0.6) - data_migrate (11.1.0) + data_migrate (11.2.0) activerecord (>= 6.1) railties (>= 6.1) database_cleaner-active_record (2.2.0) activerecord (>= 5.a) database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) - date (3.3.4) + date (3.4.0) descendants_tracker (0.0.4) thread_safe (~> 0.3, >= 0.3.1) devise (4.9.4) @@ -142,6 +142,8 @@ GEM email_validator (2.2.4) activemodel erubi (1.13.0) + et-orbi (1.2.11) + tzinfo factory_bot (6.5.0) activesupport (>= 5.0.0) factory_bot_rails (6.4.4) @@ -149,14 +151,14 @@ GEM railties (>= 5.0.0) faker (3.5.1) i18n (>= 1.8.11, < 2) - faraday (2.12.0) - faraday-net_http (>= 2.0, < 3.4) + faraday (2.12.1) + faraday-net_http (>= 2.0, < 3.5) json logger faraday-follow_redirects (0.3.0) faraday (>= 1, < 3) - faraday-net_http (3.3.0) - net-http + faraday-net_http (3.4.0) + net-http (>= 0.5.0) ffi (1.17.0-x86_64-linux-gnu) ffi (1.17.0-x86_64-linux-musl) ffi-compiler (1.3.2) @@ -165,6 +167,9 @@ GEM flamegraph (0.9.5) friendly_id (5.5.1) activerecord (>= 4.0.0) + fugit (1.11.1) + et-orbi (~> 1, >= 1.2.11) + raabro (~> 1.4) globalid (1.2.1) activesupport (>= 6.1) haml (6.3.0) @@ -177,7 +182,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) @@ -194,7 +198,7 @@ GEM irb (1.14.1) rdoc (>= 4.0.0) reline (>= 0.4.2) - json (2.7.5) + json (2.8.2) json-jwt (1.16.7) activesupport (>= 4.2) aes_key_wrap @@ -202,8 +206,6 @@ GEM bindata faraday (~> 2.0) faraday-follow_redirects - jwt (2.9.3) - base64 kaminari (1.2.2) activesupport (>= 4.1.0) kaminari-actionview (= 1.2.2) @@ -238,11 +240,11 @@ GEM method_source (1.1.0) mini_mime (1.1.5) minitest (5.25.1) - msgpack (1.7.3) + msgpack (1.7.5) naturally (2.2.1) - net-http (0.4.1) + net-http (0.5.0) uri - net-imap (0.5.0) + net-imap (0.5.1) date net-protocol net-pop (0.1.2) @@ -257,7 +259,7 @@ GEM nio4r (2.7.4) nokogiri (1.16.7-x86_64-linux) racc (~> 1.4) - oj (3.16.6) + oj (3.16.7) bigdecimal (>= 3.0) ostruct (>= 0.2) omniauth (2.1.2) @@ -284,13 +286,13 @@ GEM validate_url webfinger (~> 2.0) orm_adapter (0.5.0) - ostruct (0.6.0) + ostruct (0.6.1) pairing_heap (3.1.0) - paper_trail (15.2.0) + paper_trail (16.0.0) activerecord (>= 6.1) request_store (~> 1.4) parallel (1.26.3) - parser (3.3.5.0) + parser (3.3.6.0) ast (~> 2.4.1) racc pg (1.5.9) @@ -304,11 +306,12 @@ GEM method_source (~> 1.0) pry-rails (0.3.11) pry (>= 0.13.0) - psych (5.1.2) + psych (5.2.0) stringio public_suffix (6.0.1) puma (6.4.3) nio4r (~> 2.0) + raabro (1.4.0) racc (1.8.1) rack (3.1.8) rack-mini-profiler (3.3.1) @@ -329,23 +332,22 @@ GEM rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rackup (2.1.0) + rackup (2.2.1) rack (>= 3) - webrick (~> 1.8) - rails (7.2.2) - actioncable (= 7.2.2) - actionmailbox (= 7.2.2) - actionmailer (= 7.2.2) - actionpack (= 7.2.2) - actiontext (= 7.2.2) - actionview (= 7.2.2) - activejob (= 7.2.2) - activemodel (= 7.2.2) - activerecord (= 7.2.2) - activestorage (= 7.2.2) - activesupport (= 7.2.2) + rails (8.0.0) + actioncable (= 8.0.0) + actionmailbox (= 8.0.0) + actionmailer (= 8.0.0) + actionpack (= 8.0.0) + actiontext (= 8.0.0) + actionview (= 8.0.0) + activejob (= 8.0.0) + activemodel (= 8.0.0) + activerecord (= 8.0.0) + activestorage (= 8.0.0) + activesupport (= 8.0.0) bundler (>= 1.15.0) - railties (= 7.2.2) + railties (= 8.0.0) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -361,9 +363,9 @@ GEM rails-pg-extras (5.4.1) rails ruby-pg-extras (= 5.4.1) - railties (7.2.2) - actionpack (= 7.2.2) - activesupport (= 7.2.2) + railties (8.0.0) + actionpack (= 8.0.0) + activesupport (= 8.0.0) irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) @@ -377,12 +379,8 @@ 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.10) + reline (0.5.11) io-console (~> 0.5) request_store (1.7.0) rack (>= 1.4) @@ -394,7 +392,7 @@ GEM pairing_heap (>= 0.3, < 4.0) rexml (~> 3.2, >= 3.2.4) stream (~> 0.5.3) - rouge (4.4.0) + rouge (4.5.1) rspec-core (3.13.2) rspec-support (~> 3.13.0) rspec-expectations (3.13.3) @@ -403,7 +401,7 @@ GEM rspec-mocks (3.13.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) - rspec-rails (7.0.1) + rspec-rails (7.1.0) actionpack (>= 7.0) activesupport (>= 7.0) railties (>= 7.0) @@ -412,7 +410,7 @@ GEM rspec-mocks (~> 3.13) rspec-support (~> 3.13) rspec-support (3.13.1) - rubocop (1.67.0) + rubocop (1.68.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -422,7 +420,7 @@ GEM rubocop-ast (>= 1.32.2, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.33.0) + rubocop-ast (1.36.1) parser (>= 3.3.1.0) rubocop-md (1.2.4) rubocop (>= 1.45) @@ -431,7 +429,7 @@ GEM rubocop-ast (>= 1.31.1, < 2.0) rubocop-packaging (0.5.2) rubocop (>= 1.33, < 2.0) - rubocop-performance (1.22.1) + rubocop-performance (1.23.0) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) rubocop-rails (2.27.0) @@ -453,7 +451,7 @@ GEM terminal-table ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) - securerandom (0.3.1) + securerandom (0.3.2) sentry-rails (5.21.0) railties (>= 5.0) sentry-ruby (~> 5.21.0) @@ -464,10 +462,28 @@ GEM simple_form (5.3.1) actionpack (>= 5.2) activemodel (>= 5.2) + solid_cable (3.0.2) + actioncable (>= 7.2) + 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) + concurrent-ruby (>= 1.3.1) + fugit (~> 1.11.0) + railties (>= 7.1) + thor (~> 1.3.1) + sqlite3 (2.2.0-x86_64-linux-gnu) + sqlite3 (2.2.0-x86_64-linux-musl) stackprof (0.2.26) stream (0.5.5) stringex (2.8.6) - stringio (3.1.1) + stringio (3.1.2) swd (2.0.3) activesupport (>= 3) attr_required (>= 0.0.5) @@ -479,7 +495,7 @@ GEM thor (1.3.2) thread_safe (0.3.6) tilt (2.4.0) - timeout (0.4.1) + timeout (0.4.2) turbo-rails (2.0.11) actionpack (>= 6.0.0) railties (>= 6.0.0) @@ -487,12 +503,12 @@ GEM concurrent-ruby (~> 1.0) unicode-display_width (2.6.0) uniform_notifier (1.16.0) - uri (0.13.1) + uri (1.0.2) useragent (0.16.10) validate_url (1.0.15) activemodel (>= 3.0.0) public_suffix - view_component (3.19.0) + view_component (3.20.0) activesupport (>= 5.2.0, < 8.1) concurrent-ruby (~> 1.0) method_source (~> 1.0) @@ -500,7 +516,7 @@ GEM axiom-types (~> 0.1) coercible (~> 1.0) descendants_tracker (~> 0.0, >= 0.0.3) - vite_rails (3.0.18) + vite_rails (3.0.19) railties (>= 5.1, < 9) vite_ruby (~> 3.0, >= 3.2.2) vite_ruby (3.9.0) @@ -519,7 +535,6 @@ GEM activesupport faraday (~> 2.0) faraday-follow_redirects - webrick (1.8.2) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -531,7 +546,7 @@ PLATFORMS DEPENDENCIES action_policy - acts-as-taggable-on (~> 11.0) + acts-as-taggable-on (~> 12.0) ancestry awesome_print (~> 1.9) bootsnap (>= 1.4.2) @@ -547,18 +562,14 @@ DEPENDENCIES flamegraph friendly_id (~> 5.5.0) haml-rails (~> 2.0) - hiredis (~> 0.6.3) http (~> 5.0) ipaddress! - jwt kaminari liquid (~> 5.5) listen - mail (~> 2.8) memory_profiler naturally (~> 2.2) nilify_blanks (~> 1.4) - nokogiri (~> 1.16) oj (~> 3.10) omniauth (~> 2.0) omniauth-rails_csrf_protection @@ -569,11 +580,10 @@ DEPENDENCIES pry-rails (~> 0.3.9) puma rack-mini-profiler - rails (~> 7.2.1) + rails (~> 8.0.0) rails-patterns rails-pg-extras redcarpet - redis rgl rouge rspec-rails @@ -582,6 +592,10 @@ DEPENDENCIES sentry-ruby silencer simple_form (~> 5.3) + solid_cable + solid_cache + solid_queue + sqlite3 stackprof stringex (~> 2.8) turbo-rails (~> 2.0) @@ -590,4 +604,4 @@ DEPENDENCIES web-console (>= 3.3.0) BUNDLED WITH - 2.5.19 + 2.5.23 diff --git a/Makefile b/Makefile index 64b65e6e..67897302 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,7 @@ config: .makerc-vars ## Regenerate config file clean: .makerc-vars ## Stop containers, remove volumes and built images $(SUDO_COMMAND) docker compose -f docker/$(DEPLOY_ENVIRONMENT)/docker-compose.yml down --rmi local -v --remove-orphans + rm storage/*.sqlite3 build: .makerc-vars $(if $(findstring $(DEPLOY_ENVIRONMENT),prod),CURRENT_VERSION) ## Build app images $(SUDO_COMMAND) docker compose -f docker/$(DEPLOY_ENVIRONMENT)/docker-compose.yml build @@ -22,7 +23,7 @@ stop: .makerc-vars ## Stop containers $(SUDO_COMMAND) docker compose -f docker/$(DEPLOY_ENVIRONMENT)/docker-compose.yml down start: .makerc-vars ## Start daemonized containers - $(SUDO_COMMAND) docker compose -f docker/$(DEPLOY_ENVIRONMENT)/docker-compose.yml up -d + $(SUDO_COMMAND) docker compose -f docker/$(DEPLOY_ENVIRONMENT)/docker-compose.yml up -d --wait restart: stop start ## Restart the containers @@ -35,8 +36,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 +53,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/app/models/virtual_machine.rb b/app/models/virtual_machine.rb index fd525b53..4c678f06 100644 --- a/app/models/virtual_machine.rb +++ b/app/models/virtual_machine.rb @@ -6,6 +6,7 @@ class VirtualMachine < ApplicationRecord include SpecCacheUpdateBeforeDestroy has_paper_trail + attribute :visibility, :integer # rails bug during migrations enum :visibility, { public: 1, actor_only: 2 }, prefix: :visibility belongs_to :exercise diff --git a/bin/dev b/bin/dev index 2daf7764..5f91c205 100755 --- a/bin/dev +++ b/bin/dev @@ -1,9 +1,2 @@ -#!/usr/bin/env bash - -if ! command -v foreman &> /dev/null -then - echo "Installing foreman..." - gem install foreman -fi - -foreman start -f Procfile.dev +#!/usr/bin/env ruby +exec "./bin/rails", "server", *ARGV diff --git a/bin/jobs b/bin/jobs new file mode 100755 index 00000000..dcf59f30 --- /dev/null +++ b/bin/jobs @@ -0,0 +1,6 @@ +#!/usr/bin/env ruby + +require_relative "../config/environment" +require "solid_queue/cli" + +SolidQueue::Cli.start(ARGV) diff --git a/bin/setup b/bin/setup index 9e713d57..8ed176b2 100755 --- a/bin/setup +++ b/bin/setup @@ -2,7 +2,6 @@ require "fileutils" APP_ROOT = File.expand_path("..", __dir__) -APP_NAME = "providentia" def system!(*args) system(*args, exception: true) @@ -14,7 +13,6 @@ FileUtils.chdir APP_ROOT do # Add necessary setup steps to this file. puts "== Installing dependencies ==" - system! "gem install bundler --conservative" system("bundle check") || system!("bundle install") # puts "\n== Copying sample files ==" @@ -28,10 +26,9 @@ FileUtils.chdir APP_ROOT do puts "\n== Removing old logs and tempfiles ==" system! "bin/rails log:clear tmp:clear" - puts "\n== Restarting application server ==" - system! "bin/rails restart" - - # puts "\n== Configuring puma-dev ==" - # system "ln -nfs #{APP_ROOT} ~/.puma-dev/#{APP_NAME}" - # system "curl -Is https://#{APP_NAME}.test/up | head -n 1" + unless ARGV.include?("--skip-server") + puts "\n== Starting development server ==" + STDOUT.flush # flush the output before exec(2) so that it displays + exec "bin/dev" + end end diff --git a/bin/thrust b/bin/thrust new file mode 100755 index 00000000..36bde2d8 --- /dev/null +++ b/bin/thrust @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("thruster", "thrust") diff --git a/config/application.rb b/config/application.rb index f71c91de..c7bae3d5 100644 --- a/config/application.rb +++ b/config/application.rb @@ -11,7 +11,7 @@ module Providentia class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 7.1 + config.load_defaults 8.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. diff --git a/config/cable.yml b/config/cable.yml index 76121572..b981d129 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -1,12 +1,18 @@ development: - adapter: redis - url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> - channel_prefix: providentia_development + adapter: solid_cable + connects_to: + database: + writing: cable + polling_interval: 0.1.seconds + message_retention: 1.day test: adapter: test production: - adapter: redis - url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> - channel_prefix: providentia_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 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/database.yml b/config/database.yml index 66123aed..f8c5c0b7 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,2 +1,48 @@ +default_pg: &default_pg + adapter: postgresql + encoding: unicode + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + +default_sqlite: &default_sqlite + adapter: sqlite3 + pool: 5 + timeout: 5000 + +development: + primary: + <<: *default_pg + url: <%= ENV["DATABASE_URL"] %> + cache: + <<: *default_sqlite + database: storage/development_cache.sqlite3 + migrations_paths: db/cache_migrate + queue: + <<: *default_sqlite + database: storage/development_queue.sqlite3 + migrations_paths: db/queue_migrate + cable: + <<: *default_sqlite + database: storage/development_cable.sqlite3 + migrations_paths: db/cable_migrate + +# only specify one for test test: - url: "postgres://providentia:secret@postgresql/providentia_test?pool=5" + primary: + url: "postgres://providentia:secret@postgresql/providentia_test?pool=5" + +production: + primary: + <<: *default_pg + url: <%= ENV["DATABASE_URL"] %> + cache: + <<: *default_sqlite + database: storage/production_cache.sqlite3 + migrations_paths: db/cache_migrate + queue: + <<: *default_sqlite + database: storage/production_queue.sqlite3 + migrations_paths: db/queue_migrate + cable: + <<: *default_sqlite + database: storage/production_cable.sqlite3 + migrations_paths: db/cable_migrate diff --git a/config/environments/development.rb b/config/environments/development.rb index 22c011c5..4b9b2deb 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -6,9 +6,7 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - # 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. + # Make code changes take effect immediately without server restart. config.enable_reloading = true # Do not eager load code on boot. @@ -20,47 +18,43 @@ # Enable server timing. config.server_timing = true - # Enable/disable caching. By default caching is disabled. - # Run rails dev:cache to toggle caching. + # Enable/disable Action Controller caching. By default Action Controller caching is disabled. + # Run rails dev:cache to toggle Action Controller caching. if Rails.root.join('tmp/caching-dev.txt').exist? config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true - config.cache_store = :redis_cache_store, { url: ENV.fetch('REDIS_URL') { 'redis://localhost:6379/1' } } - config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{2.days.to_i}" } + config.public_file_server.headers = { 'cache-control' => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false - - config.cache_store = :null_store end + 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 # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false - # Disable caching for Action Mailer templates even if Action Controller - # caching is enabled. + # Make template changes take effect immediately. config.action_mailer.perform_caching = false + # Set localhost to be used by links generated in mailer templates. config.action_mailer.default_url_options = { host: 'providentia.localhost', port: 3000 } # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log - # Raise exceptions for disallowed deprecations. - config.active_support.disallowed_deprecation = :raise - - # Tell Active Support which deprecation messages to disallow. - config.active_support.disallowed_deprecation_warnings = [] - # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true + # Append comments with runtime information tags to SQL queries in logs. + config.active_record.query_log_tags_enabled = true + # Highlight code that enqueued background job in logs. config.active_job.verbose_enqueue_logs = true diff --git a/config/environments/production.rb b/config/environments/production.rb index bf53ccbd..77a2fe5a 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -8,40 +8,25 @@ # Code is not reloaded between requests. 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 - # and those relying on copy on write to perform better. - # Rake tasks automatically ignore this option for performance. + # Eager load code on boot for better performance and memory savings (ignored by Rake tasks). config.eager_load = true - # Full error reports are disabled and caching is turned on. + # Full error reports are disabled. config.consider_all_requests_local = false - config.action_controller.perform_caching = true - # 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 + # Turn on fragment caching in view templates. + config.action_controller.perform_caching = true - # Disable serving static files from `public/`, relying on NGINX/Apache to do so instead. - # config.public_file_server.enabled = false + # 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}" } # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.asset_host = "http://assets.example.com" - # Specifies the header that your server uses for sending files. - # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache - # 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 - # Mount Action Cable outside main process or domain. - # config.action_cable.mount_path = nil - # 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. @@ -50,56 +35,59 @@ # Skip http-to-https redirect for the default health check endpoint. # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } - # 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. + # Log to STDOUT with the current request id as a default log tag. config.log_tags = [ :request_id ] + config.logger = ActiveSupport::TaggedLogging.logger(STDOUT) - # "info" includes 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". + # Change to "debug" to log everything (including potentially personally-identifiable information!) config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info') - # Use a different cache store in production. - config.cache_store = :redis_cache_store, { - url: ENV.fetch('REDIS_URL') { 'redis://localhost:6379/0' }, + # Prevent health checks from clogging up the logs. + config.silence_healthcheck_path = '/up' + + # Don't log any deprecations. + config.active_support.report_deprecations = false - connect_timeout: 30, - read_timeout: 0.2, - write_timeout: 0.2, - reconnect_attempts: 1 - } + # Replace the default in-process memory cache store with a durable alternative. + config.cache_store = :solid_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 = "providentia_production" + # Replace the default in-process and non-durable queuing backend for Active Job. + config.active_job.queue_adapter = :solid_queue + config.solid_queue.connects_to = { database: { writing: :queue } } - # Disable caching for Action Mailer templates even if Action Controller - # caching is enabled. - config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. # 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' } + + # Specify outgoing SMTP server. Remember to add smtp/* credentials via rails credentials:edit. + # config.action_mailer.smtp_settings = { + # user_name: Rails.application.credentials.dig(:smtp, :user_name), + # password: Rails.application.credentials.dig(:smtp, :password), + # address: "smtp.example.com", + # port: 587, + # authentication: :plain + # } + # 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 - # Don't log any deprecations. - config.active_support.report_deprecations = false - # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false + # Only use :id for inspections in production. + config.active_record.attributes_for_inspect = [ :id ] + # 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" } } diff --git a/config/environments/test.rb b/config/environments/test.rb index d2d8a471..37fc1f7b 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'active_support/core_ext/integer/time' - # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped @@ -19,12 +17,11 @@ # 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. - config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{1.hour.to_i}" } + # Configure public file server for tests with cache-control for performance. + config.public_file_server.headers = { 'cache-control' => 'public, max-age=3600' } - # Show full error reports and disable caching. + # Show full error reports. config.consider_all_requests_local = true - config.action_controller.perform_caching = false config.cache_store = :null_store # Render exception templates for rescuable exceptions and raise for other exceptions. @@ -36,28 +33,17 @@ # Store uploaded files on the local file system in a temporary directory. config.active_storage.service = :test - # Disable caching for Action Mailer templates even if Action Controller - # caching is enabled. - config.action_mailer.perform_caching = false - # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - # Unlike controllers, the mailer instance doesn't have any context about the - # incoming request so you'll need to provide the :host parameter yourself. - config.action_mailer.default_url_options = { host: 'www.example.com' } + # Set host to be used by links generated in mailer templates. + config.action_mailer.default_url_options = { host: 'example.com' } # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - # Raise exceptions for disallowed deprecations. - config.active_support.disallowed_deprecation = :raise - - # Tell Active Support which deprecation messages to disallow. - config.active_support.disallowed_deprecation_warnings = [] - # Raises error for missing translations. # config.i18n.raise_on_missing_translations = true diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index e88b020f..497ac132 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -6,5 +6,5 @@ # Use this to limit dissemination of sensitive information. # See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. Rails.application.config.filter_parameters += [ - :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn + :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn, :cvv, :cvc ] diff --git a/config/puma.rb b/config/puma.rb index a0cb7a81..d3983379 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -3,13 +3,17 @@ # This configuration file will be evaluated by Puma. The top-level methods that # are invoked here are part of Puma's configuration DSL. For more information # about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. - +# # Puma starts a configurable number of processes (workers) and each process # serves each request in a thread from an internal thread pool. # +# You can control the number of workers using ENV["WEB_CONCURRENCY"]. You +# should only set this value when you want to run 2 or more workers. The +# default is already 1. +# # The ideal number of threads per worker depends both on how much time the # application spends waiting for IO operations and on how much you wish to -# to prioritize throughput over latency. +# prioritize throughput over latency. # # As a rule of thumb, increasing the number of threads will increase how much # traffic a given process can handle (throughput), but due to CRuby's @@ -31,6 +35,9 @@ # Allow puma to be restarted by `bin/rails restart` command. plugin :tmp_restart +# Run the Solid Queue supervisor inside of Puma for single-server deployments +plugin :solid_queue if ENV['SOLID_QUEUE_IN_PUMA'] + # Specify the PID file. Defaults to tmp/pids/server.pid in development. # In other environments, only set the PID file if requested. pidfile ENV['PIDFILE'] if ENV['PIDFILE'] diff --git a/config/queue.yml b/config/queue.yml new file mode 100644 index 00000000..9eace59c --- /dev/null +++ b/config/queue.yml @@ -0,0 +1,18 @@ +default: &default + dispatchers: + - polling_interval: 1 + batch_size: 500 + workers: + - queues: "*" + threads: 3 + processes: <%= ENV.fetch("JOB_CONCURRENCY", 1) %> + polling_interval: 0.1 + +development: + <<: *default + +test: + <<: *default + +production: + <<: *default diff --git a/config/recurring.yml b/config/recurring.yml new file mode 100644 index 00000000..d045b191 --- /dev/null +++ b/config/recurring.yml @@ -0,0 +1,10 @@ +# production: +# periodic_cleanup: +# class: CleanSoftDeletedRecordsJob +# queue: background +# args: [ 1000, { batch_size: 500 } ] +# schedule: every hour +# periodic_command: +# command: "SoftDeletedRecord.due.delete_all" +# priority: 2 +# schedule: at 5am every day diff --git a/db/cable_schema.rb b/db/cable_schema.rb new file mode 100644 index 00000000..f8d4cc62 --- /dev/null +++ b/db/cable_schema.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[8.0].define(version: 1) do + create_table 'solid_cable_messages', force: :cascade do |t| + t.binary 'channel', limit: 1024, null: false + t.binary 'payload', limit: 536870912, null: false + t.datetime 'created_at', null: false + t.integer 'channel_hash', limit: 8, null: false + t.index ['channel'], name: 'index_solid_cable_messages_on_channel' + t.index ['channel_hash'], name: 'index_solid_cable_messages_on_channel_hash' + t.index ['created_at'], name: 'index_solid_cable_messages_on_created_at' + end +end diff --git a/db/cache_schema.rb b/db/cache_schema.rb new file mode 100644 index 00000000..fc4322ec --- /dev/null +++ b/db/cache_schema.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[8.0].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/db/queue_schema.rb b/db/queue_schema.rb new file mode 100644 index 00000000..ef165500 --- /dev/null +++ b/db/queue_schema.rb @@ -0,0 +1,143 @@ +# frozen_string_literal: true + +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[8.0].define(version: 1) do + create_table 'solid_queue_blocked_executions', force: :cascade do |t| + t.bigint 'job_id', null: false + t.string 'queue_name', null: false + t.integer 'priority', default: 0, null: false + t.string 'concurrency_key', null: false + t.datetime 'expires_at', null: false + t.datetime 'created_at', null: false + t.index ['concurrency_key', 'priority', 'job_id'], name: 'index_solid_queue_blocked_executions_for_release' + t.index ['expires_at', 'concurrency_key'], name: 'index_solid_queue_blocked_executions_for_maintenance' + t.index ['job_id'], name: 'index_solid_queue_blocked_executions_on_job_id', unique: true + end + + create_table 'solid_queue_claimed_executions', force: :cascade do |t| + t.bigint 'job_id', null: false + t.bigint 'process_id' + t.datetime 'created_at', null: false + t.index ['job_id'], name: 'index_solid_queue_claimed_executions_on_job_id', unique: true + t.index ['process_id', 'job_id'], name: 'index_solid_queue_claimed_executions_on_process_id_and_job_id' + end + + create_table 'solid_queue_failed_executions', force: :cascade do |t| + t.bigint 'job_id', null: false + t.text 'error' + t.datetime 'created_at', null: false + t.index ['job_id'], name: 'index_solid_queue_failed_executions_on_job_id', unique: true + end + + create_table 'solid_queue_jobs', force: :cascade do |t| + t.string 'queue_name', null: false + t.string 'class_name', null: false + t.text 'arguments' + t.integer 'priority', default: 0, null: false + t.string 'active_job_id' + t.datetime 'scheduled_at' + t.datetime 'finished_at' + t.string 'concurrency_key' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['active_job_id'], name: 'index_solid_queue_jobs_on_active_job_id' + t.index ['class_name'], name: 'index_solid_queue_jobs_on_class_name' + t.index ['finished_at'], name: 'index_solid_queue_jobs_on_finished_at' + t.index ['queue_name', 'finished_at'], name: 'index_solid_queue_jobs_for_filtering' + t.index ['scheduled_at', 'finished_at'], name: 'index_solid_queue_jobs_for_alerting' + end + + create_table 'solid_queue_pauses', force: :cascade do |t| + t.string 'queue_name', null: false + t.datetime 'created_at', null: false + t.index ['queue_name'], name: 'index_solid_queue_pauses_on_queue_name', unique: true + end + + create_table 'solid_queue_processes', force: :cascade do |t| + t.string 'kind', null: false + t.datetime 'last_heartbeat_at', null: false + t.bigint 'supervisor_id' + t.integer 'pid', null: false + t.string 'hostname' + t.text 'metadata' + t.datetime 'created_at', null: false + t.string 'name', null: false + t.index ['last_heartbeat_at'], name: 'index_solid_queue_processes_on_last_heartbeat_at' + t.index ['name', 'supervisor_id'], name: 'index_solid_queue_processes_on_name_and_supervisor_id', unique: true + t.index ['supervisor_id'], name: 'index_solid_queue_processes_on_supervisor_id' + end + + create_table 'solid_queue_ready_executions', force: :cascade do |t| + t.bigint 'job_id', null: false + t.string 'queue_name', null: false + t.integer 'priority', default: 0, null: false + t.datetime 'created_at', null: false + t.index ['job_id'], name: 'index_solid_queue_ready_executions_on_job_id', unique: true + t.index ['priority', 'job_id'], name: 'index_solid_queue_poll_all' + t.index ['queue_name', 'priority', 'job_id'], name: 'index_solid_queue_poll_by_queue' + end + + create_table 'solid_queue_recurring_executions', force: :cascade do |t| + t.bigint 'job_id', null: false + t.string 'task_key', null: false + t.datetime 'run_at', null: false + t.datetime 'created_at', null: false + t.index ['job_id'], name: 'index_solid_queue_recurring_executions_on_job_id', unique: true + t.index ['task_key', 'run_at'], name: 'index_solid_queue_recurring_executions_on_task_key_and_run_at', unique: true + end + + create_table 'solid_queue_recurring_tasks', force: :cascade do |t| + t.string 'key', null: false + t.string 'schedule', null: false + t.string 'command', limit: 2048 + t.string 'class_name' + t.text 'arguments' + t.string 'queue_name' + t.integer 'priority', default: 0 + t.boolean 'static', default: true, null: false + t.text 'description' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['key'], name: 'index_solid_queue_recurring_tasks_on_key', unique: true + t.index ['static'], name: 'index_solid_queue_recurring_tasks_on_static' + end + + create_table 'solid_queue_scheduled_executions', force: :cascade do |t| + t.bigint 'job_id', null: false + t.string 'queue_name', null: false + t.integer 'priority', default: 0, null: false + t.datetime 'scheduled_at', null: false + t.datetime 'created_at', null: false + t.index ['job_id'], name: 'index_solid_queue_scheduled_executions_on_job_id', unique: true + t.index ['scheduled_at', 'priority', 'job_id'], name: 'index_solid_queue_dispatch_all' + end + + create_table 'solid_queue_semaphores', force: :cascade do |t| + t.string 'key', null: false + t.integer 'value', default: 1, null: false + t.datetime 'expires_at', null: false + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['expires_at'], name: 'index_solid_queue_semaphores_on_expires_at' + t.index ['key', 'value'], name: 'index_solid_queue_semaphores_on_key_and_value' + t.index ['key'], name: 'index_solid_queue_semaphores_on_key', unique: true + end + + add_foreign_key 'solid_queue_blocked_executions', 'solid_queue_jobs', column: 'job_id', on_delete: :cascade + add_foreign_key 'solid_queue_claimed_executions', 'solid_queue_jobs', column: 'job_id', on_delete: :cascade + add_foreign_key 'solid_queue_failed_executions', 'solid_queue_jobs', column: 'job_id', on_delete: :cascade + add_foreign_key 'solid_queue_ready_executions', 'solid_queue_jobs', column: 'job_id', on_delete: :cascade + add_foreign_key 'solid_queue_recurring_executions', 'solid_queue_jobs', column: 'job_id', on_delete: :cascade + add_foreign_key 'solid_queue_scheduled_executions', 'solid_queue_jobs', column: 'job_id', on_delete: :cascade +end diff --git a/db/schema.rb b/db/schema.rb index 16a3b72d..bcb58a84 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,7 +12,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_10_31_091614) do # These are extensions that must be enabled in order to support this database - enable_extension "plpgsql" + enable_extension "pg_catalog.plpgsql" create_table "actor_number_configs", force: :cascade do |t| t.bigint "actor_id", null: false diff --git a/docker/dev/docker-compose.yml b/docker/dev/docker-compose.yml index 93b7cac3..118c3eec 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 @@ -97,10 +83,8 @@ services: volumes: - /etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt - ../../:/srv/app - entrypoint: ["/srv/app/docker/dev/docker-entrypoint.sh"] - command: ["rails", "server", "-b", "0.0.0.0"] healthcheck: - test: "curl -f localhost:3000/healthz" + test: "wget -q 127.0.0.1:3000/healthz -O /dev/null" interval: 5s timeout: 5s retries: 20 @@ -114,7 +98,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 +156,5 @@ services: volumes: caddy_data: - redis: postgres_providentia: postgres_keycloak: - garnetdata: diff --git a/docker/dev/docker-entrypoint.sh b/docker/dev/docker-entrypoint.sh index 61328172..4ef82b38 100755 --- a/docker/dev/docker-entrypoint.sh +++ b/docker/dev/docker-entrypoint.sh @@ -1,21 +1,20 @@ -#!/bin/sh +#!/bin/bash set -ex ln -sf ../../docker/dev/post-commit .git/hooks/post-commit chmod +x .git/hooks/post-commit +git describe --tags >CURRENT_VERSION + if [ -f tmp/pids/server.pid ]; then rm tmp/pids/server.pid fi -if [ ! -f config/credentials.yml.enc ]; then - EDITOR=true bundle exec rails credentials:edit +# If running the rails server then create or migrate existing database +if [ "${@:1:1}" == "./bin/rails" ] && [ "${@:2:1}" == "server" ]; then + ./bin/rails db:prepare + ./bin/rails db:seed + ./bin/rails data:migrate fi -git describe --tags >CURRENT_VERSION -touch tmp/caching-dev.txt -bundle exec rake db:prepare:with_data -bundle exec rake db:seed -yarn - -exec "$@" +exec "${@}" diff --git a/docker/prod/docker-compose.yml b/docker/prod/docker-compose.yml index 9876b9e0..e944baad 100644 --- a/docker/prod/docker-compose.yml +++ b/docker/prod/docker-compose.yml @@ -1,7 +1,35 @@ -version: "3.7" - +--- name: providentia services: + web: + depends_on: + - "db" + build: + context: ../../ + dockerfile: Dockerfile + target: production + restart: unless-stopped + volumes: + - /etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt + environment: + # persistence config + - DATABASE_URL=postgres://providentia:secret@db/providentia?pool=5 + - REDIS_URL=redis://redis:6379/0 + + # OpenID connect config to local keycloak, which uses http + - OIDC_ISSUER=http://keycloak.localhost/realms/Providentia + - OIDC_CLIENT_ID=Providentia + - OIDC_CLIENT_SECRET=00000000-0000-0000-0000-000000000000 + - OIDC_RESOURCE_PREFIX=Providentia_ + - OIDC_ENABLE_HTTP=true # example only! + + # use real FQDN here + - BASE_URI=https://providentia.localhost + labels: + caddy: "providentia.localhost" + caddy.tls: internal + caddy.reverse_proxy: "{{upstreams 3000}}" + caddy: image: lucaslorentz/caddy-docker-proxy:ci-alpine ports: @@ -25,39 +53,13 @@ services: volumes: - ./initdb_keycloak.sql:/docker-entrypoint-initdb.d/001-initdb.sql - "providentia_db:/var/lib/postgresql/data" - env_file: - - db.env - - redis: - image: "redis:alpine" - restart: unless-stopped - volumes: - - "redis:/data" - - web: - depends_on: - - "db" - - "redis" - build: - context: ../../ - dockerfile: Dockerfile - target: production - entrypoint: ["/srv/app/docker-entrypoint.sh"] - command: ["puma", "-C", "config/puma.production.rb"] - restart: unless-stopped - volumes: - - /etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt - expose: - - 3000 - env_file: - - web.env - labels: - caddy: "providentia.localhost" - caddy.tls: internal - caddy.reverse_proxy: "{{upstreams 3000}}" + environment: + - POSTGRES_USER=providentia + - POSTGRES_PASSWORD=secret + - POSTGRES_DB=providentia keycloak: - image: bitnami/keycloak:23.0.4 + image: bitnami/keycloak:25.0.4 depends_on: - db environment: @@ -76,7 +78,7 @@ services: caddy.reverse_proxy: "{{upstreams 8080}}" keycloak_config: - image: adorsys/keycloak-config-cli:latest-23.0.1 + image: adorsys/keycloak-config-cli:latest-25 depends_on: - keycloak volumes: @@ -90,6 +92,5 @@ services: - IMPORT_FILES='/config/*' volumes: - redis: {} caddy_data: {} providentia_db: {} diff --git a/docker/prod/docker-entrypoint.sh b/docker/prod/docker-entrypoint.sh index ef265547..a120c6cb 100755 --- a/docker/prod/docker-entrypoint.sh +++ b/docker/prod/docker-entrypoint.sh @@ -1,15 +1,17 @@ -#!/bin/sh +#!/bin/bash set -ex -if [ -f tmp/pids/server.pid ]; then - rm tmp/pids/server.pid +# Enable jemalloc for reduced memory usage and latency. +if [ -z "${LD_PRELOAD+x}" ]; then + LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit) + export LD_PRELOAD fi -if [ ! -f config/credentials.yml.enc ]; then - EDITOR=true bundle exec rails credentials:edit +# If running the rails server then create or migrate existing database +if [ "${@:1:1}" == "./bin/rails" ] && [ "${@:2:1}" == "server" ]; then + ./bin/rails db:prepare + ./bin/rails db:seed + ./bin/rails data:migrate fi -bundle exec rails db:prepare:with_data -bundle exec rails db:seed - -exec "$@" +exec "${@}" diff --git a/log/.keep b/log/.keep new file mode 100644 index 00000000..e69de29b diff --git a/package.json b/package.json index 53fc9006..4595c4fc 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "@fortawesome/free-solid-svg-icons": "^6.6.0", "@hotwired/stimulus": "^3.2.2", "@hotwired/turbo-rails": "^8.0.12", - "@rails/actioncable": "7.2.200", - "@rails/activestorage": "7.2.200", + "@rails/actioncable": "8.0.0", + "@rails/activestorage": "8.0.0", "@stimulus-components/clipboard": "^5.0.0", "@tailwindcss/aspect-ratio": "^0.4.2", "@tailwindcss/forms": "^0.5.9", @@ -23,20 +23,20 @@ "cytoscape-node-html-label": "^1.2.2", "debounce": "^2.2.0", "element-matches-polyfill": "^1.0.0", - "postcss": "^8.4.47", + "postcss": "^8.4.49", "postcss-import": "^16.1.0", "postcss-nesting": "^13.0.1", - "postcss-preset-env": "^10.0.8", + "postcss-preset-env": "^10.1.0", "stimulus-textarea-autogrow": "^4.1.0", "stimulus-vite-helpers": "^3.1.0", - "tailwindcss": "^3.4.14", + "tailwindcss": "^3.4.15", "tailwindcss-stimulus-components": "^6.1.2", "thememirror": "^2.0.1", "throttleit": "^2.1.0", "tippy.js": "^6.3.7", "tom-select": "^2.3.1", - "vite": "^5.4.10", - "vite-plugin-ruby": "^5.1.0", + "vite": "^5.4.11", + "vite-plugin-ruby": "^5.1.1", "vite-plugin-stimulus-hmr": "^3.0.0", "web-worker": "^1.3.0" }, diff --git a/public/400.html b/public/400.html new file mode 100644 index 00000000..282dbc8c --- /dev/null +++ b/public/400.html @@ -0,0 +1,114 @@ + + + + +
+ +The server cannot process the request due to a client error. Please check the request and try again. If you’re the application owner check the logs for more information.
+You may have mistyped the address or the page may have moved.
-If you are the application owner check the logs for more information.
-The page you were looking for doesn’t exist. You may have mistyped the address or the page may have moved. If you’re the application owner check the logs for more information.
+Please upgrade your browser to continue.
-Your browser is not supported.
Please upgrade your browser to continue.
Maybe you tried to change something you didn't have access to.
-If you are the application owner check the logs for more information.
-The change you wanted was rejected. Maybe you tried to change something you didn’t have access to. If you’re the application owner check the logs for more information.
+If you are the application owner check the logs for more information.
-We’re sorry, but something went wrong.
If you’re the application owner check the logs for more information.