首页 > 解决方案 > 如何为 .NET HTTP 服务器设置 Gitlab CI 并使用 Python 进行测试?

问题描述

我正在一个项目中尝试在 C# 中设置 HTTP 服务器。来自服务器的响应使用pytest模块进行测试。
这是我到目前为止所做的:

我现在想在 gitlab 上设置 CI,然后再开始实际编写与我之前定义的路由相对应的函数。我使用 Docker 在本地机器上设置了一个 Runner(稍后将在专用服务器上)。
由于我是 CI 新手,因此我遇到了一些问题:

我知道这些问题有点疯狂,但由于我是 CI 和 Docker 的新手,我正在寻找有关如何遵循最佳实践的建议(如果有的话)。

标签: pythonasp.netdockercontinuous-integrationgitlab

解决方案


如果您未在.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.

对于你的第二个问题,这取决于你,但惯例是只提交源代码而不是依赖项/编译资源,但这只是一个惯例。建造:


推荐阅读