<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/css" href="/css/feed.min.862ab8f8bb15f1f3203a5b9e6a474b6fcd7e7137c22209e346175b0856acfd97.css"?><rss data-theme="dark" data-theme-default="dark" version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:h="http://www.w3.org/1999/xhtml"><channel><title>CI/CD · atman · ihx.cc | AirPlan - A biger solution</title><link>https://atman.ihx.cc/tags/ci/cd/</link><description>君子不器，日日自新。一處關於技術、生活與自我探索的行記。</description><language>zh-CN</language><generator>Hugo</generator><copyright>DataBase - Atman as @man</copyright><lastBuildDate>Wed, 08 Jan 2020 00:00:00 +0800</lastBuildDate><atom:link href="https://atman.ihx.cc/tags/ci/cd/index.xml" rel="self" type="application/rss+xml"/><h:script src="/js/theme.min.e9b6d7597dde98fbf1181117d7e72cec3c16ab35de5b3f3bdb17dbd866e0c62c.js" type="text/javascript" defer="defer"/><h:header class="feed-header"><h:nav><h:a href="https://atman.ihx.cc/">首页</h:a><h:a href="https://atman.ihx.cc/archive/">Archive</h:a><h:button id="theme-toggle" class="feed-theme-toggle" type="button" aria-label="暗色模式" aria-pressed="true" title="切换亮暗风格">亮 / 暗</h:button></h:nav><h:p class="feed-eyebrow">RSS / 全文订阅</h:p><h:h1>CI/CD · atman · ihx.cc | AirPlan - A biger solution</h:h1><h:p>将下面的地址粘贴到 RSS 阅读器，即可订阅更新。这里展示最近 1 篇文章的摘要，阅读器中可阅读文章全文。</h:p><h:a class="feed-address" href="https://atman.ihx.cc/tags/ci/cd/index.xml">https://atman.ihx.cc/tags/ci/cd/index.xml</h:a><h:p class="feed-note">包含 post 和 look 中的文章 · 按发布时间倒序</h:p></h:header><item><title>生态围墙 - Github Actions &amp; Hugo</title><link>https://atman.ihx.cc/post/20200108-2-github-hugo-actions/</link><guid isPermaLink="true">https://atman.ihx.cc/post/20200108-2-github-hugo-actions/</guid><pubDate>Wed, 08 Jan 2020 00:00:00 +0800</pubDate><dc:creator>Atman</dc:creator><category>Hugo</category><category>GitHub Actions</category><category>CI/CD</category><description>0x00 上帝说有光 目标：持续 tidb.cc 域名的运转 初衷：让更多的人了解 xxxx 产品 内核：提升自身技能以及建立良性记录 动力：装逼 助力 OKR、分享与讨论技术的真实性、考核自身对产拼的理解能力、管控自身 GTD 走上选型之路，从 wordpress、typecho 等 PHP 网站程序到后面静态网页生成工具 hexo、hugo 等；综合审判 …</description><content:encoded><![CDATA[<h2 id="0x00-上帝说有光">0x00 上帝说有光</h2>
<p>目标：<del>持续</del> tidb.cc 域名的运转<br>
初衷：<del>让更多的人了解 xxxx 产品</del><br>
内核：<del>提升自身技能以及建立良性记录</del><br>
动力：装逼 <del>助力 OKR、分享与讨论技术的真实性、考核自身对产拼的理解能力、管控自身 GTD</del></p>
<p>走上选型之路，从 wordpress、typecho 等 PHP 网站程序到后面静态网页生成工具 hexo、hugo 等；综合审判实力以及时间等因素，静态网页 &amp; Gitpage 更适合比较懒的我(懒是第一源动力)，依靠 Github 力量充分的免去各种劳动力与精力。<br>
然 hugo 与 hexo 需要多个过程与步骤才能让不明观众完成阅读文档的动作，这个上帝说需要优化，否则他就不干了…… 为了节省人力与时间，不要试图锻炼和测试上帝的耐心到底有多强。</p>
<h2 id="0x01-挖掘-hugo">0x01 挖掘 Hugo</h2>
<p>Hugo 、Hexo &amp; Wordpress、typecho 的对比过程，此处省略 10000 个字；直接跳到 Hugo 程序介绍与测试</p>
<p>Hugo 是一款 Go 写的静态网站生成工具，可以将标准的 markdown 文本内容结合 HTML + CSS 网页生成一套静态网站。静态的网站好处都有啥，万能的金坷垃网上自己查……<br>
Hugo：<code>https://gohugo.io/</code> &amp; <code>https://github.com/gohugoio/hugo</code> 一切从这开始</p>
<p>duck duck 一阵过后，查到海量关于 Github Actions 、Hugo 、Github Pages 的文档，以下开始逐步折腾：保障办公电脑环境的前提，找了一台  Linux 机器作为本次测试机，以下步骤以 Linux 机器为主</p>
<table>
<thead>
<tr>
<th>步骤</th>
<th>动作</th>
</tr>
</thead>
<tbody>
<tr>
<td>安装部署</td>
<td><code>https://github.com/gohugoio/hugo/releases</code> 下载响应系统安装包 / hugo_extended 扩展版需要较高的 Gcc 版本支持</td>
</tr>
<tr>
<td>&mdash;</td>
<td>解压下载包，将目录内 hugo 程序复制一份到 /usr/bin 目录下，此时可在系统内直接执行 hugo 命令</td>
</tr>
<tr>
<td>初始化网站</td>
<td>hugo new site ske</td>
</tr>
<tr>
<td>寻找 theme</td>
<td>从这里下载 <code>https://themes.gohugo.io/</code> ; 将主题包解压后放置在 ske/themes 目录下</td>
</tr>
<tr>
<td>&mdash;</td>
<td>注意将主题目录下 exampleSite/config.toml 复制并替换 /opt/ske/config.toml ，并修改 config.toml 中的 baseurl 信息</td>
</tr>
<tr>
<td>新建文档</td>
<td>hugo new posts/one.md   hugo new page/about.md ； 以上动作会在 ske/content 目录下自动生成内容</td>
</tr>
<tr>
<td>&mdash;</td>
<td>注意！如果使用相对路径引用 /opt/ske 图片、视频等文件，注意查看引用后是否正常</td>
</tr>
<tr>
<td>查看网站</td>
<td>hugo -s -D ; -s 后提示查看 localhost:1313 网站，-D 可以将 “daft 草稿” 内容也生成网页；在 one.md 文档头部有 daft:true 代表是草稿文档</td>
</tr>
<tr>
<td>部署 Nginx</td>
<td>hugo -s 适合本地修改 themes 或者学习使用；如果长期运行网站需要一个 HTML 解析编译工具。如 Nginx、Apache、IIS 三大主流引擎；centos 系统默认使用 yum install nginx 安装</td>
</tr>
<tr>
<td>调整 nginx.conf</td>
<td>调整 80 端口网站目录为 /opt/ske/public （此处注意 nginx 运行用户与网站目录权限，否则网站访问 403） ； hugo 生成后的静态网页都在这里</td>
</tr>
<tr>
<td>生成静态</td>
<td>在 /opt/ske 目录下执行 hugo 命令，生成静态网站</td>
</tr>
<tr>
<td>访问网站</td>
<td>在防火墙关闭 &amp; 端口无限制的情况下，访问 IP:port 或者 IP/dir</td>
</tr>
</tbody>
</table>
<p>以上整个过程，除 hugo 新建文档步骤，Github 上有 Dockerfile 以及 docker hub 上有完整的 Docker image 镜像；可以自行搜索下</p>
<h2 id="0x02-堆砌">0x02 堆砌</h2>
<p>上面的步骤是如此的复杂，当上帝耗费了很大精力制造完光，限制需要将光共享给大众的时候还有那么多的流程和步骤，而这些都是重复的内容 &ndash; 因此我们需要解放上帝的劳动力。简略分析上述步骤：</p>
<p>hugo 程序需要以下多个步骤帮助 Markdown 文档生成 Html 静态网站，然后 deploy 至目标仓库。</p>
<ul>
<li>命令行
<ul>
<li>hugo new site</li>
<li>hugo new posts/one.md</li>
<li>hugo -D</li>
<li>hugo deploy</li>
</ul>
</li>
</ul>
<p>把以上步骤通过打包整合使用 Travis CI 、Jenkins 等工具或者 Github Actions 工具，整个流水线调通后就是 <strong>持续集成（Continuous integration）</strong> ；后续需要针对不同环境迭代发布各种版本交付生产线需要叠加另一套方法流 <strong>持续交付（Continuous delivery）</strong></p>
<p>那么我们需要研究下对比下以上几款 CI 工具；对比过程省略几十上百字，背靠大树好乘凉直接无脑选择 Github Actions（主要是一人家人还是免费用，配置长度上比 jenkins、travis 要简单）</p>
<blockquote>
<p>引用官方 Github 对于 Actions 的部分信息 / 围观下该功能是否收费<br>
There are some limits on GitHub Actions usage. <a href="https://help.github.com/en/actions/automating-your-workflow-with-github-actions/about-github-actions#usage-limits">Unless specified</a><br>
GitHub Actions usage is <a href="https://help.github.com/en/github/setting-up-and-managing-billing-and-payments-on-github/about-billing-for-github-actions#about-billing-for-github-actions">free for public</a> repositories.<br>
<img src="https://atman.ihx.cc/post/20200108-2-github-hugo-actions/github-actions.jpg" alt="Github Actions" loading="lazy" decoding="async">
</p>
</blockquote>
<h2 id="0x03-扇风-github">0x03 扇风 Github</h2>
<blockquote>
<p><code>https://github.com/marketplace</code> 是 Github 的一个 Github repo APP 市场，各位高能开发者针对 Github repo 做了一系列小工具整合成了一个产品平台<br>
github actions 功能介绍直接看这篇 <strong>阮一峰 &ndash; <a href="http://www.ruanyifeng.com/blog/2019/09/getting-started-with-github-actions.html" title="外部引用 ｜ Docs.tidb.cc &amp; Github Actions Hugo">Github Actions 入门教程</a></strong><br>
本次用到两个 Actions App ，第一个是 <a href="https://github.com/marketplace/actions/github-pages-action">github-pages-action</a>，协助我们生成；第二个是 <a href="https://github.com/marketplace/actions/hugo-setup">hugo-setup</a>，在 github-pages-action 外面打包了一层 Hugo 生成网页的步骤。</p>
</blockquote>
<p>结合生成以下 actions.yml 文件内容：</p>
<pre><code class="language-yaml" data-lang="yaml">name: github pages

