原文链接

—— 以webpack文档部署为例子

Overview

Some friends and I have been running webpack-china for a few months.
After a few months effort, most doc translation job have also been done. We keep tracking the master and you will see Chinese version does not lag behind too much.

pretty much the same and http2 is also applied

However it has been a while that we need to manually deploy the site. With the help of Travis-Ci and Github webhook, we finally make it an auto process.

Travis-CI is used for building your code that you need to publish and push them to your gh-pages branch. Github webhook then takes over the job and sends a request to your hosting server. When your server gets the request, it would run a script to pull the latest code from gh-page. The site then finish all the updating steps.

Sample process

Travis-CI

Here I will use webpack-china/webpack.js.org as an example. The repository is forked from webpack/webpack.js.org. But we have to modify it a bit.

.travis.yml

This file is the configuration for Travis-CI. Not much difference from other project, branches means which branches will be watched by Travis-Ci. Node.js is used as the major programing language. Node 6.0 environment will be set up. The most important file should be deploy.sh. This file contains the commands used for deployment.

1st part of deploy.sh

The 1st part of deploy.sh script is used for building the site. Ready releasing code will be put under build folder when you run

npm run build复制代码
2nd part of deploy.sh

The 2nd part of the script is aiming for pushing code to gh-pages branch. But how does Travis-CI know get the permission to access your repo?
SSH Key does the trick for you. Please follow this guide, Generating a new SSH key to generate SSH Key. (Please do it under your local repository folder)

example code:

ssh-keygen -t rsa -b 4096 -C ci@travis-ci.orgEnter file in which to save the key (/var/root/.ssh/id_rsa): deploy_key复制代码

When you are asked to enter passphrase, please type enter to skip.

Enter passphrase (empty for no passphrase):复制代码

Then open deploy_key.pub and copy whole file content. Add that deploy key to your repository at https://github.com/<your name>/<your repo>/settings/keys.

deploy keys in github

Next, install travis client tool to upload SSH Key information to the Travis-CI.

After installation, run

travis encrypt-file deploy_key复制代码
travis encrypt-file result

Add the script to deploy.sh under scripts folder and also add deploy_key.enc to scripts folder. Append scripts/ to delopy_key and deploy_key in this script as follows,

openssl aes-256-cbc -K $encrypted_7562052d3e34_key -iv $encrypted_7562052d3e34_iv -in scripts/deploy_key.enc -out scripts/deploy_key -d复制代码

Please do not to upload deploy_key.pub.

If it prompts login info, try

travis login复制代码

Then you can push everything to the repository and Travis-CI will build and push things for you.
One more thing to note is that npm run deploy in deploy.sh is used here which use gh-pages library to push code to gh-pages.

GitHub Webhook

1st part Github Webhook
2nd part of Github Webhook

Add a webhook in your project (1st part of Github Webhook) and you can specify when Github will send the request (2nd part of Github Webhook).

app to receive Github Webhook Request

Then you need to deploy a small app (pm2 is recommended to persist the app process) to respond to Github Webhook.

codePath is the path where accommodate production code from gh-pages branch.

updateCommand,

cd ${codePath};sudo git fetch — all;sudo git reset — hard origin/gh-pages;复制代码

is to fetch all stuff from gh-pages branch and only show the latest record.
Don’t forget to configure your nginx/apache to serve your static files in codePath.

Reference

Auto-deploying built products to gh-pages with Travis

