使用 Travis CI 自动部署 Hexo 博客,同时上传至又拍云。
前几天使用 Travis CI 自动构建 Hexo 博客并且上传至 Github 和 Coding,就在想能不能同时上传至 又拍云。
今天晚上使用 ftp 上传至又拍云,网站实现全站 CDN 加速。
前面发现是有工具可以直接上传至又拍云:
但是这个工具在 Windows 系统下使用有问题,并且我已经使用 Travis CI 自动部署了,继续使用这个工具有令牌暴露的风险。
所以就想使用 ftp 上传至又拍云,然后就发现了这个工具:
Git-ftp -- uploads to FTP servers the Git way
在 linux 下的安装方法:
git clone https://github.com/git-ftp/git-ftp.git
cd git-ftp
# choose the newest release
tag="$(git tag | grep '^[0-9]*\.[0-9]*\.[0-9]*$' | tail -1)"
# checkout the latest tag
git checkout "$tag"
sudo make install
配置 git-ftp :
git config git-ftp.url "ftp://ftp.example.net:21/public_html"
git config git-ftp.user "ftp-user"
git config git-ftp.password "secr3t"
第一次上传执行:
git ftp init
后面上传执行,只会上传变化的部分:
git ftp push
使用方法也很简单,下面就默认在原来 Travis CI 自动部署 的基础上:
在 .travis.yml
文件中修改:
install:
- npm install
- git clone https://github.com/git-ftp/git-ftp.git
- cd git-ftp
- tag="$(git tag | grep '^[0-9]*\.[0-9]*\.[0-9]*$' | tail -1)"
- git checkout "$tag"
- sudo make install
- cd ..
在 publish-to-gh-pages.sh
中修改
# git-ftp 上传至 upyun
git config git-ftp.url "ftp://v0.ftp.upyun.com:21/"
git config git-ftp.user "${UPYUN_USE}"
git config git-ftp.password "${UPYUN_PSD}"
git ftp init
# git ftp push
第一次上传之后,修改 publish-to-gh-pages.sh
文件
# git-ftp 上传至 upyun
git config git-ftp.url "ftp://v0.ftp.upyun.com:21/"
git config git-ftp.user "${UPYUN_USE}"
git config git-ftp.password "${UPYUN_PSD}"
# git ftp init
git ftp push -v
其中 UPYUN_USE 和 UPYUN_PSD 是在 Travis 中配置的 UPYUN ftp 用户名密码。
具体值可参考:https://docs.upyun.com/api/developer_tools/
其实有点弊端就是上传之后更新具有一定的延迟性,但是速度快很多。
参考资料
1、travis-ci-deploy-ftp
https://github.com/ansediao/travis-ci-deploy-ftp
2、How to use git-ftp: 使用 git-ftp 管理你的 FTP
https://medium.com/@awonwon/how-to-use-git-ftp-使用-git-ftp-管理你的-ftp-1864700c6eb9
3、使用 git-ftp 将 git 两次提交发生变化的文件上传到服务器
http://www.sunzhongwei.com/use-the-git-ftp-to-upload-git-diff-files-to-the-server
评论 (0)