Post

Cloudflare Pages で Ruby 3.2.9 がビルドエラーになる問題と解決方法

問題

Jekyll サイトを Cloudflare Pages にデプロイしようとしたところ、以下のビルドエラーが発生しました。 全然気づいていなかったですが、20日前くらいから失敗するようになっていて通知を見逃していました。。。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Cloning repository...
Success: Finished cloning repository files
Checking for configuration in a Wrangler configuration file (BETA)
No wrangler.toml file found. Continuing.
Detected the following tools from environment: ruby@3.2.9

Installing ruby 3.2.9

Version not found

If this is a new Ruby version, you may need to update the plugin:
asdf plugin update ruby
Error: Exit with error code: 1
Failed: build command exited with code: 1
Failed: error occurred while running build command

原因

.ruby-version ファイルで Ruby 3.2.9 を指定していましたが、Cloudflare Pages のビルド環境では Ruby 3.2.9 がまだサポートされていないため、エラーが発生しました。

1
2
$ cat .ruby-version
3.2.9

Cloudflare Pages は内部で asdf を使用しているようで、それで Ruby バージョンを管理しています。

解決方法

Ruby バージョンを安定版に変更

AIにメンテナンスをおまかせしたことで勝手にバージョンが上がっていた .ruby-version をサポートされているバージョンに変更します。今回はパッチバージョンを下げました。

1
2
- 3.2.9
+ 3.2.0

変更をプッシュしてデプロイ

1
2
3
git add .ruby-version
git commit -m "Cloudflare Pages互換性のためRubyバージョンを3.2.0に変更"
git push

これでリポジトリに紐づけている Cloudflare Pages が自動的に再ビルドを開始したのでOKです。

Cloudflare Pages でサポートされている Ruby バージョン

Cloudflare Pages は asdf の Ruby プラグインを使用しているのですが、サポート状況は以下で確認できるようです。基本的には asdf を見ると良いです。

  • asdf-ruby プラグイン
  • 一般的に メジャー・マイナーバージョンの初期リリース(3.2.0, 3.3.0 など)は安定してサポートされています
  • (パッチバージョンは。。。?)

ローカル環境への影響

ローカルで Ruby 3.2.9 を使用している場合でも問題ありません:

  • rbenv/asdf: 3.2.0 と 3.2.9 はマイナーバージョン互換性があるため、通常は問題なく動作します
  • Gemfile.lock: バージョン差異による問題が発生した場合は bundle update で対応

とりあえずデプロイできるようになったので、これで Cloudflare Pages でのビルドが成功するようになります。

This post is licensed under CC BY 4.0 by the author.

© taroru. Some rights reserved.

Using the Chirpy theme for Jekyll.