使用Travis-CI 与 Github Webhook自动部署你的页面相关推荐

  1. travis ci_如何使用Travis CI和GitHub进行Web开发工作流程

    travis ci by Vijayabharathi Balasubramanian 通过Vijayabharathi Balasubramanian 如何使用Travis CI和GitHub进行W ...

  2. 用GitHub Actions自动部署Hexo

    本文不算原创,是根据参考文档结合自己的需要修改而成,但也非转载和翻译. 老苏一直用 hexo 发博文,发布过程经历了 三个阶段 第一阶段 : 在家里的台式机上发布 hexo ,流程是先把要发布博文的 ...

  3. 开箱即用,Hexo博客的github+server自动部署

    用了一段时间HEXO搭建个人的博客,但每次发布文章,都需要打开电脑hexo g编译之后,再提交到服务器上,确实挺麻烦的,和小伙伴聊完他的日志发布方式之后,痛定思痛,快捷发布日志这个问题需要解决一下了! ...

  4. 搭建Jenkins+Github的自动部署环境并使用守护进程(Supervisor)部署Golang(gin)项目

    零.前言 Jenkins是一个自动部署的平台,可以极大的帮助我们自动部署项目,把注意力放在书写代码上. 教程环境说明: 系统:ubuntu20 配置:2核4G 软件:JAVA11 安装方式:APT(不 ...

  5. 【github 自动部署】github实现自动部署

    由于业务的需求,我需要将每次写好的代码编译好后,并且通过ftp工具远程传到服务器上. 但是,这样的操作带来的问题是:整个的过程变得相当的复杂. 于是,就有了这篇文章. 我们可以这样理解: 当我们把代码 ...

  6. 使用Github Actions自动部署vue项目到nginx服务器

    解决的问题:妈妈再也不担心我deploy时候手滑了 1. 避免手动执行重复的前端发布流程,节约开发时间和耐心 2. 减少了使用Jenkins类似的工具来做这种简单的发布流程,减少了第三方系统(Jenk ...

  7. Springboot 项目通过 gitlab CI/CD 集成 k8s 自动部署

    本章节主要讲的是 springboot 项目发到 gitlab 仓库,触发 gitlab ci/cd 实现项目自动集成和部署,其中部署是以 k8s 方式部署 关于 gitlab-runner 安装和注 ...

  8. 5 分钟教你快速掌握 GitHub Actions 自动部署博客

    自从 GitHub 宣布 GitHub Actions 在平台上对所有开发人员和存储库可用以来,GitHub Actions 越来越受欢迎.很多第三方平台在生态系统中有速度等限制,将进一步推动开发人员 ...

  9. 统计gitlab代码行脚本_一点也不复杂, GitLab Webhook 自动部署代码

    项目使用了gitlab托管,以前部署代码都是登录服务器,然后git pull代码.这样每次需要发布代码,都需要登录,太繁琐.很早就了解到 gitlab支持 webhook,能够自动同步代码.今天尝试搭 ...

最新文章

  1. 7个你可能不认识的CSS单位
  2. phpstrom 代码格式
  3. 【双百解法】剑指 Offer 11. 旋转数组的最小数字
  4. CRM和C4C里的组织架构 - Organizational Structure
  5. 字符串_字符串数组_字符_字符数组
  6. delphi random 六位_《蒙面唱将猜猜猜》第五季将播,六位唱将率先登场
  7. 如何在eclipse调试mapreduce程序
  8. c语言 指针函数pdf,C语言指针经验总结(经典).pdf
  9. .NET: 如何在宿主中动态加载所有的服务
  10. java框架常见面试题_java框架面试题总结
  11. JTAG Bypass命令案例解析
  12. HFS远程命令执行漏洞入侵抓鸡黑阔服务器
  13. iptables: No config file解决方法
  14. mysql查询连续记录
  15. matlab概率论与数理统计分析,MATLAB在概率论与数理统计课程中的案例设计
  16. java飞机_使用java写出飞机小游戏
  17. 扫码支付 (基于微信)
  18. python直角坐标转极坐标_Python在OpenCV里实现极坐标变换功能
  19. 个人碰到的前端问题总结及解决方法1
  20. java 电商锁库存实现_电商项目扣减库存方案

热门文章

  1. 51单片机led灯闪烁程序C语言,51单片机控制led灯闪烁程序
  2. java poi修改word2007_java poi 替换word2007中的指定文本
  3. 20200421:周赛练习题(leetcode148周周赛上)
  4. preg_replace在java中_Java相当于PHP的preg_replace_callback
  5. html5中点击后不发生变化_魔道祖师中资深粉一看就明白的梗,路人见到后都反应不过来...
  6. java.util.zip 用法,Java压缩文件工具类ZipUtil使用方法代码示例
  7. 对Redis单线程的一些看法
  8. 瑞士科学家造出了撞不坏的无人机丨Science Robitics
  9. Facebook秘密文件泄露:赚钱(和背锅)是AI的使命
  10. Task10.Bert