python - 如何为 .NET HTTP 服务器设置 Gitlab CI 并使用 Python 进行测试?
问题描述
我正在一个项目中尝试在 C# 中设置 HTTP 服务器。来自服务器的响应使用pytest
模块进行测试。
这是我到目前为止所做的:
- 使用 swagger 编辑器定义 API
- 使用 swagger 生成器生成基本代码
- 编写一些
python
向服务器发送请求并测试响应是否满足某些要求的测试
我现在想在 gitlab 上设置 CI,然后再开始实际编写与我之前定义的路由相对应的函数。我使用 Docker 在本地机器上设置了一个 Runner(稍后将在专用服务器上)。
由于我是 CI 新手,因此我遇到了一些问题:
- 由于我需要 Python 和 .NET 进行测试,我应该选择 .NET 作为基础镜像,然后安装 Python 还是 Python 作为基础镜像,然后安装 .NET?什么会更容易?我尝试了后者,但它似乎不是很优雅......
- 我是在推送到远程存储库之前构建并将
/bin
文件夹包含在我的存储库中以执行这些文件,还是我宁愿在 CI 期间构建,因此除了源代码之外不需要推送任何东西?
我知道这些问题有点疯狂,但由于我是 CI 和 Docker 的新手,我正在寻找有关如何遵循最佳实践的建议(如果有的话)。
解决方案
如果您未在.gitlab-ci.yml
文件中指定一个,则跑步者的基本图像只是默认值。您可以通过在.gitlab-ci.yml
文件顶部(在任何作业之外)使用“管道默认”图像来覆盖跑步者的默认图像,或者您可以单独为每个作业指定图像。
使用“管道默认”图像:
image: python:latest
stages:
- build
...
在此示例中,所有作业都将使用该python:latest
图像,除非该作业指定自己的图像,如下例所示:
stages:
- build
- test
Build Job:
stage: build
image: python:latest
script:
- ...
在这里,这个作业覆盖了跑步者的默认值。
image: python:latest
stages:
- build
- db_setup
Build Job:
stage: build
script:
- # run some build steps
Database Setup Job:
stage: db_setup
image: mysql:latest
script:
- mysql -h my-host.example.com -u my-user -pmy-password -e "create database my-database;"
在此示例中,我们有一个“构建作业”使用的“管道默认”图像,因为它没有指定自己的图像,但“数据库设置作业”使用该mysql:latest
图像。
这是跑步者的默认图像的示例ruby:latest
stages:
- build
- test
Build Job:
stage: build
script:
- # run some build steps
Test Job:
stage: test
image: golang:latest
script:
- # run some tests
在最后一个示例中,“构建作业”使用运行器的基本映像,ruby:latest
但“测试作业”使用golang:latest
.
对于你的第二个问题,这取决于你,但惯例是只提交源代码而不是依赖项/编译资源,但这只是一个惯例。建造:
推荐阅读
- c - 如何使用 free 释放使用 malloc 进行的堆分配?
- swift - 基于单元的基于视图的 NSTableView 的内存问题
- amazon-web-services - Amazon Sumerian 能否对来自 Amazon SNS 的事件做出反应,还是 IoT 是我唯一的途径?
- android - android post数据发送中的连接拒绝
- r - 如何根据行和列总数获得所有可能的单元格频率组合
- javascript - 如何根据输入的值从状态中过滤数据
- rust - 重载运算符所需的 T、&T 和 &mut T 中的最小对
- python - 新项目检查缺少的 ID 并创建它
- java - 有什么方法可以将 smali 转换为 java 进行编辑,反之亦然
- google-cloud-sql - gcloud beta run deploy 成功上传图片后失败,无法启用 API