pycontw / pycon.tw

PyCon TW Proposal System & Backend Server
https://tw.pycon.org/prs
MIT License
95 stars 107 forks source link

Add Ansible CD using github action to deploy project on staging vm #1123

Open iknowright opened 1 year ago

iknowright commented 1 year ago

Types of changes

Description

Add a github action to deploy project to staging VM using ansible Ansible will do:

  1. check python docker module is present
  2. create target directory for docker build
  3. copy (rsync) projects files to vm
  4. build the docker image
  5. PENDING (start the service)

More Information

Please refer run action on https://github.com/iknowright/pycon.tw/actions/runs/4290521364/jobs/7474619726

mattwang44 commented 1 year ago

還沒有時間好好 review 但想要先開啟一個討論:在志工性質開發專案引入新的 tech stack (ansible here) 往往需要更謹慎(因志工普遍開發經驗較少、churn rate 也高,故維護成本希望越低越好),因此想丟幾個問題看看大家有沒有什麼意見

iknowright commented 1 year ago

👌🏻

但由於目前手動部署的方式我自己也沒有太清楚,所以在 CD 上需要小心。目前只是驗證到可以把 codebase 搬過去,並且 build image (docker-compose up 因為會牽涉一些環境變數與靜態檔案,還沒寫進去)。等大大們評估後才看看怎麼實際導入。

補充:後來發現學習成本其實蠻重的,如果 ssh-action, 對自動化不熟的志工來說就比較淺顯易懂(跑指令),ansible 就比較旋了 (跑 module)。

josix commented 1 year ago

那就再麻煩 @iknowright 協助補上有關部署、Ansible 使用操作相關的說明文件了,我們可以再下一次例會時討論那份文件,確認每個人可以 follow 文件進行操作,Thanks!

codecov-commenter commented 1 year ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (a200f81) 70.80% compared to head (b152d8f) 70.77%. Report is 5 commits behind head on master.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1123 +/- ## ========================================== - Coverage 70.80% 70.77% -0.03% ========================================== Files 85 85 Lines 3381 3381 ========================================== - Hits 2394 2393 -1 - Misses 987 988 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

iknowright commented 1 year ago

更新了,可以分為以下幾點:

  1. Ansible 的導入先從 staging VM 開始,且產生的 docker image 與 docker container 有做名稱上的區隔。
  2. 修改可以觸發 CD action 的事件, 分成兩部分: 第一: 當 master 有新的 commit (由於 PR 經過 review 後才 merge, 所以先預設上了 master 的 code 都可以被自動部署)。 第二: 管理者 自行觸發 (使用時機:如果 VM 中斷或者部署失敗,只有有權限的管理可以啟動 action;當環境變數的設定有改動後想要重新部署,則可以手動觸發)。
  3. 新增文件:給管理者設定 CD action 的文件
tyuchx commented 10 months ago

承如 Matt 所說,目前這個專案屬於志工維護性質,導入新的技術時需要審慎的考慮。

以目前的服務規模,似乎還沒有增加這個技術棧 (Ansible ) 需求 ,長期來看後面的組員也不見得有維護 Ansible 的經驗

建議改用 Github Action + SSH 的方式部署至 Instances 內。避免維護上增加未知的風險

詳細可參考此專案 google-github-actions

iknowright commented 8 months ago

Hi @tyuchx google-github-actions 其實跟 Ansible 是一樣後面都是 ssh,看起來 ssh-compute 這個套件是專門為 gcp 所設計,而 ansible 是不分平臺的。意思是這個 PR 也是 Github Action + SSH, 只是 SSH 是 ansible 而不是 ssh-compute。不過也蠻有道理 Ansible 要瞭解 playbook 的概念,ssh-compute 則是 script, 直覺上 ssh-compute 應該比較好上手?

主要是看大家是否可以掌握 CD 的精髓,而非後面工具的選擇,如果是選擇工具方面的話,我認爲 Ansible 是很好的選擇。如果要改成用 ssh-compute 我也可以協助。