A way to build a local pypi source using docker+devpi

  • 2021-01-19 22:34:44
  • OfStack

The first period of development requires the use of pip download, although the pip source has been changed to a domestic source, but I am not satisfied with the speed, more important is the integration
The test environment is offline, and developing in the integrated test environment obviously requires setting up your own local pip source. Before using devpi, I used pip2pi, but there was one bug which caused the tox command to always fail in offline environment, so I finally used devpi to build the pip source. Here use docker deployment, convenient and fast, if accidentally crashed also need to re-run docker container is good. If you do not have docker installed in your environment, you can search for the installation method yourself, such as the docker community documentation install docker. If you are Centos user, you can use the following method to install


sudo yum update
sudo yum -y install docker
sudo systemctl enable docker
sudo systemctl start docker

The next step is to deploy an Python local image source using docker. We can use the existing image on docker, which I chose here
muccg/devpi is the mirror image


#  Set up the  devpi  Server Administrator Password 
DEVPI_PASSWORD = 123

mkdir -p /src/docker/devpi
mkdir /tmp/wheelhouse

docker run -d --name devpi \
  --publish 3141:3141 \
  --volume /tmp/wheelhouse:/wheelhouse
  --volume /srv/docker/devpi:/data \
  --env=DEVPI_PASSWORD=$DEVPI_PASSWORD \
  --restart always \
  muccg/docker-devpi

Then download the required wheel package locally first. The contents of requirements.txt file are the list of Python libraries we need


pip wheel --wheel-dir /tmp/wheelhouse -r requirements.txt

If the library downloaded from the pip source is already in the wheel package, the file will be placed directly in /tmp/wheelhouse, if so
tar package, pip will release wheel package first build, which may take some time. The content of wheelhouse will be similar after downloading
in


ll /tmp/wheelhouse
total 524K
-rwxrwxrwx 1 rookie rookie 155K Apr 6 23:40 certifi-2019.3.9-py2.py3-none-any.whl
-rwxrwxrwx 1 rookie rookie 131K Apr 6 23:40 chardet-3.0.4-py2.py3-none-any.whl
-rwxrwxrwx 1 rookie rookie 58K Apr 6 23:40 idna-2.8-py2.py3-none-any.whl
-rwxrwxrwx 1 rookie rookie 57K Apr 6 23:40 requests-2.21.0-py2.py3-none-any.whl
-rwxrwxrwx 1 rookie rookie 116K Apr 6 23:40 urllib3-1.24.1-py2.py3-none-any.whl

If the ES53en client is installed in the local environment after the download, you can upload the ES54en package directly, but we have already done so when we created the container

the wheelhouse Folders are mounted inside, and can be manipulated directly inside the container


#  Into the container 
docker exec -it -u root devpi bash

#  Log in and upload 
devpi use http://<host_ip>:3141/root/public --set-cfg
devpi login root 123
devpi upload --from-dir /wheelhouse

It can be used after uploading http://<host_ip>:3141 View the status of the pip local source server.

To use it temporarily, you can use the --index and -- trusted-host options of pip install


pip install --index http://<host_ip>:3141/root/public/+simple/ \
      --trusted-host <host_ip>

Or modify the pip. conf file for permanent use


# vim ~/.pip/pip.conf
[global]
index_url = http://<host_ip>:3141/root/public/+simple/
trusted-host = <host_ip>
[search]
index = http://<host_ip>:3141/root/public/

Related articles: