zoukankan      html  css  js  c++  java
  • 在pai面板上devops部署static site

    本文关键字:blog联合,一文多发,blog内容联合。headless ghost cms

    前面《在云主机上手动安装腾讯PAI面板》中,我们发现PAI是一个利用git和devops,在仓库的根下放置.pai.yml来达到自动部署+运行APP目的的一种机制,除了没有容器和隔离,其它都这属于CD/CD的思路,下面来实际部署官方的hexo static blog例子,虽然我有点不承认它是serverless的hexo静态网站生成器(tx云函数官方也有一个staticsite版本,稍后会谈到真正的这类产品是headless ghost cms这种)但肯定比普通hexo要方便一点,完成之后的效果就是能作到类似利用git hook部署网站+自动更新(稍后也会谈到它的另外一个效果:可以与其它git仓库,如github,gitee作内容联合)。。

    不废话了

    安装hexo:

    在管理面板中,我们要安装的是这个仓库,https://gitee.com/TencentCloudBase/pai-mate-hello-example-static,这个仓库是个hexo的example site项目,(正常安装后,会生成/data/pai_mate_workspaces/pai-mate-hello-example-static/pai-static-pages.js和/data/pai_mate_workspaces/pai-mate-hello-example-static/ecosystem.config.js,ecosystem.config.js是pm2用的守护脚本,它守护pai-static-pages.js开启3000端口上serving public dir的静态http服务,这个服务没开起来之前,访问与pai安装时的绑定域名会一直502,安装好后,可以访问域名),但是除了这些,它却没有安装好hexo本身(也许官方期待用户手动进服务器安装) 也就少了至关重要的hexo生成网页的作用,查看它的.pai.yml下,没有部署脚本deployScripts:,只有一行static: public(这正是上面二个生成文件生成的语句),---- 无论如何,这个仓库中的.pai.yml不完善。我们来完善补全这个仓库一下:

    .pai.yml,注释掉 static: public,另:不知为什么,hexoauto加--watch会与上一条冲突,导致3000频频挂掉,故 --name hexoauto后不加--watch

    # static: public
    deployScripts:
      start:
        - npm install
        - npm install --unsafe-perm=true --allow-root -g hexo-cli
        - npm audit fix
        - pm2 start -s ecosystem.config.js
        - pm2 start "hexo generate --watch" --name hexoauto
      restart:
        - hexo clean
        - hexo generate
    

    手动在仓库里添加以上二个js文件,pai-static-pages.js:

    // This file is auto-generated by PAI-MATE
    const handler = require('serve-handler')
    const http = require('http')
    const server = http.createServer((request, response) => { return handler(request, response, {public: 'public'}) })
    const port = +process.env.PORT
    server.listen(port, () => { console.log('Running at http://localhost:' + port) })
    

    手动在仓库里添加以上二个js文件,ecosystem.config.js

    // This file is auto-generated by PAI-MATE
    module.exports = {
      apps : [{
        name: "pai-static-pages",
        script: "./pai-static-pages.js",
          watch: true,
          env: {
            "PORT": 3000,
            "NODE_ENV": "production",
            "NODE_PATH": "/usr/local/node/lib/node_modules",
          }
      }]
    }
    

    这样部署后仓库就运行起来了,点管理面板中重启应用能达到最基本的自动部署仓库中的内容和启动静态网页服务的目的。只是,它缺少一个pm2 git clone。依赖手动重启restart处的hexo generate。整个应用处,还是需要一道工序(而理想状态下,内容源git一下应该是唯一的工作)。

    内容联合:

    曾经我们有网盘联合,内容转存。blog和文章作为一种“内容”,有时也需要联合和一文多发。这类功能应该加到各大笔记和知识库核心功能中,当然也有这样的独立产品如artpub。

    上面的git方式联合,只是让仓库和这个静态站之间作内容源联合。这种基于git devops的工具层的东西,在内容联合方面还是有局限的。

    在多样内容源联合方案的选择上,还是基于API的好(因为可编程的东西不局限于工具,见《用开发tcpip的方式开发web》),比如那种headless ghost cms content api+JAMstack front-end like hexo的方案就好多了(这也使得hexo这类工具通用BLOG静态生成器上升为通用网站生成器的境界),在“迁移内容”,和”换前端“方面都有很大的自由度(虽然费折腾但是做成工具和产品也一样)。


    下文,由于pai是个类似baota panel基于pyenv的python项目管理器,下文探索它的py项目部分,未来讨论利用staticsite和markdown生成整站单页pdf book等课题


    (此处不设回复,扫码到微信参与留言,或直接点击到原文)

  • 相关阅读:
    jwt手动生成access_token
    python学习-52 XML模块
    python学习-51 shelve模块
    python学习-50 pickle模块
    python学习-49 json模块
    python学习-48 模块2
    python学习-47 random模块
    python学习-46 时间模块
    python学习-45 模块
    python学习-44 程序的解耦 (不是特别懂的,回头在复习)
  • 原文地址:https://www.cnblogs.com/minlearn/p/13771560.html
Copyright © 2011-2022 走看看