惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Engineering at Meta
Engineering at Meta
D
DataBreaches.Net
月光博客
月光博客
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
U
Unit 42
腾讯CDC
爱范儿
爱范儿
J
Java Code Geeks
有赞技术团队
有赞技术团队
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
B
Blog
Stack Overflow Blog
Stack Overflow Blog
GbyAI
GbyAI
T
The Blog of Author Tim Ferriss
小众软件
小众软件
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Y
Y Combinator Blog
大猫的无限游戏
大猫的无限游戏
Microsoft Azure Blog
Microsoft Azure Blog
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

Surmon.me

一人有限集团 你就是不敢 创造力是温柔的谎言 人类正在退出人类 AI 代替不了这样的你 脉冲点火背后的架构设计 基于 Cloudflare 生态的 AI Agent 实现 NodePress 支持用户登录了 从统计学习到通用智能 2025 投资报告:走慢的路 无依之地 会杀人的菩萨 无我不是共识 文化的积重与偏见 当下即安 科学的尽头是态度 无我不是 Egoless 信仰不因恐惧而存在 世间无解的矛与盾 先别急着做些什么 佛不需要你的皈依 真理的幻觉 两扇大门 造心里的浮屠 自胜者强 逻辑与智慧 真的相 快乐的秘密 只需愿意 是名体验
GitHub Actions 能干啥
Surmon · 2019-10-09 · via Surmon.me

原创

我已经用上 Actions 了,在我看来它不仅仅是一个 CI 工具,它更像一个「 工作流控制器 」。

你可以把它打造为 CI、Bot、跳板机、文章发布器、Issues 统计器...任何你需要的工具或平台。

Actions 事件继承于之前的 API/Webhooks,自身提供了 Docker 环境,这意味着你拥有了无限编程能力的 “工作流定制权”。

比如,在实际的使用中,我的 angular-admin (web)、nodepress (nodejs) 两个项目的部署流程,

前者在 Actions 中的流程为:

测试(前提) -> 编译 -> 打包 -> 压缩 -> 通过 scp 将压缩包传给生产机 -> 执行生产机部署脚本 -> 完成部署

代码:

        
        

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253

name: Deploy to server on: pull_request: types: [closed] branches: - master jobs: deploy: if: github.event.pull_request.merged == true name: Deploy to server runs-on: ubuntu-latest strategy: matrix: node-version: [10.x] steps: - name: Checkout uses: actions/checkout@master with: ref: master - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - name: Install Dependencies run: npm ci - name: Build run: npm run build - name: ls and pwd run: | pwd ls -la - name: Compress dist files run: tar -zcvf ./dist.tar.gz -C ./dist/angular-admin/ . - name: Copy file to server uses: appleboy/scp-action@master with: timeout: 3m overwrite: true host: ${{ secrets.HOST }} username: ${{ secrets.USER }} password: ${{ secrets.PASSWORD }} source: ./dist.tar.gz target: ${{ secrets.WWW_PATH }}/angular-admin/product/ - name: Exec deploy script with SSH uses: appleboy/ssh-action@master with: command_timeout: 3m host: ${{ secrets.HOST }} username: ${{ secrets.USER }} password: ${{ secrets.PASSWORD }} script: | sh ${{ secrets.WWW_PATH }}/angular-admin/.deploy/main.sh

后者在 Actions 中的流程为:

测试 -> 编译 -> 构建测试 -> 执行生产机部署脚本 -> 完成部署

代码:

        
        

123456789101112131415161718192021

name: Deploy to server on: pull_request: types: [closed] branches: - master jobs: deploy: if: github.event.pull_request.merged == true name: Deploy to server runs-on: ubuntu-latest steps: - name: Exec deploy script with SSH uses: appleboy/ssh-action@master with: command_timeout: 10m host: ${{ secrets.HOST }} username: ${{ secrets.USER }} password: ${{ secrets.PASSWORD }} script: sh ${{ secrets.WWW_PATH }}/nodepress/.deploy/main.sh

部署脚本:

        
        

123456789101112131415161718192021222324252627282930313233343536

#!/bin/bash WEB_PATH=$(dirname $0) # WEB_USER='root' # WEB_USERGROUP='root' echo "[deploy] Start deployment..." echo "[deploy] Fetch and rebuilding..." cd $WEB_PATH cd .. echo "[deploy] path:" $(pwd) echo "[deploy] pulling source code..." git fetch --all && git reset --hard origin/master && git pull git checkout master # echo "changing permissions..." # chown -R $WEB_USER:$WEB_USERGROUP $WEB_PATH # chmod -R 777 $WEB_PATH # sync && echo 3 | sudo tee /proc/sys/vm/drop_caches echo "[deploy] Install dependencies..." npm ci echo "[deploy] Stop service..." pm2 stop nodepress echo "[deploy] Remove old dist..." rm -r ./dist/* echo "[deploy] Building..." npm run build echo "[deploy] Restarting..." pm2 restart nodepress echo "[deploy] Finished."

这一切都在 Actions 中完成,除去目标生产服务所必须的环境,你不需要额外多做什么; 反而,你可以将 工作流、部署、测试、生产代码... 等一系列上下游相关的配置或文件约束在同一个项目,甚至同一个目录内, 使项目始终紧密耦合在同一个单元内,减少维护成本。

所以,我已经把 SRE 服务 下线并废弃了。

祝使用愉快。