# 開発環境を最新に保つための試み

**URL:** <https://meta.discourse.org/t/one-attempt-at-keeping-a-dev-environment-up-to-date/347535>\
**Category:** Development\
**Created:** [2025 年 1 月 16 日午後 9: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:** 1\
**Showing post:** 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:** [2025 年 1 月 16 日午後 9: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>

私が[こちら](https://meta.discourse.org/t/reprise-maintaining-an-up-to-date-dev-environment/262544/4)で嘆いたように、コードを書く時間よりも開発環境を最新の状態に保つのに時間を費やしているように感じることがよくあります。

Discourseを起動するためのスクリプトがあり、多くの環境設定とその他の処理を行っています。今日は`nodejs`の正しいバージョンを取得するのに失敗し、さらに多くの時間をそれに費やしました。`asdf`からのノイズの多い出力を`grep`で除外するなどの作業も行いました。以下はDiscourseを更新するセクションです。

これは以下のことを行います。

- `all-the-plugins`および`all-the-themes`リポジトリを取得または更新します。これらは、物事を行う方法の例を見つけるのに非常に役立ちます。過去100分以内にダウンロードされた場合は、この手順をスキップします。
- 最新のベースリリースを`docker pull`します（この重要な手順を省略したことが、今日私が多くの時間を費やした理由です。`discourse_docker`で`git pull`を実行すれば済むと思っていました 🤷）。
- ベースイメージを`docker run`して、Ruby、Imagemagick、およびnodeのバージョンを取得します。次に、`asdf`を使用してそれらのバージョンをグローバルにインストールおよび適用します。（`asdf`がインストールされていることを前提としています。これは私の`newmachine`スクリプトで処理します。）
- discourseディレクトリで、mainをチェックアウトし、git pullを実行し、pnpm updateとdedupeを実行します。
- データベースとテストデータベースを移行します。

Linux（Pop!\_OS、ほとんど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
  # 注意: bundlerが壊れている場合は、`gem install bundler -v 2.5.3`を試してください

  if ! [[-d $ALL_THE_PLUGINS]]; then
    echo "プラグインが見つかりません"
    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 "\nプラグインを更新中\n "
    ./reset-all-repos
  fi

  if ! [[-d $ALL_THE_THEMES]]; then
    echo "テーマが見つかりません!!!"
    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 "\nテーマを更新中. . .\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 "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 "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 ベースコンテナからnodeバージョンを取得！
  NODE_VERSION=$(docker run discourse/base:release bash -c 'node --version'|cut -d'v' -f2)
  echo "NODEJSバージョン: $NODE_VERSION を取得しました"
  asdf install nodejs $NODE_VERSION|grep -v "already"
  asdf global nodejs $NODE_VERSION|grep -v "already"
  npm install -g pnpm

  # バージョン更新の終了
  cd $DISCOURSE_SRC
  git checkout main
  git pull
  bundle install
  echo -e "\n-----------> pnpm update を実行中. . .\n"
  pnpm update
  echo -e "\n-----------> pnpm dedupe を実行中. . .\n"
  pnpm dedupe
  echo -e "\n-----------> データベースを移行中. . .\n"
  LOAD_PLUGINS=1 ./bin/rake db:migrate
  LOAD_PLUGINS=1 RAILS_ENV=test ./bin/rake db:migrate
  exit
fi

```

---

_[View the full topic](https://meta.discourse.org/t/one-attempt-at-keeping-a-dev-environment-up-to-date/347535)._
