One attempt at keeping a Dev environment up to date

As I lamented here, I often feel like I spend more time trying to keep my dev environment up to date than I do writing code.

I have a script that I use to start up Discourse with a bunch of ENV settings that also does a bunch of other stuff. Today it was failing to get the correct version of nodejs and I spent a bunch more time updating it. I even did stuff like grep out noisy output from asdf and such. Here’s the section that updates Discourse.

Here’s what it does:

  • Retrieve and/or update the all-the-plugins and all-the-themes repos. These are very useful to find examples of how to do things. If they have been downloaded in the past 100 minutes, it skips this step.
  • docker pull the latest base release (missing this crucial step is why I spent a ton of time on this today–somehow I thought that doing a git pull in discourse_docker would do it :person_shrugging: )
  • docker run the base image to get versions for Ruby, Imagemagick, and node; then use asdf to install and apply globally those versions. (It assumes you have asdf–I handle that in my newmachine script.).
  • In the discourse directory, checkout main, git pull, run pnpm update and dedupe
  • Migrate the database and test database

I haven’t tested it anywhere but Linux (Pop!OS, which is mostly Ubuntu).

SRC=~/src/discourse-repos
DISCOURSE_SRC=/home/pfaffman/src/discourse-repos/discourse
ALL_THE_PLUGINS=~/src/discourse-repos/all-the-plugins
ALL_THE_THEMES=~/src/discourse-repos/all-the-themes
ARG=$1
COMMAND=""

if [[ "$ARG" == "update" ]] || [[ "$ARG" == "upgrade" ]]
then
  # NOTE: if bundler is broken, try `gem install bundler -v 2.5.3`

  if ! [[ -d $ALL_THE_PLUGINS ]]; then
    echo "MISSING THE PLUGINS"
    cd $SRC
    git clone https://github.com/discourse/all-the-plugins
    cd $ALL_THE_PLUGINS
    ./reset-all-repos
  fi
  cd $ALL_THE_PLUGINS
  if [ -z "$(find official -mmin -100)" ]; then
    echo -e "\nUpdating the plugins\n "
    ./reset-all-repos
  fi

  if ! [[ -d $ALL_THE_THEMES ]]; then
    echo "MISSING THE THEMES!!!"
    sleep 5
    cd $SRC
    git clone https://github.com/discourse/all-the-themes
    cd $ALL_THE_THEMES
    ./reset-all-repos
  fi

  cd $ALL_THE_THEMES
  if [ -z "$(find official -mmin -100)" ]; then
    echo -e "\nUpdating themes. . . \n"
    ./reset-all-repos
  fi

  asdf plugin add ruby |grep -v "already"
  asdf plugin add imagemagick |grep -v "already"
  asdf plugin update --all > /dev/null

  docker pull discourse/base:release
  RUBY_VERSION=$(docker run discourse/base:release bash -c 'ruby --version'|cut -d' ' -f2)
  echo "Got RUBY_VERSION $RUBY_VERSION"
  asdf install ruby $RUBY_VERSION|grep -v "already"
  asdf global ruby $RUBY_VERSION|grep -v "already"
  IMAGE_MAGICK_VERSION=$(docker run discourse/base:release bash -c 'convert --version'|head -1|cut -d' ' -f3)
  echo "Got IMAGE_MAGICK_VERSION: $IMAGE_MAGICK_VERSION"
  asdf install imagemagick $IMAGE_MAGICK_VERSION|grep -v "already"
  asdf global imagemagick $IMAGE_MAGICK_VERSION|grep -v "already"

  # 2025-01-13 get node version from the base container!
  NODE_VERSION=$(docker run discourse/base:release bash -c 'node --version'|cut -d'v' -f2)
  echo "GOT NODEJS version: $NODE_VERSION"
  asdf install nodejs $NODE_VERSION|grep -v "already"
  asdf global nodejs $NODE_VERSION|grep -v "already"
  npm install -g pnpm

  # end of version updates
  cd $DISCOURSE_SRC
  git checkout main
  git pull
  bundle install
  echo -e "\n----------> Running pnpm update. . .\n"
  pnpm update
  echo -e "\n----------> Running pnpm dedupe. . .\n"
  pnpm dedupe
  echo -e "\n----------> Migrating the databases. . .\n"
  LOAD_PLUGINS=1 ./bin/rake db:migrate
  LOAD_PLUGINS=1 RAILS_ENV=test ./bin/rake db:migrate
  exit
fi
2 Likes

This is for local dev environments with Docker, correct?

No. Without docker. If you’re using docker then all of this is handled on the docker container.

1 Like

Jay, I wish I could react with multiple :chefs_kiss:.

Tested on Ubuntu on WSL as non-root, stumbled upon a few hiccups and things to do before successfully running it.

I just had to:

  • Install asdf[1] as precised in your guide and nodejs[2] prior to running the script

  • Run sudo chown -R $(whoami):$(whoami) ~/discourse because I had permissions issues[3] when the script ran pnpm dedupe. I’m not exactly fluent in Linux, so maybe there’s a more proper solution.

A small suggestion to make this guide even neater, maybe use placeholders to replace the paths variables at the beginning of your codeblock. Not that would make things that much convenient, but it would be a nice touch. :smile:


  1. Getting Started | asdf ↩︎

  2. asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git ↩︎

  3. EACCES: permission denied, unlink '/home/coco/discourse/app/assets/javascripts/discourse-plugins/node_modules/ember-this-fallback' ↩︎

1 Like

Hmm. Yeah. Maybe it should check that nodejs is installed. I’m not sure how I offish nodejs in a new machine.

Thanks

1 Like