Upgrade to Pro — share decks privately, control downloads, hide ads and more …

深入GitLabCI-談描述檔重構與流水線加速

 深入GitLabCI-談描述檔重構與流水線加速

本次的講題是在 「台中自由軟體愛好者社群」所做的分享,內容主要著重在 GitLab CI 在流水線加速與描述檔重構兩個部分。

使用之 .gitlab-ci.yml 範例連結:https://gitlab.com/mouson-gitlab-playground/gitlab-ci-demo-sample/-/tree/refactor-gitlab-ci-sample-v3

影片紀錄連結:https://www.youtube.com/watch?v=8wLGw7oYJKg&feature=youtu.be&t=2438

mouson(墨嗓)

November 28, 2020
Tweet

More Decks by mouson(墨嗓)

Other Decks in Technology

Transcript

  1. 深入 GitLab CI • Part I: 流⽔線 (Pipeline) 加速 •

    Part II: .gitlab-ci.yml 描述檔如何重構
  2. .gitlab-ci.yml Job Job Job Job Job Job Job Queue Runner

    Server Runner Server Runners Runner Runner Runner Runner
  3. .gitlab-ci.yml Job Job Job Job Job Job Job Queue Runner

    Server Runner Server Runners Runner Runner Runner Runner Run Job ____________________________
  4. ⼯作花太久時間等待進 Queue? • 套⽤ DAG 機制 (GitLab 12.2) build test

    deploy build_a test_a deploy_a build_b test_b deploy_b build_c test_c deploy_c build_b
  5. ⼯作花太久時間等待進 Queue? • 套⽤ DAG 機制 (GitLab 12.2) build test

    deploy build_a test_a deploy_a build_b test_b deploy_b build_c test_c deploy_c build_b
  6. ⼯作花太久時間等待進 Queue? • 套⽤ DAG 機制 (GitLab 12.2) build test

    deploy build_a test_a deploy_a build_b test_b deploy_b build_c test_c deploy_c build_b
  7. .gitlab-ci.yml Job Job Job Job Job Job Job Queue Runner

    Server Runner Server Runners Runner Runner Runner Runner
  8. Job Job Job Job Job Job Job Queue Runner Server

    Runner Server Runners Runner Runner Runner Runner
  9. Job Job Job Job Job Job Job Queue Runner Server

    Runner Server Runners Runner Runner Runner Runner •Runner 數量夠嗎?
  10. Job Job Job Job Job Job Job Queue Runner Server

    Runner Server Runners Runner Runner Runner Runner •Runner 數量夠嗎? •能執⾏的 Runner 夠嗎?
  11. Job Job Job Job Job Job Job Queue Runner Server

    Runner Server Runners Runner Runner Runner Runner
  12. Job Job Job Job Job Job Job Queue Runner Server

    Runner Server Runners Runner Runner Runner Runner Run Job ____________________________
  13. Runner Server Runner Server Runners Runner Runner Runner Runner Run

    R u n ____________________________ * prepare p r e p a r e p r e
  14. Runner Server Runner Server Runners Runner Runner Runner Runner Run

    R u n ____________________________ * prepare p r e p a r e p r e * git g i t g i t r
  15. Runner Server Runner Server Runners Runner Runner Runner Runner Run

    R u n ____________________________ * prepare p r e p a r e p r e * git g i t g i t r * restore r e s t o
  16. Runner Server Runner Server Runners Runner Runner Runner Runner Run

    R u n ____________________________ * prepare p r e p a r e p r e * git g i t g i t r * restore r e s t o * download d o w n l o a d
  17. Runner Server Runner Server Runners Runner Runner Runner Runner Run

    R u n ____________________________ * prepare p r e p a r e p r e * git g i t g i t r * restore r e s t o * download d o w n l o a d * script s c r i p t
  18. Runner Server Runner Server Runners Runner Runner Runner Runner Run

    R u n ____________________________ * prepare p r e p a r e p r e * git g i t g i t r * restore r e s t o * download d o w n l o a d * script s c r i p t * package p a c k a g e
  19. Runner Server Runner Server Runners Runner Runner Runner Runner Run

    R u n ____________________________ * prepare p r e p a r e p r e * git g i t g i t r * restore r e s t o * download d o w n l o a d * script s c r i p t * package p a c k a g e * saving s a v i n
  20. Runner Server Runner Server Runners Runner Runner Runner Runner Run

    R u n ____________________________ * prepare p r e p a r e p r e * git g i t g i t r * restore r e s t o * download d o w n l o a d * script s c r i p t * package p a c k a g e * saving s a v i n * uploading u p l o a d i n g
  21. Runner Server Runner Server Runners Runner Runner Runner Runner Run

    Job ____________________________ * prepare execute env * git repo fetch * restore cache * download artifacts * script execute * package install * saving cache * uploading artifacts * cleaning up f i le base var
  22. •Network Performance ? Runner Server Runner Server Runners Runner Runner

    Runner Runner Run Job ____________________________ * prepare execute env * git repo fetch * restore cache * download artifacts * script execute * package install * saving cache * uploading artifacts * cleaning up f i le base var
  23. •Network Performance ? •Docker image size ? Runner Server Runner

    Server Runners Runner Runner Runner Runner Run Job ____________________________ * prepare execute env * git repo fetch * restore cache * download artifacts * script execut e * package install * saving cache * uploading artifacts * cleaning up f i le base var
  24. •Network Performance ? •Docker image size ? •Git Repo Size

    ? Runner Server Runner Server Runners Runner Runner Runner Runner Run Job ____________________________ * prepare execute env * git repo fetch * restore cache * download artifacts * script execut e * package install * saving cache * uploading artifacts * cleaning up f i le base var
  25. •Network Performance ? •Docker image size ? •Git Repo Size

    ? •Programming Language Dependence Package Size ? Runner Server Runner Server Runners Runner Runner Runner Runner Run Job ____________________________ * prepare execute env * git repo fetch * restore cache * download artifacts * script execut e * package install * saving cache * uploading artifacts * cleaning up f i le base var
  26. •Network Performance ? •Docker image size ? •Git Repo Size

    ? •Programming Language Dependence Package Size ? •Artifacts Size ? Runner Server Runner Server Runners Runner Runner Runner Runner Run Job ____________________________ * prepare execute env * git repo fetch * restore cache * download artifacts * script execut e * package install * saving cache * uploading artifacts * cleaning up f i le base var
  27. •Network Performance ? •Docker image size ? •Git Repo Size

    ? •Programming Language Dependence Package Size ? •Artifacts Size ? •Script Performance ? Runner Server Runner Server Runners Runner Runner Runner Runner Run Job ____________________________ * prepare execute env * git repo fetch * restore cache * download artifacts * script execut e * package install * saving cache * uploading artifacts * cleaning up f i le base var
  28. Runner Server Runner Server Runners Runner Runner Runner Runner Run

    Job ____________________________ * prepare execute env * git repo fetch * restore cache * download artifacts * script execut e * package install * saving cache * uploading artifacts * cleaning up f i le base var
  29. .gitlab-ci.yml Job Job Job Job Job Job Job Queue Runner

    Server Runner Server Runners Runner Runner Runner Runner Run Job ____________________________ * prepare execute env * git repo fetch * restore cache * download artifacts * script execut e * package install * saving cache * uploading artifacts * cleaning up f i le base var
  30. 10. 拆分檔案利 ⽤ include 載入 ├── .gitlab-ci.yml └── templates ├──

    common.yml ├── de f i ne.yml ├── lint.yml ├── test.yml └── deploy.yml
  31. 10. 拆分檔案利 ⽤ include 載入 ├── .gitlab-ci.yml └── templates ├──

    common.yml ├── de f i ne.yml ├── lint.yml ├── test.yml └── deploy.yml
  32. 10. 拆分檔案利 ⽤ include 載入 ├── .gitlab-ci.yml └── templates ├──

    common.yml ├── de f i ne.yml ├── lint.yml ├── test.yml └── deploy.yml
  33. 10. 拆分檔案利 ⽤ include 載入 ├── .gitlab-ci.yml └── templates ├──

    common.yml ├── de f i ne.yml ├── lint.yml ├── test.yml └── deploy.yml
  34. 10. 拆分檔案利 ⽤ include 載入 ├── .gitlab-ci.yml └── templates ├──

    common.yml ├── de f i ne.yml ├── lint.yml ├── test.yml └── deploy.yml
  35. 10. 拆分檔案利 ⽤ include 載入 ├── .gitlab-ci.yml └── templates ├──

    common.yml ├── de f i ne.yml ├── lint.yml ├── test.yml └── deploy.yml
  36. 10. 拆分檔案利 ⽤ include 載入 ├── .gitlab-ci.yml └── templates ├──

    common.yml ├── de f i ne.yml ├── lint.yml ├── test.yml └── deploy.yml
  37. 10. 拆分檔案利 ⽤ include 載入 ├── .gitlab-ci.yml └── templates ├──

    common.yml ├── de f i ne.yml ├── lint.yml ├── test.yml └── deploy.yml
  38. include: - local: 同專案下的檔案 - remote: URL 連結 - template:

    GitLab 官⽅提供的模板 - f i le: 來⾃其他專案的檔案
  39. include: f i le introduced in GitLab 11.7 include multi

    f i le from a project in GitLab 13.6 11. 建立共⽤流 程供其他專案 使⽤
  40. Recap • 利⽤ default stage 整理所有 job 都共同的 • 利⽤

    .hidden 建立模板⼯作,並⽤ extends 繼承使⽤ • 利⽤ Anchors 整理可重複使⽤的 Script • 萃取出變數 • 利⽤ Parallel Matrix 功能 • 建立多專案共⽤流程 • Sample Source Code: https://bit.ly/3mTiBgJ
  41. Q&A