日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Github Actions 中 Service Container 的使用

發布時間:2023/12/4 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Github Actions 中 Service Container 的使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Github Actions 中 Service Container 的使用

Intro

之前寫過一個 StackExchange.Redis 的一個擴展,測試項目依賴 redis,所以之前測試一直只是在本地跑一下,最近通過 Github Action 中的 Service Container 來通過 CI 來跑測試,分享一下如何使用 service container 來跑測試,不僅僅是 Redis,數據庫等依賴也可以使用這樣的方式來測試

Redis Service Container Sample

jobs:#?Label?of?the?runner?jobrunner-job:#?You?must?use?a?Linux?environment?when?using?service?containers?or?container?jobsruns-on:?ubuntu-latest#?Service?containers?to?run?with?`runner-job`services:#?Label?used?to?access?the?service?containerredis:#?Docker?imageimage:?redis:alpine#?Set?health?checks?to?wait?until?redis?has?startedoptions:?>---health-cmd?"redis-cli?ping"--health-interval?10s--health-timeout?5s--health-retries?5ports:#?Maps?port?6379?on?service?container?to?the?host-?6379:6379

上面是一個 redis service container 配置示例的一部分,需要注意的是使用 service container 的時候必須要使用 Linux 環境,因為 service container 的本質就是 docker run 了一個 container,通過一定的規則配置來實現在跑 CI 的環境可以訪問的這個 service

上面的示例配置了一個 redis 的 service container,并將容器服務的 6379 端口映射到 host 的 6379 端口,這樣 host 上的服務就可以通過 127.0.0.1:6379/localhost:6379 訪問到使用 docker 跑起來的 ?redis 服務(redis service container)了

steps:#?Downloads?a?copy?of?the?code?in?your?repository?before?running?CI?tests-?name:?Check?out?repository?codeuses:?actions/checkout@v2#?Performs?a?clean?installation?of?all?dependencies?in?the?`package.json`?file#?For?more?information,?see?https://docs.npmjs.com/cli/ci.html-?name:?Install?dependenciesrun:?npm?ci-?name:?Connect?to?Redis#?Runs?a?script?that?creates?a?Redis?client,?populates#?the?client?with?data,?and?retrieves?datarun:?node?client.js#?Environment?variable?used?by?the?`client.js`?script?to?create#?a?new?Redis?client.env:#?The?hostname?used?to?communicate?with?the?Redis?service?containerREDIS_HOST:?localhost#?The?default?Redis?portREDIS_PORT:?6379

Container Job Sample

上面的這種形式是在 host 上跑的,也就是直接在跑 CI 的服務器上跑的,有些情況下環境的配置比較麻煩的情況下也可以直接在指定的 docker 鏡像為基礎的 docker container 里跑 CI,需要注意的是 docker container 里跑 CI 的時候和直接在 host 上跑 CI 網絡上有區別, host 可能就是直接訪問 localhost,container 訪問就是 service 名稱,來看下面的 container 的一個示例:

jobs:#?Label?of?the?container?jobcontainer-job:#?Containers?must?run?in?Linux?based?operating?systemsruns-on:?ubuntu-latest#?Docker?Hub?image?that?`container-job`?executes?incontainer:?node:10.18-jessie#?Service?containers?to?run?with?`container-job`services:#?Label?used?to?access?the?service?containerredis:#?Docker?Hub?imageimage:?redis#?Set?health?checks?to?wait?until?redis?has?startedoptions:?>---health-cmd?"redis-cli?ping"--health-interval?10s--health-timeout?5s--health-retries?5

可以看到大部分是一樣的,只是多了一個 container 的配置,這樣實際的 CI 就是在這個 container 里執行的,創建的執行 CI 的 container 和 service container 是在同一個 network 下,可以直接通過服務名稱來訪問

steps:#?Downloads?a?copy?of?the?code?in?your?repository?before?running?CI?tests-?name:?Check?out?repository?codeuses:?actions/checkout@v2#?Performs?a?clean?installation?of?all?dependencies?in?the?`package.json`?file#?For?more?information,?see?https://docs.npmjs.com/cli/ci.html-?name:?Install?dependenciesrun:?npm?ci-?name:?Connect?to?Redis#?Runs?a?script?that?creates?a?Redis?client,?populates#?the?client?with?data,?and?retrieves?datarun:?node?client.js#?Environment?variable?used?by?the?`client.js`?script?to?create?a?new?Redis?client.env:#?The?hostname?used?to?communicate?with?the?Redis?service?containerREDIS_HOST:?redis#?The?default?Redis?portREDIS_PORT:?6379

Sample

提供一個我目前在用的一個 service container,和上面的示例基本是類似的,有需要的可以參考一下:

