Nice way to run a dev env

NateDhaliwal
Tue, 22 Jul 2025 13:01:36 +0000
Extras

Hi everyone, just sharing a handy script I’ve put together that helps me run my Discourse dev instance.

It pulls all the latest changes, pulls the updates from installed plugins, and runs all the migrations, as well as installing the necessary gems and pnpm packages.

The downside to the script is that it also pulls the plugins bundled with core, which technically wouldn’t do anything since they would be updated with the first git pull. Oh well.

Note: chatgpt.com helped me write the if statement logic (my initial experiments failed).
~/rundiscourse.sh:

#!/bin/bash

cd ~/discourse
git pull
cd plugins
PLUGIN_DIR=~/discourse/plugins

for folder in "$PLUGIN_DIR"/*; do
  if [ -d "$folder/.git" ]; then
    output=$(git -C "$folder" pull)
    if ! echo "$output" | grep -q "Already up to date."; then
      echo "[$(basename "$folder")] $output"
    fi
  fi
done
cd ~/discourse
bundle install
pnpm install
bin/rails db:migrate
DISCOURSE_HOSTNAME=localhost UNICORN_LISTENER=localhost:3000 bin/ember-cli -u

Then, run:

chmod +x rundiscourse.sh

Then, go to the ~/.bashrc file (using nano, or anything), and add this bit if you don’t already have it (it’s nearer the bottom)

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

Then, add the following to the ~/.bash_aliases file:

alias discourse="~/rundiscourse.sh"

Close your terminal and re-open it.
Now, when you run discourse in the terminal, your development environment should start!

I hoped this helped! Also, do let me know if I’m doing something wrong, or if it can be improved. Thanks!

3 messaggi - 2 partecipanti