为了确保功能,我们希望在GitHub Actions上执行out CI中的所有测试。在这里,我们配置了一个名为test的部分,它在定义的文件夹中执行pytest。这已经对“单元测试”起作用了--这意味着所有那些不需要与其他容器交互的测试。
此外,我们希望添加与容器(即数据库)交互的测试。然而,开箱即用的这是失败的,因为启动一个testcontainer失败。会引发异常,因为在testcontainers的启动脚本中,会执行POST来测试容器的准备情况。
.venv/lib/python3.8/site-packages/urllib3/connectionpool.py:392:
def request(self, method, url, body=None, headers={}, *,
encode_chunked=False):
"""Send a complete request to the server."""
> self._send_request(method, url, body, headers, encode_chunked)我们的操作如下所示:
name: Test CI
on: [push]
env:
PROJECT: test
ACTION_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
PYTHON_VERSION: 3.8
jobs:
tests:
name: Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: pytest
run: |
IMAGE_NAME="${{ env.PROJECT }}:test"
docker build . --file test.dockerfile -t $IMAGE_NAME
docker run $IMAGE_NAME发布于 2020-07-17 21:38:09
事实证明,GitHub启动的默认容器没有docker客户端。因此,解决方案的一部分是手动安装docker,将以下内容添加到dockerfile中:
RUN apt -y install docker.io此外,容器仍然无法运行 docker 容器,因为它没有自己的构建守护进程。这里的技巧是通过将 docker.sock 作为卷传递来使用 GitHub Actions 拥有的容器提供的容器。因此,我们将 CI yml 中的最后一行替换为:
docker run -v "/var/run/docker.sock":"/var/run/docker.sock" $IMAGE_NAMEhttps://stackoverflow.com/questions/62955183
复制相似问题