You’re running pip install, buildout or your automated tests within a docker container and after running it multiple times you’ve become tired of waiting for it to finally complete? Then it’s time to connect a devpi server.
Docker installation required
Docker must be installed on your system.$ docker version
Client: Docker Engine - Community
Version: 19.03.5
API version: 1.40
Go version: go1.12.12
Git commit: 633a0ea
Built: Wed Nov 13 07:22:34 2019
OS/Arch: darwin/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.5
API version: 1.40 (minimum version 1.12)
Go version: go1.12.12
Git commit: 633a0ea
Built: Wed Nov 13 07:29:19 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.2.10
GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339
runc:
Version: 1.0.0-rc8+dev
GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
docker-init:
Version: 0.18.0
GitCommit: fec3683
You’ll need a working directory where docker-compose.yml file and
certificates are stored in, so please create a folder my-devpi as
shown below:
$ mkdir -p $HOME/my-devpi/cache # store your devpi data
$ cd $HOME/my-devpi
devpi docker-compose file
I found a devpi docker image
which covers exactly what I was looking for. I really like
docker-compose to build
services. So I tried to use it for my devpi server as well. Please touch
a file called docker-compose.yml in current directory:
$ touch docker-compose.yml
and fill in following content:
devpi:
container_name: devpi
restart: always
image: sigma/devpi
ports:
- 3141:3141
volumes:
- ./data:/mnt
Of course this is overkill here, but I started to use docker-compose for every service so I don’t have to carry a docker reference card with me.
Starting devpi docker-container
Now you’re ready to run docker-compose up to start your devpi server.
Attaching -d will send it to background:
$ docker-compose up -d
Check your container is running:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
24ad92999069 sigma/devpi "/run.sh" 8 seconds ago Up 7 seconds 0.0.0.0:3141->3141/tcp devpi
Adding systemd startup script (optional)
If you’re running an operating system which supports systemd you can use following example to start your devpi server with systemd:
[Unit]
Description=devpi docker-container
Requires=docker.service
After=docker.service
[Service]
Restart=always
ExecStart=/usr/local/bin/docker-compose -f ~/my-devpi/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f ~/my-devpi/docker-compose.yml stop
ExecStopPost=/usr/local/bin/docker-compose -f ~/my-devpi/docker-compose.yml rm -f
[Install]
WantedBy=multi-user.target
Connecting your devpi server
If your devpi server is up and running you’re ready to link this container to your test container and set your index server within your buildout, pip or setuptools configuration files:
$ docker run --link devpi -it ubuntu:14.04
Configuration files are located in:
pip configuration in
~/.pip/pip.conf:[global] index-url = http://devpi:3141/root/pypi/+simple/setuptools located in
~/.pydistutils.cfg:[easy_install] index_url = http://devpi:3141/root/pypi/+simple/buildout globally in
~/.buildout/default.cfgor locally inbuildout.cfg:[buildout] index = http://devpi:3141/root/pypi/+simple/