on:
  push:
    branches:
    - master  // 该位置不是用于监听 master 分支接收到 push 操作后执行以下内容。
              // 而是当前分支收到 push 操作后，去对 master 分支做 jobs 操作

jobs:  // actions 在上述分支遇见 push 操作后，执行 jobs 内的动作
  build-deploy:
    runs-on: ubuntu-18.04
    steps:
    - uses: actions/checkout@v1
      # with:
      #   submodules: true

    - name: Hugo setup
      uses: peaceiris/actions-hugo@v2.3.2
      with:
        hugo-version: &#39;latest&#39;
        extended: true

    - name: Build
      run: hugo -D  // hugo 命令，用于生成静态文件， -D 将草稿也生成文档

    - name: Deploy  // 引用 github-pages 将数据推送到当前 repo gh-pages 分支
      uses: peaceiris/actions-gh-pages@v2
      env:
        ACTIONS_DEPLOY_KEY: ${{ secrets.si }}  // 注意此处 secrets.si 声明 ssh-key 信息，si 是自定义变量名，取决于在 repo-setting-secrers 中的配置信息
        PUBLISH_BRANCH: gh-pages
        PUBLISH_DIR: ./public  //推送 hugo/public 目录下的数据到远程 repo gh-pages 分支
</code></pre><h2 id="0x04-点火">0x04 点火</h2>
<p>降低 master commit 那难看的记录，使用到了三个分支，master、draft、gh-pages，分别是 master 放置不用、draft 放 hugo 程序和 content/markdown 文档、gh-pages 放静态网页内容<br>
不断向 draft 提交文档，然后触发 gh-pages 自动更新，期间遇见的问题请向下滚动屏幕</p>
<h2 id="0x05-faq">0x05 FAQ</h2>
<h3 id="gcc-版本">Gcc 版本</h3>
<p>在低版本 Linux 内核运行 hugo 会提示 gcc 版本过低</p>
<pre><code class="language-bash" data-lang="bash">[root@Jeff-VM1 hugo]# ./hugo -V
./hugo: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20&#39; not found (required by ./hugo)
./hugo: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21&#39; not found (required by ./hugo)
</code></pre><p>该 Liunx 内核版本执行正常，使用的 ubuntu 18 版本</p>
<pre><code class="language-bash" data-lang="bash">[root@fresh-frog-3 ~]# uname -a
Linux fresh-frog-3.localdomain 4.18.0-80.el8.x86_64 #1 SMP Tue Jun 4 09:19:46 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
</code></pre><h3 id="yarn">yarn</h3>
<p>hugo 主题可能会使用比较火爆的 _scss 框架，scss 框架修改后需要通过 yarn 工具编译生成 dist 文件才能使用。辣么需要安装 yran 并编译主题包；复制粘贴安装</p>
<pre><code class="language-fallback" data-lang="fallback">sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo
yum install yarn
</code></pre><p>安装成功后，进入主题目录下：</p>
<pre><code class="language-bash" data-lang="bash">cd ./themes/even/
# install dependencies
yarn install
# build
yarn build
</code></pre><h3 id="build-failed">build failed</h3>
<p>根据内容分析，是因为 branch 中没有 hugo 的数据目录；上传后 hugo 执行编译成功。<br>
（PS：注意 hugo new site 方式，如果网站目录中已有 .git* 的目录，辣么会变成 GitHub 子项目展示）<br>
（PPS：hugo/theme/ 目录是重灾区，常用是通过 git clone 方式下载 theme，辣么这个 theme 目录里的 .git* 一定要删除，否则会发现 Github pages 看不到任何 html、css 编译后的内容）</p>
<p><img src="https://atman.ihx.cc/post/20200108-2-github-hugo-actions/github-actions-not-found.png" alt="github build failed" loading="lazy" decoding="async">
</p>
<h3 id="no-found-token">no found token</h3>
<p>actions.yml 配置完成，提交 push 记录；检查 actions 操作记录发现未 push ./public 数据到 gh-pages 分支下，提示 <code>not found ACTIONS_DEPLOY_KEY, PERSONAL_TOKEN, or GITHUB_TOKEN</code>。</p>
<p><img src="https://atman.ihx.cc/post/20200108-2-github-hugo-actions/github-actions-deploy-failed.png" alt="not found key" loading="lazy" decoding="async">
</p>
<p>前后思考很久都没理解为啥会报错，yml 配置文件也没写错。后百度发现 <code>ACTIONS_DEPLOY_KEY: ${{ secrets.si }}</code> 参数中 secrets.si 代表了 repo-setting 中 secrets 的设置信息，si 为 secrets 中添加的 ssh-key 信息（PS：就是因为没读这这段信息 <a href="https://github.com/marketplace/actions/github-pages-action#1-add-ssh-deploy-key">deploy-ssh-key</a> 与 github-pages-actions <a href="https://github.com/marketplace/actions/github-pages-action#%EF%B8%8F-personal_token">personal_token</a>。</p>
<pre><code class="language-bash" data-lang="bash">ssh-keygen -t rsa -b 4096 -C &#34;$(git config user.email)&#34; -f gh-pages -N &#34;&#34;
# You will get 2 files:
#   gh-pages.pub (public key)
#   gh-pages     (private key)
</code></pre><h3 id="cname">CNAME</h3>
<p>整体流程都可以工作了，但是每次 draft push 提交更新后，访问自定义域名就无法打开网站（提示 404），经过查看发现是 gh-pages branch 下没有 <strong>CNAME</strong> 文件。<br>
然后我就手动新建一个再次提交一次修改，发现网站又打不开了……<br>
分析了 actions 发现下图，思考十分钟发现是因为 hugo/content 目录下木有 CNAME 文件，辣么 hugo 生成的网站中也没有这个文件，按照 gh-pages 先全部删掉然后在提交 PR 的逻辑就想通了。</p>
<p><img src="https://atman.ihx.cc/post/20200108-2-github-hugo-actions/github-actions-rm-cname.png" alt="github actions rm canme" loading="lazy" decoding="async">
</p>
<p>最后当然是在 hugo/content 目录下创建一个 CNAME 文件，该文件并不影响网站静态生成。</p>
<h3 id="自我懵逼">自我懵逼</h3>
<p>github repo 三个分支分别别是 master、draft、gh-pages，master 中存放 actions.yml、draft 存放 hugo 程序和 markdown 文档、gh-pages 是用于发布网站的分支<br>
此时不断向 draft 提交文档修改，发现 gh-pages actions 并未有任何动作<br>
经过一番测试发现是 actions.yml 文件所在的 branch 收到 push 操作才会去工作（嗯，肯定是我脑等级太低了）//<br>
（PS：每个 barnch 都可以放 actions.yml ，并且可以是不同的内容信息，跨 branch 执行 jobs 也可以工作。每个 branch 下的 actions.yml 由当前 barnch 接受 pull、push 等操作而触发）</p>
<h3 id="匪夷所思">匪夷所思</h3>
<p>提交更新本篇文档，首次 hugo 编译遇见以下问题，第二次静态编译成功。没有 actions 运行日志，不知道咋回事……<br>
如果需要重新执行本次 issue build，可以点右上角的 re-run checks 按钮<br>
（PS：再次遇见该问题，猜测是本文档图片太多了、然后 docker 处理时超时了吧）</p>
<p><img src="https://atman.ihx.cc/post/20200108-2-github-hugo-actions/github-open-Cname.png" alt="open error caname" loading="lazy" decoding="async">
</p>
<h3 id="hugo-version">hugo version</h3>
<p>因为填错了 hugo version 信息，hugo 木有 0.62.2 版本。与上面那个问题是联动的，第一次失败时为了触发再次执行 actions，就修改了下 hugo version 排查下问题，还把版本填错了。</p>
<p><img src="https://atman.ihx.cc/post/20200108-2-github-hugo-actions/github-hugo-version-failed.png" alt="hugo version" loading="lazy" decoding="async">
</p>
<h2 id="0x06-emmm">0x06 emmm</h2>
<blockquote>
<p>没及时搞出来文档，貌似忘记了一部分内容咋写了、先这样了
<img src="https://atman.ihx.cc/post/20200108-2-github-hugo-actions/bottom.png" alt="懒癌晚期" loading="lazy" decoding="async">
</p>
</blockquote>
]]></content:encoded><h:time datetime="2020-01-08T00:00:00+08:00">2020-01-08 · post</h:time><h:a class="feed-article-title" href="https://atman.ihx.cc/post/20200108-2-github-hugo-actions/">生态围墙 - Github Actions &amp; Hugo</h:a></item></channel></rss>