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 agit pull
indiscourse_docker
would do it )docker run
the base image to get versions for Ruby, Imagemagick, and node; then useasdf
to install and apply globally those versions. (It assumes you haveasdf
–I handle that in mynewmachine
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