diff options
Diffstat (limited to 'doc/INSTALL.md')
| -rw-r--r-- | doc/INSTALL.md | 341 |
1 files changed, 341 insertions, 0 deletions
diff --git a/doc/INSTALL.md b/doc/INSTALL.md new file mode 100644 index 0000000..8056f7c --- /dev/null +++ b/doc/INSTALL.md | |||
| @@ -0,0 +1,341 @@ | |||
| 1 | # CCCMS Installation Guide | ||
| 2 | |||
| 3 | This document covers the non-obvious steps required to install the CCCMS | ||
| 4 | stack on a fresh FreeBSD jail. It assumes a FreeBSD 14.x base jail with | ||
| 5 | network access and a working pkg repository. | ||
| 6 | |||
| 7 | ## 1. Install packages | ||
| 8 | |||
| 9 | ```sh | ||
| 10 | pkg install gmake pkgconf curl gnupg git autoconf automake libtool bash \ | ||
| 11 | readline libyaml libffi gdbm libxml2 libxslt libical \ | ||
| 12 | postgresql16-server postgresql16-client \ | ||
| 13 | ImageMagick7-nox11 node vim | ||
| 14 | ``` | ||
| 15 | |||
| 16 | Note: the package is `ImageMagick7-nox11`, not `ImageMagick-nox11`. The | ||
| 17 | nox11 variant avoids pulling in the entire X11 dependency chain. | ||
| 18 | |||
| 19 | ## 2. Enable sysvipc for the jail | ||
| 20 | |||
| 21 | PostgreSQL uses System V shared memory for inter-process communication. | ||
| 22 | On the host, the jail must have sysvipc enabled. In `/etc/jail.conf` or | ||
| 23 | the jail's ezjail configuration: | ||
| 24 | |||
| 25 | `allow.sysvipc = 1;` | ||
| 26 | |||
| 27 | Restart the jail after making this change. Without it, PostgreSQL will | ||
| 28 | fail to start with a shared memory error. | ||
| 29 | |||
| 30 | ## 3. Enable and initialise PostgreSQL | ||
| 31 | |||
| 32 | ```sh | ||
| 33 | # Enable PostgreSQL in rc.conf | ||
| 34 | echo 'postgresql_enable="YES"' >> /etc/rc.conf | ||
| 35 | |||
| 36 | # Initialise the database cluster | ||
| 37 | service postgresql initdb | ||
| 38 | |||
| 39 | # Start PostgreSQL | ||
| 40 | service postgresql start | ||
| 41 | ``` | ||
| 42 | |||
| 43 | ## 4. Create database roles and set permissions | ||
| 44 | |||
| 45 | ```sh | ||
| 46 | psql -U postgres postgres | ||
| 47 | ``` | ||
| 48 | |||
| 49 | ```sql | ||
| 50 | CREATE ROLE rails WITH LOGIN PASSWORD 'your-password-here'; | ||
| 51 | ALTER ROLE rails CREATEDB; | ||
| 52 | ``` | ||
| 53 | |||
| 54 | `CREATEDB` is required for the Rails test suite to create and drop the | ||
| 55 | test database between runs. | ||
| 56 | |||
| 57 | ## 5. Create databases | ||
| 58 | |||
| 59 | ```sql | ||
| 60 | CREATE DATABASE cccms_production OWNER rails ENCODING 'UTF8' | ||
| 61 | LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8' TEMPLATE template0; | ||
| 62 | CREATE DATABASE cccms_dev OWNER rails ENCODING 'UTF8' | ||
| 63 | LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8' TEMPLATE template0; | ||
| 64 | CREATE DATABASE psql_test OWNER rails ENCODING 'UTF8' | ||
| 65 | LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8' TEMPLATE template0; | ||
| 66 | ``` | ||
| 67 | |||
| 68 | `TEMPLATE template0` is required when specifying a non-default locale. | ||
| 69 | |||
| 70 | ## 6. Restore the database dump (or start empty) | ||
| 71 | |||
| 72 | If restoring from a pg_dump: | ||
| 73 | |||
| 74 | ```sh | ||
| 75 | pg_restore -U postgres -d cccms_production \ | ||
| 76 | --no-owner --no-acl /path/to/cccms_production.dump | ||
| 77 | |||
| 78 | pg_restore -U postgres -d cccms_dev \ | ||
| 79 | --no-owner --no-acl /path/to/cccms_production.dump | ||
| 80 | ``` | ||
| 81 | |||
| 82 | Expected harmless warnings: | ||
| 83 | - `schema "public" already exists` — benign, ignore | ||
| 84 | - `array_accum aggregate` failure — dead code, ignore | ||
| 85 | |||
| 86 | Transfer ownership to the rails user (REASSIGN OWNED does not work on | ||
| 87 | PostgreSQL 15+ due to system object protection): | ||
| 88 | |||
| 89 | ```sh | ||
| 90 | psql -U postgres cccms_production | ||
| 91 | ``` | ||
| 92 | |||
| 93 | ```sql | ||
| 94 | DO $$ | ||
| 95 | DECLARE | ||
| 96 | obj RECORD; | ||
| 97 | BEGIN | ||
| 98 | FOR obj IN | ||
| 99 | SELECT tablename FROM pg_tables WHERE schemaname = 'public' | ||
| 100 | LOOP | ||
| 101 | EXECUTE 'ALTER TABLE public.' || quote_ident(obj.tablename) || | ||
| 102 | ' OWNER TO rails'; | ||
| 103 | END LOOP; | ||
| 104 | FOR obj IN | ||
| 105 | SELECT sequence_name FROM information_schema.sequences | ||
| 106 | WHERE sequence_schema = 'public' | ||
| 107 | LOOP | ||
| 108 | EXECUTE 'ALTER SEQUENCE public.' || quote_ident(obj.sequence_name) || | ||
| 109 | ' OWNER TO rails'; | ||
| 110 | END LOOP; | ||
| 111 | FOR obj IN | ||
| 112 | SELECT viewname FROM pg_views WHERE schemaname = 'public' | ||
| 113 | LOOP | ||
| 114 | EXECUTE 'ALTER VIEW public.' || quote_ident(obj.viewname) || | ||
| 115 | ' OWNER TO rails'; | ||
| 116 | END LOOP; | ||
| 117 | END $$; | ||
| 118 | |||
| 119 | ALTER SCHEMA public OWNER TO rails; | ||
| 120 | ``` | ||
| 121 | |||
| 122 | Repeat for `cccms_dev`. | ||
| 123 | |||
| 124 | ## 7. Clone the repository | ||
| 125 | |||
| 126 | ```sh | ||
| 127 | cd /usr/local/www | ||
| 128 | git clone https://github.com/erdgeist/cccms.git | ||
| 129 | cd cccms | ||
| 130 | git checkout rails-upgrade | ||
| 131 | ``` | ||
| 132 | |||
| 133 | ## 8. Copy assets (optional but recommended) | ||
| 134 | |||
| 135 | The `public/system/uploads/` directory contains all uploaded files | ||
| 136 | referenced by the database. Without it, images and attachments will be | ||
| 137 | missing throughout the site. | ||
| 138 | |||
| 139 | ```sh | ||
| 140 | # On the source system: | ||
| 141 | tar -czf /tmp/cccms_uploads.tar.gz -C /usr/local/www cccms/public/system | ||
| 142 | |||
| 143 | # On the new system: | ||
| 144 | tar -xzf /path/to/cccms_uploads.tar.gz -C /usr/local/www | ||
| 145 | ``` | ||
| 146 | |||
| 147 | ## 9. Copy gitignored config files | ||
| 148 | |||
| 149 | These files are not in the repository and must be copied or created: | ||
| 150 | |||
| 151 | ```sh | ||
| 152 | # Required: | ||
| 153 | config/database.yml | ||
| 154 | config/initializers/secret_token.rb | ||
| 155 | |||
| 156 | # If used: | ||
| 157 | config/initializers/exception_notification.rb | ||
| 158 | /usr/local/etc/unicorn.rb | ||
| 159 | ``` | ||
| 160 | |||
| 161 | `database.yml` template: | ||
| 162 | |||
| 163 | ```yaml | ||
| 164 | development: | ||
| 165 | adapter: postgresql | ||
| 166 | encoding: unicode | ||
| 167 | database: cccms_dev | ||
| 168 | pool: 5 | ||
| 169 | username: rails | ||
| 170 | password: your-password-here | ||
| 171 | |||
| 172 | test: | ||
| 173 | adapter: postgresql | ||
| 174 | encoding: UTF8 | ||
| 175 | database: psql_test | ||
| 176 | username: rails | ||
| 177 | password: | ||
| 178 | |||
| 179 | production: | ||
| 180 | adapter: postgresql | ||
| 181 | encoding: unicode | ||
| 182 | database: cccms_production | ||
| 183 | pool: 5 | ||
| 184 | username: rails | ||
| 185 | password: your-password-here | ||
| 186 | ``` | ||
| 187 | |||
| 188 | ## 10. Install rvm | ||
| 189 | |||
| 190 | rvm 1.29.12 is the latest formal release as of mid-2026. Download and | ||
| 191 | verify before installing: | ||
| 192 | |||
| 193 | ```sh | ||
| 194 | curl -L https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz \ | ||
| 195 | -o /tmp/rvm-1.29.12.tar.gz | ||
| 196 | curl -L https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc \ | ||
| 197 | -o /tmp/rvm-1.29.12.tar.gz.asc | ||
| 198 | |||
| 199 | gpg --keyserver hkps://keys.openpgp.org \ | ||
| 200 | --recv-keys 7D2BAF1CF37B13E2069D6956105BD0E739499BDB | ||
| 201 | |||
| 202 | gpg --verify /tmp/rvm-1.29.12.tar.gz.asc /tmp/rvm-1.29.12.tar.gz | ||
| 203 | ``` | ||
| 204 | |||
| 205 | If verification passes: | ||
| 206 | |||
| 207 | ```sh | ||
| 208 | tar -xzf /tmp/rvm-1.29.12.tar.gz -C /tmp | ||
| 209 | bash /tmp/rvm-1.29.12/install --auto-dotfiles | ||
| 210 | source /usr/local/rvm/scripts/rvm | ||
| 211 | ``` | ||
| 212 | |||
| 213 | The installed rvm ships with a stale known-versions list that only goes | ||
| 214 | to Ruby 3.0.0. Update it immediately: | ||
| 215 | |||
| 216 | ```sh | ||
| 217 | curl -L https://raw.githubusercontent.com/rvm/rvm/master/config/known \ | ||
| 218 | -o /usr/local/rvm/config/known | ||
| 219 | rvm list known | grep '^\[ruby-\]3\.' | ||
| 220 | ``` | ||
| 221 | |||
| 222 | Should now show Ruby 3.2.x and later. | ||
| 223 | |||
| 224 | ## 11. Install Ruby and create gemset | ||
| 225 | |||
| 226 | ```sh | ||
| 227 | source /usr/local/rvm/scripts/rvm | ||
| 228 | rvm install 3.2.11 --autolibs=read-only --with-opt-dir=/usr/local | ||
| 229 | rvm use 3.2.11 | ||
| 230 | rvm gemset create rails7-upgrade | ||
| 231 | rvm use 3.2.11@rails7-upgrade | ||
| 232 | ``` | ||
| 233 | |||
| 234 | The `.ruby-version` and `.ruby-gemset` files in the project root will | ||
| 235 | cause rvm to switch automatically when entering the project directory. | ||
| 236 | |||
| 237 | ## 12. Install bundler and gems | ||
| 238 | |||
| 239 | ```sh | ||
| 240 | gem install bundler | ||
| 241 | cd /usr/local/www/cccms | ||
| 242 | export MAKE=gmake | ||
| 243 | bundle install 2>&1 | tee /tmp/bundle_install.log | ||
| 244 | ``` | ||
| 245 | |||
| 246 | `MAKE=gmake` is required because FreeBSD's native make (BSD make) uses | ||
| 247 | different `-j` syntax than native gems expect. Without it, several native | ||
| 248 | gem compilations will fail. | ||
| 249 | |||
| 250 | ## 13. Run migrations | ||
| 251 | |||
| 252 | ```sh | ||
| 253 | bundle exec rails db:migrate | ||
| 254 | ``` | ||
| 255 | |||
| 256 | If restoring an existing database, first insert fake migration versions | ||
| 257 | to prevent re-running migrations that were applied to the old schema: | ||
| 258 | |||
| 259 | ```sql | ||
| 260 | INSERT INTO schema_migrations (version) VALUES | ||
| 261 | ('20260624035149'), ('20260624035150'), ('20260624035151'), | ||
| 262 | ('20260624035152'), ('20260624035153'), | ||
| 263 | ('20260625031409') | ||
| 264 | ON CONFLICT DO NOTHING; | ||
| 265 | ``` | ||
| 266 | |||
| 267 | Then run `db:migrate` to apply only new migrations. | ||
| 268 | |||
| 269 | To enable full-text search (requires PostgreSQL 10+ with plpgsql): | ||
| 270 | |||
| 271 | ```sh | ||
| 272 | mv doc/20260626025705_add_search_vector_to_page_translations.rb.pending \ | ||
| 273 | db/migrate/20260626025705_add_search_vector_to_page_translations.rb | ||
| 274 | bundle exec rails db:migrate | ||
| 275 | ``` | ||
| 276 | |||
| 277 | ## 14. Compile admin assets | ||
| 278 | |||
| 279 | ```sh | ||
| 280 | bundle exec rails assets:precompile | ||
| 281 | ``` | ||
| 282 | |||
| 283 | This compiles the admin JavaScript bundle (jQuery, jQuery UI, hotkeys) | ||
| 284 | into `public/assets/`. Required for the admin interface to work. Must be | ||
| 285 | re-run after any changes to `app/assets/javascripts/admin_bundle.js`. | ||
| 286 | |||
| 287 | ## 15. Run tests (optional but recommended) | ||
| 288 | |||
| 289 | ```sh | ||
| 290 | bundle exec rake test | ||
| 291 | ``` | ||
| 292 | |||
| 293 | Expected result: 129 runs, ~339 assertions, 3 failures, 0 errors. | ||
| 294 | The 3 failures are pre-existing and documented in the handover document. | ||
| 295 | |||
| 296 | ## 16. Start the server | ||
| 297 | |||
| 298 | Development: | ||
| 299 | |||
| 300 | ```sh | ||
| 301 | bundle exec rails server -p 3000 -b 0.0.0.0 -e development | ||
| 302 | ``` | ||
| 303 | |||
| 304 | Note: `-b 0.0.0.0` is required — `localhost` does not resolve inside | ||
| 305 | a FreeBSD jail. | ||
| 306 | |||
| 307 | Production (unicorn): | ||
| 308 | |||
| 309 | ```sh | ||
| 310 | /usr/local/rvm/gems/ruby-3.2.11@rails7-upgrade/wrappers/unicorn \ | ||
| 311 | -c /usr/local/etc/unicorn.rb -E production -D | ||
| 312 | ``` | ||
| 313 | |||
| 314 | The rc.d script at `/etc/rc.d/cccms` needs updating from `unicorn_rails` | ||
| 315 | to `unicorn` before use — see the handover document for details. | ||
| 316 | |||
| 317 | ## Known Gotchas | ||
| 318 | |||
| 319 | **sysvipc:** PostgreSQL will fail silently or with a cryptic error if | ||
| 320 | sysvipc is not enabled for the jail. Enable it on the host before starting | ||
| 321 | PostgreSQL. | ||
| 322 | |||
| 323 | **MAKE=gmake:** Native gem compilation fails without this. Set it before | ||
| 324 | every `bundle install` or add to your shell profile. | ||
| 325 | |||
| 326 | **rvm known versions:** rvm 1.29.12 ships with a stale `config/known` that | ||
| 327 | only lists Ruby up to 3.0.0. Always update from master after installing rvm. | ||
| 328 | |||
| 329 | **ImageMagick 7:** The `convert` command is deprecated; use `magick convert`. | ||
| 330 | The `file_attachment.rb` concern needs updating before production use. | ||
| 331 | |||
| 332 | **pg_hba.conf:** The default FreeBSD PostgreSQL configuration uses `trust` | ||
| 333 | for local Unix socket connections, which is sufficient for the application. | ||
| 334 | No changes needed unless TCP connections are required. | ||
| 335 | |||
| 336 | **assets:precompile:** Must be run after checkout and after any changes to | ||
| 337 | admin JavaScript. The compiled files in `public/assets/` are gitignored. | ||
| 338 | |||
| 339 | **chaos_calendar include path:** On FreeBSD 14.x with libical 3.0.20+, | ||
| 340 | the include path is `<libical/ical.h>` not `<ical.h>`. This is already | ||
| 341 | fixed in the `erdgeist-ruby1.9` branch. | ||
