iT邦幫忙

2023 iThome 鐵人賽

DAY 24
0
DevOps

Azure DevOps Troubleshooting and best practices 系列 第 24

Azure Artifacts – 以 nuget 為例的實作

  • 分享至 

  • xImage
  •  

前言

前一篇 Azure Artifacts – 為何團隊需要 Package Management 有簡單介紹什麼是 Azure Artifact,但個人覺得比較重要的功能在於當沒有此套件時,可以從上游 (即公開套件儲存庫) 下載並儲存一分至 Azure Artifact,讓團隊可以快取使用,而不會因為外部儲存庫因某些因素移除或更改後,突然間造成 Pipeline 錯誤發生。雖然這種錯誤發生機會不多,但一旦發生輕則 Build 發生錯誤,重則造成 runtime 錯誤造成 downtime,不得不謹慎。

此類型錯誤也很難發現 root cause,往往查案耗時費力

 
 

實作

Azure Artifact 主要觀念在於摘要 (Feed),用於儲存、管理與分組套件,可以控制可以使用的團隊成員。單一摘要可以支援多種套件類型 (npm、NuGet、Maven、Python... etc.)。使用者可以在 Azure Artifact 功能內點選 Create Feed 按鈕以建立摘要。
https://ithelp.ithome.com.tw/upload/images/20231010/20091494vR3jTKsPIM.png

https://ithelp.ithome.com.tw/upload/images/20231010/20091494k384mKIMoy.png

 

上游來源 (Upstream Sources) 讓您可以使用單一摘要來儲存私有的套件與遠端/公開儲存庫的套件

Public Feed: npmjs.com 與 nuget.org

https://ithelp.ithome.com.tw/upload/images/20231010/20091494KJUyNkUnqp.png

https://ithelp.ithome.com.tw/upload/images/20231010/20091494OoKFuDc6j0.png

 

連結至摘要 (Connect to Feed) 則是會教導使用者各種套件工具如何連接至已經建立好的摘要
https://ithelp.ithome.com.tw/upload/images/20231010/20091494Ds9MSeYCSG.png

https://ithelp.ithome.com.tw/upload/images/20231010/20091494ca7aQvETsx.png

 
 

Azure Artiface - Nuget 實作

.NET 開發過程中安裝套件可以分重兩種類型:透過 UI (Visual Studio) 與 Command line (dotnet.exe, nuget.ext 或 Package Manager Console)。雖然過程有點不盡相同,但實際上設定檔案內容是一致的。

https://ithelp.ithome.com.tw/upload/images/20231010/20091494m19KCqW8MC.png

 

你可以在 Azure Artifact 選擇要連接的摘要,點選 Connect to Feed,點選 nuget 即有說明不同類型開發環境如何連接至此摘要。以 dotnet 為例,即可顯示前置作業與專案內如何安裝設定。

以下圖為例,其中步驟 2 為前置作業、步驟 3 為專案內如何安裝設定

https://ithelp.ithome.com.tw/upload/images/20231010/20091494DJqCn1TbtC.png

 

前置作業大致上是安裝最新版本 .NET Core SDK 或 nuget,並且安裝 Credential provider (用於驗證)
https://ithelp.ithome.com.tw/upload/images/20231010/20091494nha2wAfTiK.png

 

專案安裝主要是設定 nuget.config 檔案,設定其摘要來源。後續只需要進行 Restore 即可從 Azure Artifact 摘要下載套件。
https://ithelp.ithome.com.tw/upload/images/20231010/20091494Y5uwHAeFyQ.png

 
 

注意費用

Azure Artifact 的容量並非無限制使用,要注意免費版本只提供 2GB。老實說這個對於組織相當不足,若確認使用需要謹慎評估費用
https://ithelp.ithome.com.tw/upload/images/20231010/200914940PtUVuw6bc.png


上一篇
Azure Artifacts – 為何團隊需要 Package Management
下一篇
Azure Pipeline 危機處理 - 使用者不能不知道 Roll back 操作
系列文
Azure DevOps Troubleshooting and best practices 30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言