方便地从存储库提供静态文件?

问题描述 投票:0回答:1

考虑

test.py

import unittest
import os

import src.dl_latest_data

if 'PREFIX_OVERRIDE' in os.environ:
    PREFIX_OVERRIDE = os.environ['PREFIX_OVERRIDE']
else:
    PREFIX_OVERRIDE = 'http://localhost:8000/'

src.dl_latest_data.DATA_URL_PREFIX = PREFIX_OVERRIDE


from src.__main__ import main


class TestMain(unittest.TestCase):
    def test_main_does_not_crash(self):
        main()


if __name__ == '__main__':
    unittest.main()

gitlab-ci.yml

stages:
  - test

run_tests:
  stage: test
  image: python
  script:
    - pip install -r requirements-dev.txt
    - pip install -r requirements.txt
    - python3 -m unittest

我想在

python3 test.py
script
部分运行
gitlab-ci.yml
,最终将从
PREFIX_OVERRIDE
中指定的路径下载。运行从
testcases
目录中提供文件的 HTTP 服务的惯用方法是什么?

gitlab-ci
1个回答
0
投票

在等待更好的解决方案时,我想出了构建自己的 Docker 容器并将其发布到 Docker Hub 中。这是源代码:

Dockerfile

FROM python:3.13
EXPOSE 8000
ADD ./main.sh /main.sh
ENTRYPOINT ["/main.sh"]

main.sh

#!/bin/bash

cd $DIRECTORY
python3 -m http.server $@

现在,

.gitlab-ci.yml
的相关部分如下所示:

run_tests:
  stage: test
  image: python
  variables:
    DIRECTORY: /builds/$CI_PROJECT_PATH/testsample
    PREFIX_OVERRIDE: http://httpserver:8000/
  services:
    - name: d33tah/python-http-server
      alias: httpserver
  script:
    - pip install -r requirements-dev.txt
    - pip install -r requirements.txt
    - python3 -m unittest
© www.soinside.com 2019 - 2024. All rights reserved.