Github Actions E02最小Demo

前言

前面一篇已经说明一些概念,于是为了更好的理解,直接用一个简单的demo帮助进一步理解概念。

示例仓库: https://github.com/cicd-draft/api-test-demo

1.配置工作流

1.1 步骤一

在仓库的根目录,创建名为 .github/workflows 的目录以存储工作流程文件。

1.2 步骤二

.github/workflows 中,为工作流程添加 .yml 或 .yaml 文件。 例如 .github/workflows/demo.yml。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
name: my workflow demo 

# 此处使用最常见的触发方法,还有其他的很多方法可满足不同需求
on:
push:
branches:
- master

#工作流程运行包括一项或多项作业。 作业默认是并行运行。 要按顺序运行作业,needs 关键词在其他作业上定义依赖项。
jobs:
#每项作业必须关联一个 ID。<job_id> 必须以字母或 _ 开头
my_first_job:
# 作业1名称为 Demo First job,也是作业显示在 GitHub 上的名称。
name: Demo First job
# 此作业在 Linux 上运行
runs-on: ubuntu-latest
steps:
- name: My step one
run: echo "Hello ,Github actions, I'm >>My step one<<"
- name: My step two
run: |
echo "My step one begin..."
echo "doing..."
echo "Finished!!!"
my_second_job:
name: Demo Second job
runs-on: macos-latest
steps:
- name: check OS info
run : system_profiler SPSoftwareDataType

1.3 步骤三

将工作流程文件中的更改提交到您希望其中运行工作流程的分支。

到这里一个简单的demo就算完成了,可以去 Actions 按钮下查看运行情况。

2.管理工作流

官网链接有详细说明以下每个操作中的细节

由于图片太多,就不做搬运工了

about

Ops/Devops, China.

Email: 771963601@qq.com

宅,爱好发呆、阅读、羽毛球…

电影爱好者,程序员里的中学生了

一个足够简单的人,还想成为一个有趣的人


👏 找工作可邮件,城市:北上深、西安、武安、成都,职位:Devops,开发,测试,PM等!

Github Actions E01初识

前言

随着github actions在2019年下半年的推出,越来越多的人认识并了解到它。而也因为项目上的机遇,想尝试一下它。于是会较完整地从个人使用角度去记录一下,会有一系列的关于Github actions的文章

另外,为方便会将 Github actions 简称为GA; 如果官方有简写,到时候再统一更换。

0. Github Actions的历史

2018年10月16日,全球最大开发者社区GitHub Universe开发者大会在旧金山召开,发布了新产品GitHub Actions。但是仅处于 limited public beta。个人是2019年9,10月份的时候看到新闻消息,听说了这个新词。当时还是 Beta 版本,需要自己简单的申请一下,才可以使用。而到这个时间点(2020.03),对于公开的 Github Public repositories 早已经可以全面使用(‘2019年11月13日 GitHub Actions 将在 GitHub Universe 上正式发布’)。

1. 什么是Github Actions

根据官网的介绍如下:

Github Actions

Automate your workflow from idea to production.

GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.

个人理解:

  • 首先做了 CI/CD 工具的事情,后面在使用过程中也可以看到github actions 实现了很多CI/CD工具 jenkins,Travis CI,CircleCI 等一些部分功能;
  • automate(自动),可以让很多与代码库相关的事情自动,比如很多人用到的 用github actions 发布hexo博客用github actions给自己推送天气预报

2. 为什么使用

  • 1.不要钱(部分)

    本着github 开源的原则,公开的仓库可免费,私有仓库有限制的使用,对于企业用户也是。不过很好奇对于购买了github企业版的用户,如果想要使用github actions会怎么收费,有哪些方式可选。

  • 2.多平台

    支持3大主流操作系统 Linux, macOS, Windows,这一条无疑很有吸引力,因为毕竟一个人难以拥有三种系统的电脑(即便有方法,切换起来也会费时费劲)。而对于苹果软件而言,有一个 macOS 的构建环境实属难得,毕竟人家的系统是收费的。也可对接很多云,如AWS、Azure 或是 GCP,也支持众多语言。

  • 3.功能强

    功能太多,不一一说明,只简单提及几点,Matrix Workflows,Container Services,Caching Dependencies, Actions Marketplace 等等,具体使用后续细解。

