summary
Blog部署经历
status
Published
tags
建站
category
学习思考
date
Dec 29, 2021
slug
SthAboutSitDelpoy
icon
💡
兜兜转转,我还是回到了notion,此文做用作留念

之前看到了云游君做的Hexo主题,真的太好看了,简直戳我XP,所以整一个。
云游君的Hexo主题的说明文档:https://yun.yunyoujun.cn/

使用Docker配置Hexo环境

云游君提供了很详细的部署文档,以及docker部署的方法,但是在部署过程中还是遇到了一些问题,所以记录下来~

docker挂载单个文件出错

挂载主机的_config.yml文件到容器中时会报错,docker官方不建议挂载单个文件
ERROR: for cli  Cannot start service cli: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:o:76: mounting "/run/desktop/mnt/host/e/hexo/_config.yml" to rootfs at "/blog/_config.yml" caused: mount through procfd: not a directory: unknown: Are you trying to mount a directory onto f a file (or vice-versa)? Check if the specified host path exists and is the expected type
应该先在主机对应对目录中创建好相应的文件,然后再执行(曲线救国):
docker-compose build
docker-compose up -d

镜像中缺少hexo的git部署工具

在base镜像的run命令中补充npm install –save hexo-deployer-git

添加git用户信息

INFO  Validating config
INFO  Yun version 1.6.2. Guide: https://yun.yunyoujun.cn
INFO  Deploying: git
INFO  Clearing .deploy_git folder...
INFO  Copying files from public folder...
INFO  Copying files from extend dirs...

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'root@c165b5f2baca.(none)')
error: src refspec HEAD does not match any
error: failed to push some refs to 'https://github.com/RyuuYou0529/ryuuyou.github.io.git'
FATAL {
  err: Error: Spawn failed
      at ChildProcess.<anonymous> (/blog/node_modules/hexo-util/lib/spawn.js:51:21)
      at ChildProcess.emit (events.js:314:20)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12) {
    code: 1
  }
} Something's wrong. Maybe you can find the solution here: %s https://hexo.io/docs/troubleshooting.html
向第二阶段的镜像中添加自己的用户名和邮箱
git config --global user.email "example@123.com" \
git config --global user.name "shuai_ge"

在容器外部执行部署命令失败

INFO  Validating config
INFO  Yun version 1.6.2. Guide: https://yun.yunyoujun.cn
INFO  Deploying: git
INFO  Clearing .deploy_git folder...
INFO  Copying files from public folder...
INFO  Copying files from extend dirs...
On branch master
nothing to commit, working tree clean
fatal: could not read Username for 'https://github.com': No such device or address
FATAL {
  err: Error: Spawn failed
      at ChildProcess.<anonymous> (/blog/node_modules/hexo-util/lib/spawn.js:51:21)
      at ChildProcess.emit (events.js:314:20)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12) {
    code: 128
  }
} Something's wrong. Maybe you can find the solution here: %s https://hexo.io/docs/troubleshooting.html
进入容器内部执行 npx hexo d 命令
提示输入用户名和密码,结果又报错
INFO  Validating config
INFO  Yun version 1.6.2. Guide: https://yun.yunyoujun.cn
INFO  Deploying: git
INFO  Clearing .deploy_git folder...
INFO  Copying files from public folder...
INFO  Copying files from extend dirs...
On branch master
nothing to commit, working tree clean
Username for 'https://github.com': RyuuYou
Password for 'https://RyuuYou@github.com':
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/RyuuYou0529/ryuuyou.github.io.git/'
FATAL {
  err: Error: Spawn failed
      at ChildProcess.<anonymous> (/blog/node_modules/hexo-util/lib/spawn.js:51:21)
      at ChildProcess.emit (events.js:314:20)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12) {
    code: 128
  }
} Something's wrong. Maybe you can find the solution here: %s https://hexo.io/docs/troubleshooting.html
github要求使用token来访问仓库,所以先生成自己的token:https://github.com/settings/tokens
点击Generate new token,Note和Expiration自定,勾选repo,最后点击Generate token即可。
之后切记复制保存自己的token(后续无法查看)
将token代替密码进行验证。

每次执行github部署命令,如果缺少git用户信息,主机中不会有相关提示让我输入(构建镜像时配置好应该可以解决,但我不会),只是报错。
我不太懂docker容器中,git的配置信息是如何记录的,进入容器中输入一次用户名和token后,下次部署就还需要进去输入。
若以,如果不会将 _config.yml 文件公开,就可以将 _config.yml 文件中修改repo字段为:
repo:  https://<your_token>@github.com/<your_username>/<your_repo>.git
之后在主机中执行部署命令即可,不用每次进入容器内输了。。。

上面很多的坑,都是用一些妥协的办法解决的,毕竟实力不够啊 : (

换为本地Hexo环境

将Hexo博客部署到github page,每次都得生成静态页面后再发送到对应仓库,同时我还需要推送博客项目本身,好麻烦。。。
同时,把Hexo环境放在docker容器里用着很不爽,有些奇奇怪怪的问题,譬如:
  1. 使用 “docker exec hexo npx hexo s” 命令,并 CTRL+C 停止后,仍然存在4000端口被占用的问题
  1. github部署时,要么得把token附在配置文件里(我不喜欢),要没就得每次进入容器输账户和toke
  1. 我想要package.json等文件,但它们在容器内部,查看又不方便
  1. ……
因此,我想把博客部署到vercel,只需要将博客项目上传到github仓库,并导入到vercel,它就会自动部署。
问题又来了,原来的项目仓库中,并没有package.json等项目配置文件,因为它们都在dock儿容器内部,所以vercel部署时无法下载相关依赖,导致部署不成功。
最终我决定换为 本地Hexo环境+github托管+vercel部署(很顺利,没遇到什么坑,yes!)

Notion + NotionNext

使用Hexo部署静态博客,对我这种懒人来说还是太麻烦了,所以我开始考虑用notion作为CMS。
之前尝试过Nobeliumnextjs-notion-starter-kit,但在部署时都遇到了些奇奇怪怪的问题。
后来我看到了这篇文章:
https://nobelium-plum-nine.vercel.app/article/notion-next
然后我使用了这位大佬在Nobelium基础上开发的NotionNext,非常方便,主题也好看!
repo:https://github.com/tangly1024/NotionNext
暂时不折腾了......
环境配置2021Autumn-SE