当前位置: 首页 > news >正文

食品品牌网站策划九江市区

食品品牌网站策划,九江市区,门户网站栏目规范化建设,江西省兴赣建设监理咨询有限公司网站Github Actions 中 Service Container 的使用Intro之前写过一个 StackExchange.Redis 的一个扩展#xff0c;测试项目依赖 redis#xff0c;所以之前测试一直只是在本地跑一下#xff0c;最近通过 Github Action 中的 Service Container 来通过 CI 来跑测试#xff0c;分享… Github Actions 中 Service Container 的使用Intro之前写过一个 StackExchange.Redis 的一个扩展测试项目依赖 redis所以之前测试一直只是在本地跑一下最近通过 Github Action 中的 Service Container 来通过 CI 来跑测试分享一下如何使用 service container 来跑测试不仅仅是 Redis数据库等依赖也可以使用这样的方式来测试Redis Service Container Samplejobs:# 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-jobservices:# 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/checkoutv2# 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 可能就是直接访问 localhostcontainer 访问就是 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-jobservices:# 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/checkoutv2# 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-teamlatest/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/checkoutv1- name: Setup .NET Coreuses: actions/setup-dotnetv1with:dotnet-version: 5.0.x- name: dotnet inforun: dotnet --info- name: buildrun: bash build.sh --targettest CI 执行日志从日志上我们可以看出来比普通的 CI 执行会多出两个步骤一个是初始化 container一个是清理 container完整的CI 日志可以在这里看到https://github.com/WeihanLi/WeihanLi.Redis/runs/1400006789?check_suite_focustrueMore虽然我的场景是 redis但是不仅仅是 redis很多应用外的依赖比如说数据库甚至MQ等都是可以通过 service container 来做一个完善的集成测试没有尝试过的快去试试吧~~Referenceshttps://docs.github.com/en/free-pro-teamlatest/actions/guides/about-service-containershttps://docs.github.com/en/free-pro-teamlatest/actions/guides/creating-redis-service-containershttps://github.com/WeihanLi/WeihanLi.Redis/blob/dev/.github/workflows/dotnetcore.yml
http://www.huolong8.cn/news/287710/

相关文章:

  • 福建漳州东山建设局网站网站做的图上传后字变得很模糊
  • 苏州网站建设企业全国高校校园网站联盟建设
  • wordpress安装后查看站点失败订阅号自定义可以做链接网站不
  • 电子商务网站建设与管理实务目前哪个城市又封了
  • 怎么在网上建网站啊做网站php语言用什么工具
  • 如何做发表文章的网站如果网站不备案
  • 深圳企业网站网站设计评级
  • 怎么在公司网站上安装百度商桥创建网页快捷键
  • wordpress导航站模版网站建设费可以计入办公费用么
  • 周末做兼职上什么网站找营销型网站建设制作
  • 免费舆情信息网站域名大全 二级域名
  • 网站模板兼容手机端建筑资料软件
  • 哈尔滨企业做网站网站基本建设
  • 网站前期准备工作电商网站前端开发
  • 网站浏览图片怎么做北京一个公司做网站认证
  • 做h5哪些网站好 知乎他达拉非片正确服用方法
  • 番禺 建网站 360元app免费制作软件中文版
  • 怀化灵知网站建设推荐小蚁人网站建设
  • 我的网站百度怎么搜索不到河南住房和建设厅网站
  • 网站需要什么费用建地方门户网站
  • 手机网站上线左右滑动wordpress点评插件
  • 青海省建设局网站安阳论坛网
  • 建公司网站哪家公司好许昌企业网站去哪开发
  • 国家建设协会工程质量分会网站网站建设需要注意什么 知乎
  • 个人网站名可以和别人一样吗北京关键词优化报价
  • 北京孤儿院做义工网站中国建设人才服务信息网站
  • 哈尔滨百度网站快速优化北京网站建设+++招聘信息
  • 济南网站制作0531soso门户网站首页模板下载
  • 网站流量高有什么用成都微信小程序定制
  • 做网站做小程序推广一般网站图片尺寸