3.基本概念

workflow(工作流程):持续集成一次运行的过程。

job(任务):一个 workflow 由一个或多个 job 构成,含义是一次持续集成的运行,可以完成多个任务。

step(步骤):每个 job 由多个 step 构成,一步步完成。

action(动作):每个 step 可以依次执行一个或多个命令(action)。

由于自己使用jenkins较多,一直想把以上概念与jenkins的做对比,但后来发现,还是不对比较好。因为 github actions的基本组成有自己的特色和优势,在使用时不要纠结旧的Jenkins中掌握的知识,需要抛弃旧的观念.建议:不被jenkins和其他cicd工具所限制住,最好深入理解github actions开发者的初衷,灵活运用。

小思考?

一年后,两年后,Github Actions 会怎么影响其他工具?(Jenkins,Gocd, Gitlab CI, AWS CodeDeploy等等)

(欢迎评论区留言)


待完成清单


More Ref:

hexo sytnax

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

用HEXO在Github建立个人博客教程: https://www.jianshu.com/p/1f23f94b73d4

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment


hexo sytnax

常用的偏门小技巧

书写风格

Markdown书写风格指南

https://gerrit.googlesource.com/gitiles/+/master/Documentation/markdown.md

文章框架

同一类型的文章,比如技术类的,最好有一个框架用来提醒自己,把事情尽量写清楚;推荐看看
文章框架

目录categories和标签tags的说明:

也不知道合不合适,目录包含标签,是一个大的范围,标签是具体的东西,属于其中,一个目录可包含多个标签。

画图UML

@startuml
Bob -> Alice : hello
@enduml

加密

hexo-blog-encrypt ,具体过程也是参考链接完成安装、使用的。

图床

选用 路过图床

  • 不用注册账号
  • 未注册最大5M,注册后最大10M。大小都够了,不行的话可以提前用 https://tinypng.com/ 压缩一些
  • 上传后提供多种格式供嵌入代码

评论

使用disqus,其账号保持和github的账号一致,毕竟blog内容也在github上。用github用的邮箱注册一把,

然后我当前的主题好像不支持

该用Valine

Valine是基于 LeanCloud 作为数据存储的

  • 登录 https://console.leancloud.app/ 注册 (用国际版,国内的版本似乎还要实名认证)

  • 邮箱验证,手机验证

  • 创建应用:控制台 -> 创建应用(开发版)

  • 创建 Class: CounterComment (默认权限配置即可)

  • Settings-> App keys 获取AppIDAppKey。放到对应主题的 _config.yml

链接中的括号

解决方法1:
%28 代替(, %29代替) 主要是后者会歧义链接部分的结束.,这是使用url符号码去代替ascii的符号,能够解决这个问题。可参考 https://www.w3schools.com/tags/ref_urlencode.asp The default character-set in HTML5 is UTF-8.

例如:
更多关于 Telegram 的介绍可以查看 Wikipedia

解决方法2:
直接使用特殊字符的编码

例如:
更多关于 Telegram 的介绍可以查看 Wikipedia

提示块

目前主题貌似暂时不支持
[note]
Note: This is a note.

[warning]
Warning: This is a warning.

[warning] 我是warning类型引用


删除线

跑路指南哇

锚点

说明文字,点击这里会跳到下面的位置

跳转到的位置

上标、下标

1
2
H<sub>2</sub>O  CO<sub>2</sub>
爆米<sup>TM</sup>

效果:

1
2
H2O CO2
爆米TM

画UML

TL;DR
文字 + 工具 ,画个好图

什么是 UML

全称 Unified Modelling Language,UML维基百科

什么是 PlantUML

是一个开源项目,支持快速绘制各种图,包括 时序图、用例图、类图、活动图、组件图、状态图、对象图、部署图、定时图;同时还支持以下非UML图:线框、图形界面、架构图、规范和描述语言 (SDL)、Dita diagram、甘特图 、思维导图

