之前一直使用Travis CI + Github Pages + Hexo + Cloudflare的方案托管博客,省心速度还将就。最近一段时间CF的443端口出现劣化现象,于是将博客重新迁移回腾讯云对象存储上了。并记录一下配置。
安装hexo-deployer-cos
在package.json下的dependencies中添加:
1
| "hexo-deployer-cos": "^1.0.0"
|
配置hexo-deployer-cos
在_config.yml中填写配置信息。由于配置文件会上传到github中,为了安全文件不保存SecretID和SecretKey。
1 2 3 4 5 6 7
| deploy: type: cos appId: 1234567890 secretId: SecretId secretKey: SecretKey bucket: iloft-1234567890 region: ap-shanghai
|
配置Travis-CI
在Travis-CI项目设置界面中配置环境变量。

修改.travis.yml,与只部署到Github Pages相比,增加了将SecretId与SecretKey替换成为预设的环境变量的sed命令和hexo d命令。完整的部署到COS和Github Pages配置文件:
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 30 31 32 33 34 35 36 37 38 39 40
| language: node_js node_js: stable cache: directories: - node_modules
install: - npm install
script: - sed -i "s/SecretId/${SecretId}/" _config.yml - sed -i "s/SecretKey/${SecretKey}/" _config.yml - hexo clean && hexo g && hexo d
after_script: - git clone https://${GH_REF} .deploy_git - cd .deploy_git - git checkout master - cd ../ - mv .deploy_git/.git/ ./public/ - cd ./public - git init - git config user.name "solyn" - git config user.email "[email protected]" - git add . - git commit -m ":memo:\ Update blog by CI" - git push --force --quiet "https://${CI_TOKEN}@${GH_REF}" master:gh-pages
branches: only: - master env: global: - GH_REF: github.com/myloft/blog
|