我正在尝试构建一个使用glue_libs_4.0.0_image_01 的管道。管道中的一个步骤是运行 docker 实例,如下所示:
docker run \
--mount=type=bind,source=./test,target=/home/glue_user/workspace/test \
--mount=type=bind,source=./libs,target=/home/glue_user/workspace/libs \
-w /home/glue_user/workspace \
-e DISABLE_SSL=true \
-e "PYTHONPATH=$PYTHONPATH:/home/glue_user/workspace/deps" \
--rm -p 4040:4040 \
-p 18080:18080 \
--name glue_unit_tests docker-default-virtual.${{ vars.ARTIFACTORY_HOST }}/amazon/aws-glue-libs:glue_libs_4.0.0_image_01 \
-c "mkdir -p deps/ && pip install -r test/requirements.txt -r libs/requirements.txt -t deps/; cd test && pytest || exit 1"
尝试在
deps/
内创建 /home/glue_user/workspace
目录时遇到多个权限被拒绝错误,而且 pip
会在 pytest
尝试在已安装路径中写入缓存文件时抛出权限被拒绝错误
../deps/_pytest/cacheprovider.py:445
/home/glue_user/workspace/deps/_pytest/cacheprovider.py:445: PytestCacheWarning:无法创建缓存路径 /home/glue_user/workspace/test/.pytest_cache/v/cache/nodeids: [Errno 13]权限被拒绝:'/home/glue_user/workspace/test/.pytest_cache' config.cache.set(“缓存/nodeids”,排序(self.cached_nodeids))../deps/_pytest/stepwise.py:56
/home/glue_user/workspace/deps/_pytest/stepwise.py:56: PytestCacheWarning:无法创建缓存路径 /home/glue_user/workspace/test/.pytest_cache/v/cache/stepwise: [Errno 13]权限被拒绝:'/home/glue_user/workspace/test/.pytest_cache' session.config.cache.set(STEPWISE_CACHE_DIR, [])
原因是容器中的用户
glue_user
没有对test/
文件夹的写入权限。原因是该文件夹将拥有来自主机的所有者和组。
例如,这就是我容器上的样子:
drwxr-xr-x 2 glue_user root 4096 Nov 15 11:20 jupyter_workspace
drwxrwxr-x 2 1000 1000 4096 Apr 18 05:01 libs
drwxrwxr-x 2 1000 1000 4096 Apr 18 05:18 test
libs/
和 test/
文件夹的用户:组所有权为 1000:1000,并且活动用户 glue_user
,因此没有写入权限。
但是你可以设置不同的缓存目录。
在主机上的
test/
文件夹中创建一个 pytest.ini
文件,其中包含以下内容:
[pytest]
cache_dir = /tmp/pytest-cache/
您的项目应该具有如下结构:
├── libs
│ └── requirements.txt
└── test
├── pytest.ini
└── requirements.txt
现在,当
pytest
在容器上运行时,它将使用文件夹 /tmp/pytest-cache/
,该文件夹具有写入权限。