- Notifications
You must be signed in to change notification settings - Fork5
Docker images of the Devpi server and client program, which work as a local index and caching server for pip packages.
License
JonasAlfredsson/docker-devpi
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Docker images for bothdevpi-server
anddevpi-client
, with bothDebian and Alpine versions available.
Devpi allows you to host a local PyPi cache, along with the ability for you toadd your own packages that you do not want to upload publicly.
ℹ️ Docker tags use the same version numberings as the devpipackges on PyPi (server &client), but can be viewed on DockerHubas well:server &client.
This repository is split into two parts: theserver and theclient. You will of course need a working server before there isany point in using the client.
DEVPI_PASSWORD
: The password to set for the "root" user on init (required).
TheDEVPI_PASSWORD
environment variable will set the root password on thefirst startup of this image. Set it to something more secure than what I useas an example here.
docker run -it -p 3141:3141 \ -e DEVPI_PASSWORD=password \ -v$(pwd)/data-server:/devpi/server \ --name devpi-server jonasal/devpi-server:latest
The command will also host mount the data directory from the server to yourlocal folder, in order to persist data between restarts.
The first time this container is started a full re-index of the upstream PyPiwill commence, so the logs might be spammed with "Committing 2500 newdocuments to search index." for a while.
It is possible to customize the devpi instance with any of the availablearguments by appending them to the command displayed above:
docker run -it<...> jonasal/devpi-server:latest \ --threads 4 \ --debug
DEVPI_URL
: The URL to the devpi instance to connect to (default:http://localhost:3141/root/pypi
)DEVPI_USER
: The username to login to the devpi instance with (default:""
)DEVPI_PASSWORD
: The password for the user when logging in (default:""
)
TheDEVPI_URL
environment variable is the only one that needs to be set, andit will use the default unless you specify something else. The other two areoptional, and can be defined for convenience so you do not have to manuallylogin every time you start this container. Furthermore, ifDEVPI_USER
is setbutDEVPI_PASSWORD
is empty you will be prompted for the password.
The following command expects that there is a functional devpi instance runningon the local computer, and that the "root" user has a password set. The hostmounted directory may be used to transfer files in and out of the container.
docker run -it --rm --network host \ -e DEVPI_USER=root \ -e DEVPI_PASSWORD=password \ -v$(pwd)/data-client:/devpi/client \ jonasal/devpi-client:latest
Important note here is that this container uses the "host" network, else thelocalhost
in the URL would just make so that the container tried to contactitself and would thus not reach the container running the server program.
For a quick test to see if thedevpi-server
actually works you can make aone-off installation like this:
pip install -i http://localhost:3141/root/pypi simplejson
The server logs should move and thepip
installation should be successful.
To then make this setting a bit more permanent you can edit~/.pip/pip.conf
with this:
[global]index-url = http://localhost:3141/root/pypi
Following installations should then be going through your local cache.
By default devpi creates an index calledroot/pypi
, which serves as a proxyand cache forPyPI, and you can’t upload your own packages to it.
In order to upload local packages we need to create another index, and to makeour lives easier we will also configure it so that it "inherits" from theroot/pypi
index. What this meas is that if our search for a package in thelocal index fails it will fall back to theroot/pypi
index and try to find itthere. Thus we can add all our private packages without losing the ability tofind all the public ones.
To achieve this we will start thedevpi-client
container as root (we needto be able to make modifications):
docker run -it --rm --network host \ -e DEVPI_USER=root \ -e DEVPI_PASSWORD=password \ -v$(pwd)/data-client:/devpi/client \ jonasal/devpi-client:latest
Inside the container we will first create another user:
devpi user -clocal password=something_long_and_complicated
Then we will create an index under this new user that inherits from theroot/pypi
index:
devpi index -c local/stable bases=root/pypi volatile=False
Restart the container again, but this time specify the new index URL and thenew user:
docker run -it --rm --network host \ -e DEVPI_URL="http://localhost:3141/local/stable" \ -e DEVPI_USER=local \ -e DEVPI_PASSWORD=something_long_and_complicated \ -v$(pwd)/data-client:/devpi/client \ jonasal/devpi-client:latest
You can now upload files from the/devpi/client
folder to the current indexby running something similar to this:
devpi upload /devpi/client private_package-0.1.0-py3-none-any.whl
After this you should be able to install it by pointing to the new index:
pip install -i http://localhost:3141/local/stable private_package
⚠️ This is semi-experimental since I am having trouble findingofficial documentation on the proper way to do this.
The best guide on upgrading devpi server I could find wasthis one, soI tried to integrate that into the entrypoint. It is not very automated, butyou will at least have full control of what it is doing the entire time.
ℹ️ You should also only have to do this procedure whenthere is a change in the database schema. Such a changewill warrant amajor version bump, so this process is not necessary if you are justupgrading aminor or apatch version.
Begin by stopping any of the currently running devpi containers, and then runthe same image again with the/export
folder mounted to initiate an exportprocess:
docker run -it --rm -e DEVPI_PASSWORD=password \ -v$(pwd)/data-server:/devpi/server \ -v$(pwd)/tmp:/export \ jonasal/devpi-server:old-tag
If this is successful you should now rename the old data folder (don't deleteit before you know the new one works):
sudo mv data-server data-server.bak
Run the new image with the/import
folder mounted in order to initiate animport process:
docker run -it --rm -e DEVPI_PASSWORD=password \ -v$(pwd)/data-server:/devpi/server \ -v$(pwd)/tmp:/import \ jonasal/devpi-server:new-tag
When this one completes you can go back to running the image normally withoutany of theimport/export
folders mounted. This should most likely give you afunctional upgraded instance of devpi. Cleanup of the extra folders can be donewith this simple command
sudo rm -r data-server.bak&& sudo rm -r tmp
I got most of the information I needed to complete this project from thefollowing sources, perhaps they are useful for you too:
About
Docker images of the Devpi server and client program, which work as a local index and caching server for pip packages.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.