iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 23
1
Cloud Native

從零開始建立自動化發佈的流水線系列 第 23

23. 持續發佈 - Web

吉米: 前面,我們將程式檔案發佈到 DropBox 之中,那結果要發佈 Web 之類的,又要怎麼做?

Eric: 自動發佈 Web ,是很常用遇到的情境。那下面就來聊聊如何發佈 Web 吧。吉米,你還記得我們曾經寫了一支基於 .Net Core 的 WebAPI 嗎?

吉米: 記得啊,還記得那支改了很多次。

Eric: 對啊,所以接下來就那支 Web API 做為範例。


01. Travis CI

發佈的網站位置是在 Azure Web App 之中,直接採用 Traivs CI 現成的 Deploy 方式。

# .travis.yml

deploy:
  provider: azure_web_apps
  username: azure_deployment_user       # If AZURE_WA_USERNAME isn't set
  password: azure_deployment_password   # If AZURE_WA_PASSWORD isn't set
  site: azure_deployment_sitename       # If AZURE_WA_SITE isn't set
  slot: azure_deployment_slotname       # (optional) If AZURE_WA_SLOT isn't set

但是,直接將 Azure 的帳密打在 .yml 是很危險的一件事, Travis CI 建議使用 Environment Variables 的方式。

就筆者看到的實作方式,一種是使用 Travis 的 Encryption keys、另一種則是使用 Environment Variables。第一種方式,筆者沒有實驗過,有興趣的朋友可以參考延伸閱讀 5。筆者採用 Environment Variables 的方式。

https://ithelp.ithome.com.tw/upload/images/20181108/20107551cEic35jdIu.png

這時,.travis.yml 的內容如下。

# .travis.yml

deploy:
  provider: azure_web_apps
  username: $azure_id    # If AZURE_WA_USERNAME isn't set
  password: $azure_pwd   # If AZURE_WA_PASSWORD isn't set
  site: azure_deployment_sitename       # If AZURE_WA_SITE isn't set

或是在 Environment Variables 中,直接宣告 AZURE_WA_USERNAME、AZURE_WA_PASSWORD、AZURE_WA_SITE,這樣的話 .travis.yml 的內容就省略 username、password、site 。

這時,.travis.yml 中,deploy 部份的內容如下。

# .travis.yml
deploy:
  provider: azure_web_apps

02. Azure DevOps

如果點開 Build 的 log 出來看,會發現下方的 Deployments 沒有有任何設定。

在 Azure Pipelines 的 Deployments 是由 Releases 中進行設定的。

Azure_devops_Origin

在建立 Release 的第一步,就是選擇 deploy 的目標。因為要 deploy web 到 Azure App Service 之中,所以指定 Azure App Service deployment

Azure_Devops_release_1

建立完成 stage 後,記得到 Tasks 中進一步設定。

Azure_Devops_release_3

完成所有設定後,再到 Build 之中,按下 Queue 進行建置。完成後,再觀查一下 log 就可以看最下方的 Deployments 己經存在剛剛設定的 Release 了。

Azure_devops_release_4

可惜的是,筆者實作到這邊,未能在順利的處理無法順序發佈的問題。若解決,會再補上。

1541600936547


Eric: 因為是將 Web 發佈到 Azure 上,而主流的 CI Server 大多己經有現成的支援,這讓 Web 的發佈簡易很多。

吉米: 那如果要將 Web 發佈到私有的伺服器上呢?

Eric: 這時候,可能就要利用 Shell,以 command line 的方式,進行封裝與發佈的動作,就像之前發佈安裝的方式。

吉米: 嗯嗯,了解。

Eric: 以後有遇到這情況,就有設定的機會。

吉米: 哈哈哈,有備無患啊。

<<待續>>


延伸閱讀

  1. Travis Document, Script deployment
  2. Travis Document, Azure Web App Deployment
  3. Travis Document, Environment Variables
  4. FELIX RIESEBERG , Using Travis to Deploy Apps to Azure
  5. Stack overflow, Travis CI - Using repository environment variables in .travis.yml
  6. ASP.NET Web Deployment using Visual Studio: Command Line Deployment
  7. Microsoft Document, Azure Web App deployment
  8. Microsfot Document, Use the visual designer
  9. Deployment of website using Visual studio, FTP Tool, Dropbox etc. in Microsoft Azure.
  10. [Using Managed Service Identity (MSI) with an Azure App Service or an Azure Function

上一篇
22. 持續發佈 - 安裝檔
下一篇
24. 部署新境界 - 使用 Container 簡化流程
系列文
從零開始建立自動化發佈的流水線30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
not
iT邦新手 4 級 ‧ 2022-05-13 17:14:39

我是卡在 release 後,發佈上去但網站顯示 The service is unavailable.
想說來找解答找到這篇結果也是失敗哈哈,不知道經過三四年,您後來有沒有找到解法了呢?

我要留言

立即登入留言