# Eén poging om een Dev-omgeving up-to-date te houden

**URL:** https://meta.discourse.org/t/one-attempt-at-keeping-a-dev-environment-up-to-date/347535
**Category:** Development
**Created:** [16 januari 2025 om 21:57 UTC](https://meta.discourse.org/t/one-attempt-at-keeping-a-dev-environment-up-to-date/347535 "2025-01-16T21:57:34Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [16 januari 2025 om 21:57 UTC](https://meta.discourse.org/t/one-attempt-at-keeping-a-dev-environment-up-to-date/347535/1 "2025-01-16T21:57:34Z")

</div>

As I lamented [here](https://meta.discourse.org/t/reprise-maintaining-an-up-to-date-dev-environment/262544/4), 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 🤷 )
- `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).

```bash
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

```

---

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [16 januari 2025 om 23:15 UTC](https://meta.discourse.org/t/one-attempt-at-keeping-a-dev-environment-up-to-date/347535/2 "2025-01-16T23:15:34Z")

</div>

This is for local dev environments with Docker, correct?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [16 januari 2025 om 23:17 UTC](https://meta.discourse.org/t/one-attempt-at-keeping-a-dev-environment-up-to-date/347535/3 "2025-01-16T23:17:08Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [16 januari 2025 om 23:26 UTC](https://meta.discourse.org/t/one-attempt-at-keeping-a-dev-environment-up-to-date/347535/4 "2025-01-16T23:26:36Z")

</div>

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](https://meta.discourse.org/t/placeholder-forms/113533) 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. 😄

* * *

1. [Getting Started | asdf](https://asdf-vm.com/guide/getting-started.html) 

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'`

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [17 januari 2025 om 02:18 UTC](https://meta.discourse.org/t/one-attempt-at-keeping-a-dev-environment-up-to-date/347535/5 "2025-01-17T02:18:50Z")

</div>

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

Thanks
