自动化部署 Jekyll(Automated Deployment)
有很多方式可以让你轻松简单地自动化部署 Jekyll 网站。
持续集成服务Permalink
使用持续集成服务是自动化部署流程的比较的简单方式。
当你在你的 Git 仓库上提交代码时这些服务会运行一个脚本。然后持续集成服务的脚本自动化构建网站、对输出进行测试,然后将网站部署到你设定的服务(服务器)上。
以下是推荐的常见的持续集成服务服务商,点击链接查看对应的教程:
Git 接收 hook 后Permalink
如果想让远程服务器在你每次使用 Git 推送更改时自动处理部署,可以创建一个用户账户,并在 authorized_keys
文件中包含所有被授权进行部署的公钥。设置接收 hook 后的步骤如下:
laptop$ ssh deployer@example.com
server$ mkdir myrepo.git
server$ cd myrepo.git
server$ git --bare init
server$ cp hooks/post-receive.sample hooks/post-receive
server$ mkdir /var/www/myrepo
然后将以下内容添加到 hooks/post-receive
文件中(确保服务器上已安装 Jekyll):
#!/bin/bash -l
# Install Ruby Gems to ~/gems
export GEM_HOME=$HOME/gems
export PATH=$GEM_HOME/bin:$PATH
TMP_GIT_CLONE=$HOME/tmp/myrepo
GEMFILE=$TMP_GIT_CLONE/Gemfile
PUBLIC_WWW=/var/www/myrepo
git clone $GIT_DIR $TMP_GIT_CLONE
BUNDLE_GEMFILE=$GEMFILE bundle install
BUNDLE_GEMFILE=$GEMFILE bundle exec jekyll build -s $TMP_GIT_CLONE -d $PUBLIC_WWW
rm -Rf $TMP_GIT_CLONE
exit
最后,在任何需要使用此 hook 进行部署的电脑上运行以下命令:
laptops$ git remote add deploy deployer@example.com:~/myrepo.git
现在,部署变得非常简单。
只需要让 nginx 或 Apache 服务器指向 /var/www/myrepo
目录,然后运行以下命令:
laptops$ git push deploy master