简体   繁体   中英

Install private library to python docker image

I have git private repo, which python project and it has setup.py and setup.cfg .

Tree structure as

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

Files in src are empty.

deployment/dockerfiles/py/Dockerfile

FROM python:3.7

ADD . .

RUN pip3 install --upgrade pip pbr && pip3 install --no-cache-dir --compile --editable .

This is the simple, but I don't know why it stuck somewhere when I try to build image.

$ 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:///

I waited for 1 hour but it never pass this Obtaining file:///

Since default dir in the container is root: / I would recommend making the following changes to 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM