Cloudflare Pagesでデプロイする
Cloudflare Pages デプロイログメモ
背景
Cloudflare Pages で Jekyll + Chirpy テーマのサイトをデプロイしようとした際、以下のエラーが発生。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
```
16:43:37.337 Bundle complete! 5 Gemfile dependencies, 41 gems now installed.
16:43:37.337 Gems in the groups 'development' and 'test' were not installed.
16:43:37.338 Use `bundle info [gemname]` to see where a bundled gem is installed.
16:43:37.405 Executing user command: jekyll build
16:43:38.534 /opt/buildhome/.asdf/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/bundler-2.6.9/lib/bundler/definition.rb:691:in 'Bundler::Definition#materialize': Could not find html-proofer-5.0.10, async-2.27.0, nokogiri-1.18.9-x86_64-linux-gnu, pdf-reader-2.14.1, rainbow-3.1.1, typhoeus-1.4.1, yell-2.2.2, zeitwerk-2.7.3, console-1.33.0, fiber-annotation-0.2.0, io-event-1.12.1, metrics-0.13.0, traces-0.16.2, Ascii85-2.0.1, afm-0.2.2, hashery-2.1.2, ruby-rc4-0.1.5, ttfunk-1.8.0, ethon-0.16.0, fiber-local-1.1.0, fiber-storage-1.0.1 in locally installed gems (Bundler::GemNotFound)
16:43:38.534 from /opt/buildhome/.asdf/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/bundler-2.6.9/lib/bundler/definition.rb:237:in 'Bundler::Definition#specs'
16:43:38.534 from /opt/buildhome/.asdf/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/bundler-2.6.9/lib/bundler/definition.rb:304:in 'Bundler::Definition#specs_for'
16:43:38.534 from /opt/buildhome/.asdf/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/bundler-2.6.9/lib/bundler/runtime.rb:18:in 'Bundler::Runtime#setup'
16:43:38.534 from /opt/buildhome/.asdf/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/bundler-2.6.9/lib/bundler.rb:167:in 'Bundler.setup'
16:43:38.534 from /opt/buildhome/.asdf/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/jekyll-4.4.1/lib/jekyll/plugin_manager.rb:52:in 'Jekyll::PluginManager.require_from_bundler'
16:43:38.535 from /opt/buildhome/.asdf/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/jekyll-4.4.1/exe/jekyll:11:in '<top (required)>'
16:43:38.535 from /opt/buildhome/.asdf/installs/ruby/3.4.4/bin/jekyll:25:in 'Kernel#load'
16:43:38.535 from /opt/buildhome/.asdf/installs/ruby/3.4.4/bin/jekyll:25:in '<main>'
16:43:38.543 Failed: Error while executing user command. Exited with error code: 1
16:43:38.553 Failed: build command exited with code: 1
16:43:39.582 Failed: error occurred while running build command
```
これは Gemfile.lock に development や test グループの gem が含まれている一方、Cloudflare Pages のビルド環境ではそれらがインストールされていないため。
対処内容
Cloudflare Pages の「ビルド環境変数(Environment Variables)」に以下を追加:
BUNDLE_WITHOUT=development test
これにより、bundle install 実行時に Gemfile 内の development と test グループの gem がインストールされなくなる。
成果
- 不要な gem に起因するビルドエラーが解消
jekyll buildが正常に実行され、ページがデプロイ完了
補足
- ローカルで
Gemfile.lockを一度削除し、再生成する必要がある(Cloudflareと同じ構成にするため) -
以下のコマンドを使用:
1 2 3
rm Gemfile.lock bundle lock --add-platform x86_64-linux bundle install --without development test
- 生成された
Gemfile.lockを git にコミット・プッシュして完了
結論
Cloudflare Pages において Jekyll を用いたビルドを成功させるには、本番ビルドで不要な gem グループ(development, test)を除外する設定が重要。BUNDLE_WITHOUT の環境変数で明示的に除外することで、安定したビルドが可能となった。
This post is licensed under
CC BY 4.0
by the author.