Featured image of post Cloudflare Pagesでいきなりデプロイできなくなった

Cloudflare Pagesでいきなりデプロイできなくなった

hugoでgithub actionsではビルドが通るのにcloudflare側でビルドがコケる

# はじめに

私のブログは現在Cloudflare Pagesでデプロイしているのですが、記事をおいているリポジトリにpushするタイミングでデプロイが走るように設定してあるのに、勝手にビルドがコケたという通知が飛んできていました。

その時の自分は記事を追加しているわけではないし、最後に成功したものがデプロイが継続されているならそれでいいやと無視していました。

# 結論

とりあえずroot直下にwlangler.tomlを作成してその中に

1
2
3
4
5
name = "my-pages-app"
pages_build_output_dir = "./public"
[vars]
CF_PAGES_URL=<your domain>
HUGO_VERSION="v0.124.1+extended"

こんな感じにconfigを書けば動く

# 問題が発生してしまった

先日こんなエラーが出ていました。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
10:08:52.347	Cloning repository...
10:08:53.456	From https://github.com/WhatACotton/myblog
10:08:53.457	 * branch            37d6b4194bd6307ffd880b0720a353b843c221b5 -> FETCH_HEAD
10:08:53.457	
10:08:53.510	HEAD is now at 37d6b41 CI: Update theme
10:08:53.538	
10:08:53.633	
10:08:53.633	Using v2 root directory strategy
10:08:53.657	Success: Finished cloning repository files
10:08:54.933	Detected the following tools from environment: hugo@extended_0.121.1
10:08:54.934	Installing hugo extended_0.121.1
10:08:55.061	* Downloading hugo release extended_0.121.1...
10:08:56.759	hugo extended_0.121.1 installation was successful!
10:08:57.153	Executing user command: cd myblog;hugo -b $CF_PAGES_URL
10:08:57.158	/bin/sh: 1: cd: can't cd to myblog
10:08:58.991	hugo: collected modules in 1566 ms
10:08:58.992	Start building sites … 
10:08:58.992	hugo v0.121.1-00b46fed8e47f7bb0a85d7cfc2d9f1356379b740+extended linux/amd64 BuildDate=2023-12-08T08:47:45Z VendorInfo=gohugoio
10:08:58.992	
10:09:03.534	ERROR render of "home" failed: "/opt/buildhome/.cache/hugo_cache/modules/filecache/modules/pkg/mod/github.com/!cai!jimmy/hugo-theme-stack/[email protected]/layouts/_default/baseof.html:4:12": execute of template failed: template: index.html:4:12: executing "index.html" at <partial "head/head.html" .>: error calling partial: "/opt/buildhome/.cache/hugo_cache/modules/filecache/modules/pkg/mod/github.com/!cai!jimmy/hugo-theme-stack/[email protected]/layouts/partials/head/head.html:15:4": execute of template failed: template: partials/head/head.html:15:4: executing "partials/head/head.html" at <partial "head/opengraph/include.html" .>: error calling partial: "/opt/buildhome/.cache/hugo_cache/modules/filecache/modules/pkg/mod/github.com/!cai!jimmy/hugo-theme-stack/[email protected]/layouts/partials/head/opengraph/include.html:1:3": execute of template failed: template: partials/head/opengraph/include.html:1:3: executing "partials/head/opengraph/include.html" at <partial "head/opengraph/provider/base" .>: error calling partial: "/opt/buildhome/.cache/hugo_cache/modules/filecache/modules/pkg/mod/github.com/!cai!jimmy/hugo-theme-stack/[email protected]/layouts/partials/head/opengraph/provider/base.html:35:20": execute of template failed: template: partials/head/opengraph/provider/base.html:35:20: executing "partials/head/opengraph/provider/base.html" at <.Site.Lastmod.IsZero>: can't evaluate field Lastmod in type page.Site
10:09:03.535	ERROR render of "section" failed: "/opt/buildhome/.cache/hugo_cache/modules/filecache/modules/pkg/mod/github.com/!cai!jimmy/hugo-theme-stack/[email protected]/layouts/_default/baseof.html:4:12": execute of template failed: template: _default/list.html:4:12: executing "_default/list.html" at <partial "head/head.html" .>: error calling partial: "/opt/buildhome/.cache/hugo_cache/modules/filecache/modules/pkg/mod/github.com/!cai!jimmy/hugo-theme-stack/[email protected]/layouts/partials/head/head.html:15:4": execute of template failed: template: partials/head/head.html:15:4: executing "partials/head/head.html" at <partial "head/opengraph/include.html" .>: error calling partial: "/opt/buildhome/.cache/hugo_cache/modules/filecache/modules/pkg/mod/github.com/!cai!jimmy/hugo-theme-stack/[email protected]/layouts/partials/head/opengraph/include.html:1:3": execute of template failed: template: partials/head/opengraph/include.html:1:3: executing "partials/head/opengraph/include.html" at <partial "head/opengraph/provider/base" .>: error calling partial: "/opt/buildhome/.cache/hugo_cache/modules/filecache/modules/pkg/mod/github.com/!cai!jimmy/hugo-theme-stack/[email protected]/layouts/partials/head/opengraph/provider/base.html:35:20": execute of template failed: template: partials/head/opengraph/provider/base.html:35:20: executing "partials/head/opengraph/provider/base.html" at <.Site.Lastmod.IsZero>: can't evaluate field Lastmod in type page.Site
10:09:03.535	ERROR render of "taxonomy" failed: "/opt/buildhome/.cache/hugo_cache/modules/filecache/modules/pkg/mod/github.com/!cai!jimmy/hugo-theme-stack/[email protected]/layouts/_default/baseof.html:4:12": execute of template failed: template: _default/list.html:4:12: executing "_default/list.html" at <partial "head/head.html" .>: error calling partial: "/opt/buildhome/.cache/hugo_cache/modules/filecache/modules/pkg/mod/github.com/!cai!jimmy/hugo-theme-stack/[email protected]/layouts/partials/head/head.html:15:4": execute of template failed: template: partials/head/head.html:15:4: executing "partials/head/head.html" at <partial "head/opengraph/include.html" .>: error calling partial: "/opt/buildhome/.cache/hugo_cache/modules/filecache/modules/pkg/mod/github.com/!cai!jimmy/hugo-theme-stack/[email protected]/layouts/partials/head/opengraph/include.html:1:3": execute of template failed: template: partials/head/opengraph/include.html:1:3: executing "partials/head/opengraph/include.html" at <partial "head/opengraph/provider/base" .>: error calling partial: "/opt/buildhome/.cache/hugo_cache/modules/filecache/modules/pkg/mod/github.com/!cai!jimmy/hugo-theme-stack/[email protected]/layouts/partials/head/opengraph/provider/base.html:35:20": execute of template failed: template: partials/head/opengraph/provider/base.html:35:20: executing "partials/head/opengraph/provider/base.html" at <.Site.Lastmod.IsZero>: can't evaluate field Lastmod in type page.Site
10:09:03.535	Total in 6112 ms
10:09:03.535	Error: error building site: render: failed to render pages: render of "home" failed: "/opt/buildhome/.cache/hugo_cache/modules/filecache/modules/pkg/mod/github.com/!cai!jimmy/hugo-theme-stack/[email protected]/layouts/_default/baseof.html:4:12": execute of template failed: template: index.html:4:12: executing "index.html" at <partial "head/head.html" .>: error calling partial: "/opt/buildhome/.cache/hugo_cache/modules/filecache/modules/pkg/mod/github.com/!cai!jimmy/hugo-theme-stack/[email protected]/layouts/partials/head/head.html:15:4": execute of template failed: template: partials/head/head.html:15:4: executing "partials/head/head.html" at <partial "head/opengraph/include.html" .>: error calling partial: "/opt/buildhome/.cache/hugo_cache/modules/filecache/modules/pkg/mod/github.com/!cai!jimmy/hugo-theme-stack/[email protected]/layouts/partials/head/opengraph/include.html:1:3": execute of template failed: template: partials/head/opengraph/include.html:1:3: executing "partials/head/opengraph/include.html" at <partial "head/opengraph/provider/base" .>: error calling partial: "/opt/buildhome/.cache/hugo_cache/modules/filecache/modules/pkg/mod/github.com/!cai!jimmy/hugo-theme-stack/[email protected]/layouts/partials/head/opengraph/provider/base.html:35:20": execute of template failed: template: partials/head/opengraph/provider/base.html:35:20: executing "partials/head/opengraph/provider/base.html" at <.Site.Lastmod.IsZero>: can't evaluate field Lastmod in type page.Site
10:09:03.544	Failed: Error while executing user command. Exited with error code: 1
10:09:03.556	Failed: build command exited with code: 1
10:09:04.862	Failed: error occurred while running build command