官网:https://plantuml.com/zh/, 包含了各种具体用法,比如更改字的颜色,图片背景颜色等

举几个🌰🌰

示例1: 画一个UML
工具: VSCode + 插件 plantuml
步骤:

  • 1.打开VSCode,安装插件 plantuml

    似乎要提前安装JDK,由于我本机已经安装,暂没验证这一步

  • 2.新建文件 example1.wsd
  • 3.添加内容如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    @startmindmap
    skinparam true
    * 数据库运维
    ** 安装
    *** 如何安装
    *** 如何设置高可用
    ** 备份
    ** 恢复
    @endmindmap
  • 4.按 alt + d,立马会生成UML图

示例2: 给md文档添加 UML 图
好处:不用单独保留一张图片,然后再插入到 readme.md 文档中
工具: markdown
新建md文件,比如 example2.md,成果如下:

只能利用vscode 打开时,才能看到图形,如用浏览器,打开一个readme.md文档,是无法看到图形的


More Ref:

  1. UML维基百科
  2. 参考例子
  3. youtube视频

移动端打包pipeline通识:从零开始

背景: 一台被格式化后的 MacBook Pro, 对某个移动端项目( xx类型 )做android pipeline、iOS pipeline

网络:公司网络(可翻墙)

makefile

记得验证/确认

1-安装/Set up

1.1 install brew
1
2
3
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew -v

brew cask 是在brew 的基础上一个增强的工具,用来安装Mac上的Gui程序应用包(.dmg/.pkg), 比如qq、chrome等。它先下载解压到统一的目录中(/opt/homebrew-cask/Caskroom),省掉了自己去下载、解压、拖拽(安装)等步骤,同样,卸载相当容易与干净。然后再软链到~/Applications/目录下, 非常方便,而且还包含很多在 AppStore 里没有的常用软件。

1.2 install brew cask

brew install brew-cask-completion

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
➜  Desktop brew cask
Homebrew Cask provides a friendly CLI workflow for the administration
of macOS applications distributed as binaries.

Commands:

--cache display the file used to cache the Cask
audit verifies installability of Casks
cat dump raw source of the given Cask to the standard output
create creates the given Cask and opens it in an editor
doctor checks for configuration issues
edit edits the given Cask
fetch downloads remote application files to local cache
home opens the homepage of the given Cask
info displays information about the given Cask
install installs the given Cask
list with no args, lists installed Casks; given installed Casks, lists staged files
outdated list the outdated installed Casks
reinstall reinstalls the given Cask
style checks Cask style using RuboCop
uninstall uninstalls the given Cask
upgrade upgrades all outdated casks
zap zaps all files associated with the given Cask

See also "man brew-cask"
1.3 install java

方法一: 官网下载

1
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3a%2F%2Fwww.oracle.com%2Ftechnetwork%2Fjava%2Fjavase%2Fdownloads%2Fjdk8-downloads-2133151.html; oraclelicense=accept-securebackup-cookie;" "https://download.oracle.com/otn/java/jdk/8u231-b11/5b13a193868b4bf28bcb45c792fce896/jdk-8u231-macosx-x64.dmg"

方法二: brew cask下载

1
2
brew tap homebrew/cask-versions
brew cask install adoptopenjdk8

检查版本:java -version

1.4 install jenkins

在Mac OS上安装jenkins的N(4)种方法

  • 方法一: 下载war包,java命令启动
    curl -L -O http://mirrors.jenkins-ci.org/war/2.211/jenkins.war

java -jar /xx/xx/jenkins.war --httpPort=8080

  • 方法二: 将下载的war包文件部署到 tomcat servlet 容器,用脚本 startup.sh 启动

    暂不介绍

  • 方法三: brew 安装&启动

1
2
3
4
5
6
#install jenkins, Requires Java 1.8, [issus](https://github.com/Homebrew/homebrew-core/issues/39037)
brew install jenkins-lts
# start jenkins, default port: 8080
brew services start jenkins-lts
# stop jenkins
brew services stop jenkins-lts
  • 修改默认端口 link
  • 假设希望jenkins能够开机自启动以及异常自己主动重新启动 link

