将私有库安装到 python docker 图像
Install private library to python docker image
我有 git 私人仓库,其中有 python 项目,它有 setup.py
和 setup.cfg
。
树结构为
bsNotify/
├── deployment
│ └── dockerfiles
│ └── py
│ └── Dockerfile
├── setup.cfg
├── setup.py
└── src
└── bsnotify
├── __init__.py
└── resources.py
setup.py
$ cat bsNotify/setup.py
"""Base module setup."""
from setuptools import setup
setup(
setup_requires=['pbr'],
pbr=True
)
setup.cfg
$ cat bsNotify/setup.cfg
[metadata]
name = bsNotify
classifiers =
License :: N/A :: N/A
Programming Language :: Python :: 3.7
[options]
zip_safe = False
include_package_data = True
python_requires = >= 3.7
install_requires =
mongoengine
bson
package_dir=
=src
packages=find:
[options.packages.find]
where=src
[tool:wheel]
universal = 1
[flake8]
exclude =
venv,
.tox,
.git,
__pycache__,
*.pyc,
*.egg-info,
.cache,
.eggs,
max-line-length = 80
[tox]
envlist = py37,unittest,lint
[testenv]
basepython=python3.7
deps =
ipython
pylint
pytest
pytest-cov
pytest-xdist
flake8
flake8-docstrings
[testenv:unittest]
commands=
pytest -v -s -n auto -l --cov=bsnotify --cov-report term-missing --cov-report xml --no-cov-on-fail tests/unit
[testenv:lint]
commands=
flake8 src/bsnotify
pylint src/bsnotify
src/bsnotify/init.py
$ cat bsNotify/src/bsnotify/__init__.py
src/bsnotify/resources.py
$ cat bsNotify/src/bsnotify/resources.py
src
中的文件为空。
deployment/dockerfiles/py/Dockerfile
FROM python:3.7
ADD . .
RUN pip3 install --upgrade pip pbr && pip3 install --no-cache-dir --compile --editable .
这很简单,但我不知道为什么当我尝试构建图像时卡在某个地方。
$ docker build -f deployment/dockerfiles/py/Dockerfile .
Sending build context to Docker daemon 60.06MB
Step 1/3 : FROM python:3.7
---> 8e3336637d81
Step 2/3 : ADD . .
---> 287d4e44a735
Step 3/3 : RUN pip3 install --upgrade pip pbr && pip3 install --no-cache-dir --compile --editable .
---> Running in cbf3c92083de
Collecting pip
Downloading pip-20.1.1-py2.py3-none-any.whl (1.5 MB)
Collecting pbr
Downloading pbr-5.4.5-py2.py3-none-any.whl (110 kB)
Installing collected packages: pip, pbr
Attempting uninstall: pip
Found existing installation: pip 20.0.2
Uninstalling pip-20.0.2:
Successfully uninstalled pip-20.0.2
Successfully installed pbr-5.4.5 pip-20.1.1
Obtaining file:///
我一直在等待 1 hour
但它从未通过 Obtaining file:///
由于容器中的默认目录是根目录:/
我建议对 Dockerfile
进行以下更改
FROM python:3.7
# then scope of work is just reduced to this directory
WORKDIR /mypackage
ADD . .
RUN pip3 install --upgrade pip pbr && pip3 install --no-cache-dir --compile --editable .
我有 git 私人仓库,其中有 python 项目,它有 setup.py
和 setup.cfg
。
树结构为
bsNotify/
├── deployment
│ └── dockerfiles
│ └── py
│ └── Dockerfile
├── setup.cfg
├── setup.py
└── src
└── bsnotify
├── __init__.py
└── resources.py
setup.py
$ cat bsNotify/setup.py
"""Base module setup."""
from setuptools import setup
setup(
setup_requires=['pbr'],
pbr=True
)
setup.cfg
$ cat bsNotify/setup.cfg
[metadata]
name = bsNotify
classifiers =
License :: N/A :: N/A
Programming Language :: Python :: 3.7
[options]
zip_safe = False
include_package_data = True
python_requires = >= 3.7
install_requires =
mongoengine
bson
package_dir=
=src
packages=find:
[options.packages.find]
where=src
[tool:wheel]
universal = 1
[flake8]
exclude =
venv,
.tox,
.git,
__pycache__,
*.pyc,
*.egg-info,
.cache,
.eggs,
max-line-length = 80
[tox]
envlist = py37,unittest,lint
[testenv]
basepython=python3.7
deps =
ipython
pylint
pytest
pytest-cov
pytest-xdist
flake8
flake8-docstrings
[testenv:unittest]
commands=
pytest -v -s -n auto -l --cov=bsnotify --cov-report term-missing --cov-report xml --no-cov-on-fail tests/unit
[testenv:lint]
commands=
flake8 src/bsnotify
pylint src/bsnotify
src/bsnotify/init.py
$ cat bsNotify/src/bsnotify/__init__.py
src/bsnotify/resources.py
$ cat bsNotify/src/bsnotify/resources.py
src
中的文件为空。
deployment/dockerfiles/py/Dockerfile
FROM python:3.7
ADD . .
RUN pip3 install --upgrade pip pbr && pip3 install --no-cache-dir --compile --editable .
这很简单,但我不知道为什么当我尝试构建图像时卡在某个地方。
$ docker build -f deployment/dockerfiles/py/Dockerfile .
Sending build context to Docker daemon 60.06MB
Step 1/3 : FROM python:3.7
---> 8e3336637d81
Step 2/3 : ADD . .
---> 287d4e44a735
Step 3/3 : RUN pip3 install --upgrade pip pbr && pip3 install --no-cache-dir --compile --editable .
---> Running in cbf3c92083de
Collecting pip
Downloading pip-20.1.1-py2.py3-none-any.whl (1.5 MB)
Collecting pbr
Downloading pbr-5.4.5-py2.py3-none-any.whl (110 kB)
Installing collected packages: pip, pbr
Attempting uninstall: pip
Found existing installation: pip 20.0.2
Uninstalling pip-20.0.2:
Successfully uninstalled pip-20.0.2
Successfully installed pbr-5.4.5 pip-20.1.1
Obtaining file:///
我一直在等待 1 hour
但它从未通过 Obtaining file:///
由于容器中的默认目录是根目录:/
我建议对 Dockerfile
FROM python:3.7
# then scope of work is just reduced to this directory
WORKDIR /mypackage
ADD . .
RUN pip3 install --upgrade pip pbr && pip3 install --no-cache-dir --compile --editable .