name:?dotnetcoreon:?[push]jobs:#?Label?of?the?container?jobredis-integration-test:#?Containers?must?run?in?Linux?based?operating?systemsruns-on:?ubuntu-latest#?#?Docker?image?that?`job`?executes?in#?container:?mcr.microsoft.com/dotnet/sdk:5.0#?Service?containers?to?run?with?`container-job`#?https://docs.github.com/en/free-pro-team@latest/actions/guides/creating-redis-service-containersservices:#?Label?used?to?access?the?service?containerredis:#?Docker?Hub?imageimage:?redis:alpine#?Set?health?checks?to?wait?until?redis?has?startedoptions:?>---health-cmd?"redis-cli?ping"--health-interval?10s--health-timeout?5s--health-retries?5ports:#?Maps?port?6379?on?service?container?to?the?host-?6379:6379steps:-?uses:?actions/checkout@v1-?name:?Setup?.NET?Coreuses:?actions/setup-dotnet@v1with:dotnet-version:?5.0.x-?name:?dotnet?inforun:?dotnet?--info-?name:?buildrun:?bash?build.sh?--target=test

CI 執行日志:

從日志上我們可以看出來比普通的 CI 執行會多出兩個步驟,一個是初始化 container,一個是清理 container

完整的CI 日志可以在這里看到:https://github.com/WeihanLi/WeihanLi.Redis/runs/1400006789?check_suite_focus=true

More

雖然我的場景是 redis,但是不僅僅是 redis,很多應用外的依賴比如說數據庫,甚至MQ等都是可以通過 service container 來做一個完善的集成測試,沒有嘗試過的快去試試吧~~

References

  • https://docs.github.com/en/free-pro-team@latest/actions/guides/about-service-containers

  • https://docs.github.com/en/free-pro-team@latest/actions/guides/creating-redis-service-containers

  • https://github.com/WeihanLi/WeihanLi.Redis/blob/dev/.github/workflows/dotnetcore.yml

總結

以上是生活随笔為你收集整理的Github Actions 中 Service Container 的使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: av小说免费在线观看 | 日日操天天射 | 久久av高潮av无码av喷吹 | 91精品一区二区三 | 这里只有久久精品 | 精品人妻一区二区三区麻豆91 | 色噜噜狠狠狠综合曰曰曰 | 天天做夜夜爱 | 精品一区亚洲 | 国产成人无码一区二区在线播放 | 一级片aaaaa 国产又黄又粗又猛又爽 | 久久精品国产精品亚洲色婷婷 | 久热这里只有精品在线 | 国产一级淫片免费 | 91色噜噜| 国产精品久久国产精麻豆96堂 | 亚洲综合av网 | 小辣椒导航 | 麻豆传媒视频入口 | 欧美成人三级在线视频 | 爱情岛论语亚洲入口 | 视频成人免费 | 国产丰满农村老妇女乱 | 丰满岳乱妇一区二区 | 伊人网在线 | 男人天堂视频网站 | 日本a级片网站 | 成人av动漫在线 | 免费看黄色a级片 | 噼里啪啦免费高清看 | 国产精品羞羞答答 | 成人一级视频在线观看 | 毛片91 | 日韩视频一区二区三区四区 | 91视频最新| 成人一区二区在线 | 国产51自产区 | 四虎精品久久 | 探花国产 | 国产欧美在线观看 | 欧美aa | 欧美日韩二区三区 | 免费av成人| 欧美v亚洲 | 丰满少妇熟乱xxxxx视频 | 国产一级生活片 | 国产96在线 | 亚洲 | 国产精品入口66mio男同 | 亚洲激情精品 | 国产v亚洲v天堂无码久久久 | 91一区二区在线 | 国产区精品视频 | 亚洲精品男女 | 蜜桃一区二区 | 探花国产 | 成人小视频在线免费观看 | 日韩一区二区影院 | 136fldh导航福利微拍 | jlzzjlzzjlzz亚洲人 | 亚洲精品一级二级 | 午夜精彩视频 | 狠狠久久 | 国产精品婷婷午夜在线观看 | 欧美性大战久久久久久久 | 欧美二三区 | 调教91| 国产精品久久久久毛片大屁完整版 | 91在线公开视频 | 国产成人精品一区二区在线小狼 | 国产一线二线三线在线观看 | 亚洲少妇第一页 | 亚洲国产日韩av | 激情国产精品 | 在线观看你懂的视频 | 国产亚洲精品电影 | 玖玖视频 | 美日韩毛片 | 欧美日韩高清在线 | 99热播 | 久久精品国产99国产 | 亚洲精品97久久中文字幕 | 直接看毛片 | 国产精品久久久久不卡 | 五月婷婷激情小说 | 91av看片| 波多野结衣午夜 | 特级毛片a | 久久久国产精品成人免费 | 免费看黄网站在线 | 成人无码av片在线观看 | 国产综合精品在线 | 超碰在线免费 | 最新中文在线视频 | 国产伦精品一区二区三区视频免费 | 亚洲AV永久无码国产精品国产 | 五月婷婷综合久久 | 久久夜色精品 | 哺乳喂奶一二三区乳 | 色偷偷91 |