どうやらテーマアップデートが自動で走ったときにコケたらしいですね。

1
2
10:08:57.153	Executing user command: cd myblog;hugo -b $CF_PAGES_URL
10:08:57.158	/bin/sh: 1: cd: can't cd to myblog

ここでcdできていないようです。どうやら仕様が変わったらしい…?

cdできていないだけなら別に問題ないはずで、本質はhugoのビルドにコケていることの気がしてきました。

ココらへんを確認するとバージョン指定やconfigの問題ということがわかってきました。

とりあえず記事を追加してビルドを走らせてみるとこうなりました

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
13:31:12.565	Cloning repository...
13:31:13.605	From https://github.com/WhatACotton/myblog
13:31:13.605	 * branch            1ab836c6188ccd759e303a10f2d836a4f09c0a24 -> FETCH_HEAD
13:31:13.605	
13:31:13.660	HEAD is now at 1ab836c Merge pull request #11 from WhatACotton/add/article
13:31:13.661	
13:31:13.743	
13:31:13.744	Using v2 root directory strategy
13:31:13.770	Success: Finished cloning repository files
13:31:15.361	
13:31:15.448	✘ [ERROR] No Pages config file found
13:31:15.448	
13:31:15.448	
13:31:15.452	🪵  Logs were written to "/root/.config/.wrangler/logs/wrangler-2024-04-10_04-31-15_190.log"
13:31:15.463	No wrangler.toml file found
13:31:16.072	Detected the following tools from environment: hugo@extended_0.121.1
13:31:16.073	Installing hugo extended_0.121.1
13:31:16.201	* Downloading hugo release extended_0.121.1...
13:31:17.823	hugo extended_0.121.1 installation was successful!
13:31:18.198	Executing user command: cd myblog;hugo -b $CF_PAGES_URL
13:31:18.202	/bin/sh: 1: cd: can't cd to myblog
13:31:19.936	hugo: collected modules in 1463 ms
13:31:19.937	Start building sites … 
13:31:19.937	hugo v0.121.1-00b46fed8e47f7bb0a85d7cfc2d9f1356379b740+extended linux/amd64 BuildDate=2023-12-08T08:47:45Z VendorInfo=gohugoio
13:31:19.938	
13:31:24.470	ERROR render of "home" ...
13:31:24.479	Failed: Error while executing user command. Exited with error code: 1
13:31:24.490	Failed: build command exited with code: 1
13:31:25.486	Failed: error occurred while running build command