sudo touch /Library/LaunchDaemons/org.jenkins-ci.plist

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>Jenkins</string>
<key>KeepAlive</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/java</string>
<string>-Dmail.smtp.starttls.enable=true</string>
<string>-jar</string>
<string>/usr/local/opt/jenkins/libexec/jenkins.war</string>
<string>--httpListenAddress=127.0.0.1</string>
<string>--httpPort=8080</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>jenkins</string>
</dict>
</plist>
  • 方法四: docker container 启动,添加宿主机作为一个slave node,并使用

TODO:
[] jenkins加入到开机自启动
[X] 定制化配置等

我是谁 -> whoami
我在哪里 -> pwd && ls -al
我要到哪里去 -> New item

配置项目pipeline

安装项目所需工具 cocoapods

1
2
# install cocoapods
sudo gem install cocoapods

检查所有工具的版本
xcodebuild -version
react-native

添加jenkins 凭证

ref:

The Gig Economy Note

零工经济是指一种经济价值,它来源于一种不断增长的趋势,即人们开始从事工作时间不定的工作,而这有别于以工作时间固定不变为特征的传统工作

共享经济和零工经济的主要区别在于,前者包括了涉及实体资产的服务或体验购买,而后者则是有时限的、由个人交付的服务

按需经济是零工经济的一个子集,它是指在需求触发下提供产品或服务的数字市场的经济活动

按需经济和零工经济的关键区别在于需求的即时性,而即时性取决于零工所需的技能水平和持续时间

有时,新鲜的视角是必需的,因为内部团队已经围绕一个问题工作太久了,他们无法再分辨出问题中微妙的部分。

在一些公司,由于没有人愿意打开“潘多拉的魔盒”,因此,困难的问题常常被忽略了。而一名中立的旁观者往往是打开魔盒的最佳选择。咨询师可以被视为不结盟者,因此他们的观点会更为客观。

收费结构

设定收费的方式很多,通常分为四个大类:按小时收费按项目收费成交费股权

按时收费是最常见的,提一下定价的 1%原则,即每个人的每日费用应该是他等效年收入的1%。

Scan Docker Images for Vulnerabilities

  • 可以扫描哪些方面,哪些方面检查不出来

  • 有哪些工具,各自特点

  • 工具开源/收费

  • 是否方便与pipeline集成

  • 报告形式

  • 是否需要单独的服务端、数据库

Tool 1: trivy

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
➜   trivy python:alpine
2019-12-12T09:40:48.656+0800 INFO Detecting Alpine vulnerabilities...

python:alpine (alpine 3.10.2)
=============================
Total: 9 (UNKNOWN: 0, LOW: 2, MEDIUM: 7, HIGH: 0, CRITICAL: 0)

+-----------+------------------+----------+-------------------+--------------------------------+
| LIBRARY | VULNERABILITY ID | SEVERITY | INSTALLED VERSION | FIXED VERSION | TITLE |
+-----------+------------------+----------+-------------------+--------- +-------------------+
| e2fsprogs | CVE-2019-5094 | MEDIUM | 1.45.2-r0| 1.45.2-r1 | e2fsprogs: crafted |
| | | | | | ext4 partition leads to |
| | | | | | out-of-bounds write |
+-----------+------------------+ +-------------------+---------------+--------------------------------+
| expat | CVE-2019-15903 | | 2.2.7-r0| 2.2.7-r1 | expat: heap-based buffer |
| | | | | | over-read via crafted XML |
| | | | | | input |
+-----------+------------------+ +-------------------+---------------+--------------------------------+
| libgcrypt | CVE-2019-13627 | | 1.8.4-r2| 1.8.5-r0 | libgcrypt: ECDSA timing |
| | | | | | attack in the libgcrypt20 |
| | | | | | cryptographic library |
+-----------+------------------+ +-------------------+--------------
省略100行

Tool 2: Anchore

Anchore consists of a commercial edition (Anchore Enterprise) and an open-source edition (Anchor Engine).

Tool 3: open-scap

Tool 4: Dagda

