owned this note changed 4 years ago
Linked with GitHub

CI CD Pipeline 為自動化獻上你的肝 - Rain

從最初 CI / CD 被提出的時空背景開始思考,他們的本質與目標究竟為何?應該如何實踐?實踐過程可能遇到哪些瓶頸?本次議程講者將透過分享在團隊中導入 CI / CD 的經驗,描述在微服務架構下規劃 pipeline 的流程與思維、使用的一些工具、遇到的各類工程問題和解決方案、以及一些大膽的想法。

先備知識

任意語言或工具的開發及部署經驗

tags: SITCON 2020 共筆 SITCON 2020 2020 共筆 R1

歡迎大家來到SITCON 2020 ヽ(✿゚▽゚)ノ
共筆入口:https://hackmd.io/@SITCON/2020
手機版請點選上方 按鈕展開議程列表。

請從這裡開始

SlideShare

Whoami

  • Python, Go
  • Backend Engineer
  • 3D artist(Blender!)

Agenda

  • CI
  • CD
  • Get started with CI CD
  • Issues and solutions

CI
Continuous Integration

林博仁 其實我剛剛是想講這個:
https://pre-commit.com

Why CI?

  • Detect integrated issues
  • Avoid integration hell

Pipeline

  • Drone CI
    • json yaml 語法支援
    • secret 管理不便
    • 全部都是基於 Docker 容器,方便起服務
    • 用 Golang 撰寫,對 Golang 熟可以從這個開始下手
  • Travis CI
    • 語法複雜
    • 不太好上手
  • Circle CI
    • youtube廣告很兇(x
    • 使用者社群活躍
    • 新手友善
  • Jenkins
    • 存活年份很久
    • 功能完備強大
    • 不好上手
  • GitHub/GitLab CI
    • 跟 codebase 整合

Packing
打包

  • Docker
    • Dockerfile
  • Hashicorp packer
    • 支援多個 provider(ex. AWS, GCP
    • json 比較人性化
    • 回報的錯誤比較不人性化 (只有 error code)
    • 需要對 shell script 比較熟悉

Output Results of CI

Result

  • Quality of artifacts
  • Cost of Integration
    整合成本
    • 前期不整合,專案後期投入的成本較高
    • 痛苦指數(X

CD
Continous Delivery
持續交付 / 部署

Why continuously deliver?

  • Check artifacts quality
  • Make sure deploy strategy is feasible
    • 只需要部署一台 / 特定幾台機器,會不會導致整個服務掛掉

CD tools and

Provision

  • Hashcorp Terraform
    • 屬於 IaC 的服務
    • 使用自己的 HCL 語法
    • HCL 我覺得很難寫講者

  • Pulumi(推薦)
    • 比較新的工具
    • 大幅改善Terraform設定檔很難寫的問題
    • Typescript/Go(Beta)
  • AWS Cloud Formation
    • 全家桶內工具
  • AWS Cli
    • command line 狂人
    • 用 shell script
    • Hardcore, 新手不友善
    • 靈活性最大 最細節的設定

Device Discover

機器的 ip 可能是由 provider 分配的,要如何讓機器之間找到彼此的 ip

  • Hashicorp Consul
    • 不好上手
  • Prometheus
    • 整合 monitor 跟 device discover
    • 視覺化
    • 掃特定 IP 區段找到新機器的 IP

Orchestration(容器編排)

  • Docker compose
    • 好用
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
  • Helm
    • 用於 K8s 部屬
    • 提供模板,下指令時可以帶參數進去

Artifacts Management

  • DockerHub
    • 很多開源的 image 可以直接 pull
  • AWS ECR
    • 專注於跟 AWS Database、其他服務整合
  • Harbor
    • 也是管 docker image
    • 需要自己架

Scripts

  • Shellscript
    • 要專注 CI/CD 這條路要學的東西
    • 老手新手寫出來完全不一樣
  • Python
    • 直接在 pipeline 中執行就好
  • Makefile
    • 老牌工具

Others

  • SSH
    • 看遠端機器
    • 和遠端機器的溝通
  • SCP
    • 送 config

Output results of CD

Results

  • Anyone can deliver any version to any environment
    • CI/CD 的終極目標
    • 降低工程師被 PM 打擾的頻率
    • 降低部屬服務需要的成本剛domain knockladge
  • Reduce the frequency of being disturbed
    • 5~6/d -> 1 time/3 days

Get started with CI/CD

沒那麼難講者

  • Connect codebase with CI service
    • 給github、gitlab的Token
    • 將Codebase與CI server連結
  • Add testing scripts
    • 確保程式能正常運作(沒有 conflict、能正常執行等等)
  • Add packing scripts
    • 指令:docker build
  • Add deploying scripts
    • 拉下執行檔 去執行

CI CD 疑難雜症

族繁不及備載
實在是太多了(x

CI 太久怎麼辦?

  • 一分鐘觸發兩三次,多人在用就卡住
  • Parallel executing
    • Test case 是獨立的話,可以讓他同時執行
  • Pre-bake docker image
    • 先 build 好基本的 image 再加上後面的程式

Config 好難寫怎麼辦?

寫 Config File 的好工具們:

  • Jsonnet
    • 與DroneCI整合
    • 類似json檔,去產生yaml
  • Starlark

只剩你的機器看得懂,連你自己都看不懂(X

CI CD 怎麼切

  • 以產出Artifacts為分界
  • CI以做到包成image為界

CD 太久怎麼辦?

  • Parallel executing
    • 同時間部屬兩個服務
    • 做load balancing
  • multi-level deployment
    • 階段型部屬
    • 沒必要一次部屬成千上萬個 container
    • 分很多個等級去部屬
    • 可以更新某小部分的container就好
    • 可以先確認是否每個container需要部屬
    • 下線的時間越短越好

開機、服務啟動的延遲

  • While loop 不斷 retry
    • 看看機器是否開好可以使用
  • 或是 sleep 幾秒
    • not recommend (on production)
    • 比較硬的等待
    • 如果等待完還沒開好 你的整合就會失敗

Config 要動態生成

  • 前一個 step 先由程式生成後推上 Artifacts server
  • 下一個 step 再由 Service server pull 下來

不想工作030

  • 那就離職阿!!!

Pycon Taiwan宣導

  • 9/5-9/6

Reference

  • Unsplash
Select a repo