configファイルがないと怒られているようです。よく見るとhugoのバージョンが指定したものになっていませんでした。

1
2
13:31:19.937	Start building sites … 
13:31:19.937	hugo v0.121.1-00b46fed8e47f7bb0a85d7cfc2d9f1356379b740+extended linux/amd64 BuildDate=2023-12-08T08:47:45Z VendorInfo=gohugoio	

config

公式Docsに、ないと言われていたwrangler.tomlの書き方が書いてありました。

example web上で設定した環境変数が読めていないようだったので、とりあえずroot直下にconfigを書いてみました。
ビルドコマンドはhugo -b $CF_PAGES_URLに修正しておきました。

wrangler.toml

1
2
3
4
5
name = "my-pages-app"
pages_build_output_dir = "./public"
[vars]
CF_PAGES_URL="https://blog.whatacotton.com"
HUGO_VERSION="v0.124.1+extended"

とりあえずこれで解決しました!!! status

# 終わりに

いきなり仕様が変わったみたいでかなり困惑したところはありましたが、なんとか解決できたので良かったです。
しかし、webUIで設定した環境変数が呼ばれないのはあまり納得できないので、なにか知ってる人はtwitterなどで教えてほしいです…

comments powered by Disqus
Hugo で構築されています。
テーマ StackJimmy によって設計されています。