Connect devpi to your docker container

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.

Prerequisites

Note

If you’re running a Mac, please prepare a docker-machine first, please use docker-machine installation guide.

$ docker-machine create -d virtualbox dev
$ docker-machine start dev
$ eval $(docker-machine env dev)

Test your docker-machine by running docker ps command.

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.cfg or locally in buildout.cfg:

    [buildout]
    index = http://devpi:3141/root/pypi/+simple/
    

Comments

comments powered by Disqus