一、定義
製品
Artifacts is a list of files and directories which are attached to a job after it completes successfully.
製品(Artifacts)概念源自傳統製造業,在持續集成引入軟件業後,該術語用於描述編譯出的文件,將編譯類比爲生產活動。
製品庫
製品庫用於存放編譯出的產品包,包括測試通過和測試失敗的版本,通過驗收的產品包,將遷移至產品庫,供發佈和部署。
二、需求
- 立足於 GitLab 能力設計製品管理,簡化工具棧。
- 有序管理編譯出的產品包:
- 產品包存放標準化
- 開發人員便捷獲取
- 最小授權
- 有限保持編譯出的產品包,過期清理。
三、解決方案
創建專用製品庫服務器,並基於 GitLab 製品功能完成製品流轉與存檔等管理。
- 專用製品庫服務器:緩解 GitLab 服務所在機器的存儲壓力;減少多職責引發的管理混亂。
- 基於dependencies特性,實現編譯出的製品流轉至製品庫及測試 job,通過測試後存入產品庫。
- 基於 GitLab UI,實現開發人員對製品的查看、獲取的需求。
- 基於 Artifacts的過期設置,實現自動清理。
3.1 配置 dependencies 支持製品在 job 間流轉
以一個示例說明,目標編譯兩個平臺的版本(osx 及 linux),並分別在兩個平臺上進行測試。在 build job(build:osx
、build:linux
j)中,指定製品來源的路徑(paths:
);在test job (test:osx
、test:linux
)中指定從哪個上游 job 中獲取製品包
build:osx:
stage: build
script: make build:osx
artifacts:
paths:
- binaries/
build:linux:
stage: build
script: make build:linux
artifacts:
paths:
- binaries/
test:osx:
stage: test
script: make test:osx
dependencies:
- build:osx
test:linux:
stage: test
script: make test:linux
dependencies:
- build:linux
deploy:
stage: deploy
script: make deploy
3.2 關於製品的控制信息
請參考.gitlab-ci.yml中涉及artifacts的小節,包括:
- 哪些納入到製品範圍
- 如何命名
- 過期時間
- ...
https://docs.gitlab.com/ee/ci/yaml/README.html#artifacts
四、GitLab 能力
GitLab 版本選擇 V8.17或更新的版本,GitLab Runner 選擇 V1.0或更新的版本。支持以下能力:
- 基於.gitlab-ci.yml來定義Artifacts
- 基於瀏覽器,瀏覽Artifacts
- 基於瀏覽器,下載Artifacts
- 基於瀏覽器,清除Artifacts
- 檢索特定的Artifacts
- 可以在不同 job 之間,傳遞Artifacts
注意
GitLab關於製品包大小上限及保存時間有全局默認值(100M,30天),需根據需要調整。
https://docs.gitlab.com/ee/user/admin_area/settings/continuous_integration.html#maximum-artifacts-size-core-only
https://docs.gitlab.com/ee/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration-core-only
參考鏈接
- 管理描述 https://docs.gitlab.com/ee/administration/job_artifacts.html
- 功能描述 https://docs.gitlab.com/ee/user/project/pipelines/job_artifacts.html
- 約束條件 https://docs.gitlab.com/runner/executors/#compatibility-chart)
- 執行依賴 https://docs.gitlab.com/ee/ci/yaml/README.html#dependencies
- yaml文件中如何配置製品信息 https://docs.gitlab.com/ee/ci/yaml/README.html#artifacts
- what‘s YAML https://yaml.org/