|
| 1 | +This page details the steps required to set up a production environment from source. |
| 2 | + |
| 3 | +> [!NOTE] |
| 4 | +> This documentation has been heavily adopted from [Mastodons 'Installing from source' documentation](https://docs.joinmastodon.org/admin/install/) |
| 5 | +
|
| 6 | +## Pre-requisites |
| 7 | + |
| 8 | +* A server running **Ubuntu 24.04** or **Debian 12** that you have root access to |
| 9 | +* A domain name (or subdomain) for your Retrospring site, like `example.com` |
| 10 | +* A mail delivery service or an SMTP server |
| 11 | + |
| 12 | +### System repositories |
| 13 | + |
| 14 | +Make sure curl, wget, gnupg, apt-transport-https, lsb-release and ca-certificates are installed first: |
| 15 | + |
| 16 | +```shell |
| 17 | +apt install -y curl wget gnupg apt-transport-https lsb-release ca-certificates |
| 18 | +``` |
| 19 | + |
| 20 | +#### Node.js |
| 21 | + |
| 22 | +```shell |
| 23 | +mkdir -p /etc/apt/keyrings && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg |
| 24 | +echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list |
| 25 | +``` |
| 26 | + |
| 27 | +Retrospring uses Yarn as a package manager: |
| 28 | + |
| 29 | +```shell |
| 30 | +npm install -g yarn |
| 31 | +``` |
| 32 | + |
| 33 | +### System packages |
| 34 | + |
| 35 | +```shell |
| 36 | +apt-get install -y --no-install-recommends build-essential libpq-dev postgresql-client libxml2-dev libxslt1-dev libmagickwand-dev imagemagick libidn11-dev libicu-dev libjemalloc-dev libyaml-dev libreadline-dev libssl-dev libjemalloc-dev redis-server redis-tools |
| 37 | +``` |
| 38 | + |
| 39 | +### Installing Ruby |
| 40 | + |
| 41 | +We will use rbenv to manage Ruby versions as it simplifies obtaining the correct versions and updating them when new releases are available. Since rbenv needs to be installed for an individual Linux user, we must first create the user account under which Retrospring will run: |
| 42 | + |
| 43 | +```shell |
| 44 | +adduser --disabled-login retrospring |
| 45 | +usermod -s /bin/bash retrospring |
| 46 | +``` |
| 47 | + |
| 48 | +We can then switch to the user: |
| 49 | + |
| 50 | +```shell |
| 51 | +su - retrospring |
| 52 | +``` |
| 53 | + |
| 54 | +And proceed to install rbenv and rbenv-build: |
| 55 | + |
| 56 | +```bash |
| 57 | +git clone https://github.com/rbenv/rbenv.git ~/.rbenv |
| 58 | +echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc |
| 59 | +echo 'eval "$(rbenv init -)"' >> ~/.bashrc |
| 60 | +exec bash |
| 61 | +``` |
| 62 | +```bash |
| 63 | +git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build |
| 64 | +``` |
| 65 | + |
| 66 | +Once this is done, we can install the correct Ruby version: |
| 67 | + |
| 68 | +```shell |
| 69 | +RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 3.2.3 |
| 70 | +rbenv global 3.2.3 |
| 71 | +``` |
| 72 | + |
| 73 | +We’ll also need to install the bundler: |
| 74 | + |
| 75 | +```shell |
| 76 | +gem install bundler --no-document |
| 77 | +``` |
| 78 | + |
| 79 | +Return to the root user: |
| 80 | + |
| 81 | +```shell |
| 82 | +exit |
| 83 | +``` |
| 84 | + |
| 85 | +## Setup |
| 86 | + |
| 87 | +### Setting up PostgreSQL |
| 88 | + |
| 89 | +#### Performance configuration (optional) |
| 90 | + |
| 91 | +For optimal performance, you may use [pgTune](https://pgtune.leopard.in.ua/#/) to generate an appropriate configuration and edit values in `/etc/postgresql/16/main/postgresql.conf` before restarting PostgreSQL with `systemctl restart postgresql` |
| 92 | + |
| 93 | +#### Creating a user |
| 94 | + |
| 95 | +You will need to create a PostgreSQL user that Retrospring could use. It is easiest to go with “ident” authentication in a simple setup, i.e. the PostgreSQL user does not have a separate password and can be used by the Linux user with the same username. |
| 96 | + |
| 97 | +Open the prompt: |
| 98 | + |
| 99 | +```shell |
| 100 | +sudo -u postgres psql |
| 101 | +``` |
| 102 | + |
| 103 | +In the prompt, execute: |
| 104 | + |
| 105 | +```sql |
| 106 | +CREATE USER retrospring CREATEDB; |
| 107 | +CREATE DATABASE retrospring_production OWNER retrospring; |
| 108 | +\q |
| 109 | +``` |
| 110 | + |
| 111 | +Done! |
| 112 | + |
| 113 | +### Setting up nginx |
| 114 | + |
| 115 | +Copy the configuration template for nginx from the Retrospring directory: |
| 116 | + |
| 117 | +```bash |
| 118 | +cp /home/retrospring/retrospring/docs/nginx.conf /etc/nginx/sites-available/retrospring |
| 119 | +ln -s /etc/nginx/sites-available/retrospring /etc/nginx/sites-enabled/retrospring |
| 120 | +rm /etc/nginx/sites-enabled/default |
| 121 | +``` |
| 122 | + |
| 123 | +Then edit `/etc/nginx/sites-available/retrospring` and follow the comments and adjusts domains and paths according to your setup. |
| 124 | + |
| 125 | +Reload nginx for the changes to take effect: |
| 126 | + |
| 127 | +```bash |
| 128 | +systemctl reload nginx |
| 129 | +``` |
| 130 | + |
| 131 | +### Setting up Retrospring |
| 132 | + |
| 133 | +It is time to download the Retrospring code. Switch to the retrospring user: |
| 134 | + |
| 135 | +```shell |
| 136 | +su - retrospring |
| 137 | +``` |
| 138 | + |
| 139 | +#### Checking out the code |
| 140 | + |
| 141 | +Use git to download the latest stable release of Retrospring: |
| 142 | + |
| 143 | +```shell |
| 144 | +git clone https://github.com/Retrospring/retrospring.git && cd retrospring |
| 145 | +``` |
| 146 | + |
| 147 | +Visit [the latest releases page](https://github.com/retrospring/retrospring/releases/latest) and check it out (ex. `2024.0811.1`) |
| 148 | + |
| 149 | +```shell |
| 150 | +git checkout 2024.0811.01 |
| 151 | +``` |
| 152 | + |
| 153 | +#### Installing dependencies |
| 154 | + |
| 155 | +Now to install Ruby and JavaScript dependencies: |
| 156 | + |
| 157 | +```shell |
| 158 | +bundle install --deployment --without development test mysql |
| 159 | +yarn install --frozen-lockfile |
| 160 | +``` |
| 161 | + |
| 162 | +#### Configuring Retrospring |
| 163 | + |
| 164 | +##### Database configuration |
| 165 | + |
| 166 | +You can either configure Retrosprings database connection via environment variables: |
| 167 | + |
| 168 | +```shell |
| 169 | +export DATABASE_URL=postgres://[username]:[password]@[host]/[dbname]?pool=25 |
| 170 | +``` |
| 171 | + |
| 172 | +...or with copying the `config/database.yml.postgres` to `config/database.yml` and adjusting its contents: |
| 173 | + |
| 174 | +```shell |
| 175 | +cp config/database.yml.postgres config/database.yml |
| 176 | +$EDITOR config/database.yml |
| 177 | +``` |
| 178 | + |
| 179 | +##### Application configuration |
| 180 | + |
| 181 | +Copy the configuration file `config/justask.yml.example` to `config/justask.yml` and adjust its contents: |
| 182 | + |
| 183 | +``` |
| 184 | +cp config/justask.yml.example config/justask.yml |
| 185 | +$EDITOR config/justask.yml |
| 186 | +``` |
| 187 | +##### SMTP configuration |
| 188 | + |
| 189 | +It is recommended to read up on the chapter [Action Mailer configuration](https://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration) from the Ruby on Rails guides. |
| 190 | + |
| 191 | +E-Mail sending configuration is currently done via environment variables, the following ones are available: |
| 192 | + |
| 193 | +| Rails `:smtp_settings` key | Retrospring environent variable | |
| 194 | +|----------------------------|---------------------------------| |
| 195 | +| `:address` | `SMTP_SERVER` | |
| 196 | +| `:port` | `SMTP_PORT` | |
| 197 | +| `:user_name` | `SMTP_LOGIN` | |
| 198 | +| `:password` | `SMTP_PASSWORD` | |
| 199 | +| `:domain` | `SMTP_DOMAIN` (or `LOCAL_DOMAIN` as fallback) | |
| 200 | +| `:authentication` | `SMTP_AUTH_METHOD` |
| 201 | +| `:ca_file` | `SMTP_CA_FILE` (`/etc/ssl/certs/ca-certificates.crt` as default) | |
| 202 | +| `:openssl_verify_mode` | `SMTP_OPENSSL_VERIFY_MODE` | |
| 203 | +| `:enable_starttls` | `SMTP_ENABLE_STARTTLS` (`always`, `never` or `auto`) | |
| 204 | +| `:enable_starttls_auto` | `true` when `SMTP_ENABLE_STARTTLS` is set to `auto`, otherwise `false` | |
| 205 | +| `:tls` | `SMTP_TLS` (any value, or `true` enables this) | |
| 206 | +| `:ssl` | `SMTP_SSL` (any value, or `true` enables this) | |
| 207 | + |
| 208 | +Additionally, you can configure the Action Mailer delivery method using `SMTP_DELIVERY_METHOD`, the default is `sendmail`. |
| 209 | + |
| 210 | +#### Setup tasks |
| 211 | + |
| 212 | +##### Generate secret key |
| 213 | + |
| 214 | +This command creates a secret key used for encryption/hashing across the application: |
| 215 | + |
| 216 | +```shell |
| 217 | +RAILS_ENV=production bundle exec rails credentials:edit |
| 218 | +``` |
| 219 | + |
| 220 | +> [!NOTE] |
| 221 | +> This command only needs to be run once per setup, the other setup tasks need to be run after each deployment. |
| 222 | +
|
| 223 | +##### Export locales |
| 224 | + |
| 225 | +This exports the locales for use in JavaScript code: |
| 226 | + |
| 227 | +```shell |
| 228 | +RAILS_ENV=production bundle exec i18n export |
| 229 | +``` |
| 230 | + |
| 231 | +##### Initialize the database |
| 232 | + |
| 233 | +This command creates the database schema: |
| 234 | + |
| 235 | +```shell |
| 236 | +RAILS_ENV=production bundle exec rake db:migrate |
| 237 | +``` |
| 238 | + |
| 239 | +##### Precompile assets |
| 240 | + |
| 241 | +This command compiles all JavaScript/Stylesheet assets: |
| 242 | + |
| 243 | +```shell |
| 244 | +RAILS_ENV=production bundle exec rake assets:precompile |
| 245 | +``` |
| 246 | + |
| 247 | +#### Running Retrospring |
| 248 | + |
| 249 | +##### Manually |
| 250 | + |
| 251 | +You can start Retrospring manually using `foreman`. |
| 252 | + |
| 253 | +If it is not installed yet, install it using Bundler with: |
| 254 | + |
| 255 | +```shell |
| 256 | +gem install foreman |
| 257 | +``` |
| 258 | + |
| 259 | +Then just start Retrospring using: |
| 260 | +```shell |
| 261 | +foreman start |
| 262 | +``` |
| 263 | + |
| 264 | +##### As systemd services |
| 265 | + |
| 266 | +Copy the example Retrospring service files from the repository: |
| 267 | + |
| 268 | +```shell |
| 269 | +cp /home/retrospring/retrospring/docs/systemd/retrospring-*.service /etc/systemd/system/ |
| 270 | +``` |
| 271 | + |
| 272 | +If you deviated from the defaults at any point, check that the username and paths are correct: |
| 273 | + |
| 274 | +``` |
| 275 | +$EDITOR /etc/systemd/system/retrospring-*.service |
| 276 | +``` |
| 277 | + |
| 278 | +Finally, start and enable the new systemd services: |
| 279 | +```shell |
| 280 | +systemctl daemon-reload |
| 281 | +systemctl enable --now retrospring-web retrospring-sidekiq |
| 282 | +``` |
| 283 | + |
| 284 | +They will now automatically start at boot. |
| 285 | + |
| 286 | +---- |
| 287 | + |
| 288 | +You should now be able to visit your configured domain and see the Retrospring homepage! |
| 289 | + |
| 290 | +Continue to [First Steps](/docs/setup/first-steps.md) for setting up an administrator account and more. |
0 commit comments