Tool 5: Clair

ref:

Azure FAQs

1. asm, arm

  • asm: Azure Service Manager
  • arm: Azure Resource Manager

最开始一直都是classic模型,它的模型中有service的概念,所以它也叫 asm(Azure Service Manager)。2014年开始提出arm(Azure Resource Manager),其管理平台叫portal。2015年底arm发布。

当前情况是微软正在将azure的所有功能往arm上迁移。以后都推荐使用arm。但 是当前状况是arm不完全向后兼容asm,有些功能只有asm上才有,所以还有很多 用户还是在使用classic。

ref: https://pengpengxp.github.io/archive/before-2018-11-10/2017-06-28-Azure%E7%BB%8F%E5%85%B8%E6%A8%A1%E5%BC%8F%E5%92%8C%E8%B5%84%E6%BA%90%E7%AE%A1%E7%90%86%E6%A8%A1%E5%BC%8F%E7%9A%84%E5%8C%BA%E5%88%AB.html#orgbb66971

2. AWS to Azure services comparison

详见链接 https://docs.microsoft.com/en-us/azure/architecture/aws-professional/services

Azure tutorial 02: Storage

storage account type
https://docs.microsoft.com/en-us/azure/storage/common/storage-account-overview

Blob - Binary Large Object
Binary Object - Images,Documents,Media Files, Log Files, Backup data Virtual Disks

Blod types:

  • Block Blob - Text and binary data Files
  • Append Blobs - Optimized for append operations
  • Page Blob - A collection of 512 byte pages optimized for random read and writes(virtual disk)

Locations and Redundancy:

  • Locally-redundant storage (LRS): A simple, low-cost replication strategy. Data is replicated synchronously three times within the primary region.
  • Zone-redundant storage (ZRS): Replication for scenarios requiring high availability. Data is replicated synchronously across three Azure availability zones in the primary region.
  • Geo-redundant storage (GRS): Cross-regional replication to protect against regional outages. Data is replicated synchronously three times in the primary region, then replicated asynchronously to the secondary region. For read access to data in the secondary region, enable read-access geo-redundant storage (RA-GRS).
  • Geo-zone-redundant storage (GZRS) (preview): Replication for scenarios requiring both high availability and maximum durability. Data is replicated synchronously across three Azure availability zones in the primary region, then replicated asynchronously to the secondary region. For read access to data in the secondary region, enable read-access geo-zone-redundant storage (RA-GZRS).

Access Tiers:

  • Hot
  • Cool
  • Archive

Azure Storage services:

  • Blob service
  • File service
  • Queue service
  • Table Storage

Securing Storage Accounts:

  • Access Keys -Two per storage account,full access
  • Share Access Signatures - Time based access keys that give granular control

作业:新建storage account ,并上传文件或文件夹到

create顺序:
a subscriptions -> a storage account -> a SAS token

除了从azure portal页面操作之外,还提供以下两种方式

打开 Azure Storage Explorer, 通过xx链接storage

1
2
#mac os terminal
azcopy cp "/Users/xxx/Desktop/testdir/hello_azure.txt" "https://storage873375.blob.core.windows.net/container1/?[?sv=2019-02-02&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-12-11T11:40:09Z&st=2019-12-11T03:40:09Z&spr=https&sig=5%2FFHo4%2BBwxDB6wLftyB7%2FSF7gqnhaEmpFa4nheBOXQg%3D]"

报错,原始是 后边格式的问题

1
2
#mac os terminal
azcopy cp "/Users/xxx/Desktop/testdir/hello_azure.txt" "https://storage873375.blob.core.windows.net/container1/newdir/?sv=2019-02-02&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-12-11T11:40:09Z&st=2019-12-11T03:40:09Z&spr=https&sig=5%2FFHo4%2BBwxDB6wLftyB7%2FSF7gqnhaEmpFa4nheBOXQg%3D"

https://docs.microsoft.com/en-us/rest/api/storageservices/understanding-block-blobs--append-blobs--and-page-blobs

  • Copyrights © 2019-2024 John Doe
  • Visitors: | Views:

请我喝杯咖啡吧~