This guide follow instructions in the devpi quickstart server guide. We will install in own user home using virtualenvs, than, will setup a nginx instance. Server used here is Ubuntu Server 12.04 LTS in one virtualbox instance.
root ~ # useradd -m -U -s /bin/bash devpi
root ~ # passwd devpi
We must setup stuff in virtualenvs because it is easy to restart if have some problem and keep stuff local, not system wide. Virtualenvwrapper turn it more simple.
root ~ # apt-get install python-virtualenv virtualenvwrapper
Now we will log in devpi user, setup virtualenvwrapper and virtualenv.
root ~ # su - devpi
devpi ~ $ pwd
/home/devpi
I sugest create a project for devpi instance using virtualenvwrapper mkproject command:
devpi ~ $ mkdir -p projects/devpi
devpi ~ $ echo "export PROJECT_HOME='${HOME}/projects'" >> ~/.bashrc
devpi ~ $ source .bashrc
devpi ~ $ mkproject devpi
New python executable in devpi/bin/python
Installing distribute.............................................................................................................................................................................................done.
Installing pip...............done.
virtualenvwrapper.user_scripts creating /home/devpi/.virtualenvs/devpi/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/devpi/.virtualenvs/devpi/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/devpi/.virtualenvs/devpi/bin/preactivate
virtualenvwrapper.user_scripts creating /home/devpi/.virtualenvs/devpi/bin/postactivate
virtualenvwrapper.user_scripts creating /home/devpi/.virtualenvs/devpi/bin/get_env_details
Setting project for devpi to projects/devpi/
Creating /home/devpi/projects/devpi
Setting project for devpi to /home/devpi/projects/devpi
Now we are on virtualenv:
(devpi) devpi ~/projects/devpi $ which python
/home/devpi/.virtualenvs/devpi/bin/python
(devpi) devpi ~/projects/devpi $ python --version
Python 2.7.3
Finally we are on same steps that the guide.
(devpi) devpi ~/projects/devpi $ pip install devpi-server
.
.
.
Successfully installed devpi-server py devpi-common execnet itsdangerous docutils pygments bottle requests
Cleaning up..
Now set the devpi root password. Root password is used by client.
(devpi) devpi ~/projects/devpi $ devpi-server --passwd root
enter password for root: 123
repeat password for root: 123
At this point, the guide tell us to create virtualenv, that we already did so let's move over this step that should use gendeploy, but it also not works here and is deprecated, so let's move step by step. The configuration files used here is based on the files that came with devpi-server package.
As root (open in another shell), install supervisor:
root ~ $ apt-get install supervisor
Then we add a new file to supervisor conf directory, the /etc/supervisor/conf.d/devpi-server.conf
[program:devpi-server]
command=/home/devpi/.virtualenvs/devpi/bin/devpi-server --port 4040 --serverdir /home/devpi/projects/devpi/data
priority=999
startsecs = 5
redirect_stderr = True
autostart=False
Reload supervisor and devpi-server should be STOPPED:
root ~ $ supervisorctl reload
Restarted supervisord
root ~ $ supervisorctl status
devpi-server STOPPED Not started
There is many possible configurations to use with nginx. We will keep it simple and will configure to listen on port 8080. If you have a dedicated server, you probably want it to listen in port 80 in place of nginx default site, or using a dns name for your site.
As root, install nginx:
root ~ $ apt-get install nginx
Then we add new file to nginx sites-avaliable directory, the /etc/nginx/sites-available/devpi.conf:
server {
server_name localhost;
listen 8080;
gzip on;
gzip_min_length 2000;
gzip_proxied any;
gzip_types application/json;
client_max_body_size 30M;
root %(serverdir)s;
# try serving docs and (md5/immutable) directly
location ~ \+(f|doc)/ {
try_files $uri @proxy_to_app;
}
location / {
# XXX how to tell nginx to just refer to @proxy_to_app here?
try_files /.lqkwje @proxy_to_app;
}
location @proxy_to_app {
proxy_pass http://localhost:4040;
proxy_set_header X-outside-url $scheme://$host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Now, create a symlink to sites-enabled:
root ~ $ ln -s /etc/nginx/sites-available/devpi.conf /etc/nginx/sites-enabled/devpi.conf
And restart nginx if configtest pass (never, never restart nginx if configtest dont pass):
root ~ $ service nginx configtest
Testing nginx configuration: nginx.
root ~ $ service nginx restart
Restarting nginx: nginx.
To test if configurations is working start devpi-server with supervisorctl and make a request to localhost:8080:
root ~ $ supervisorctl start devpi-server
devpi-server: started
root ~ $ supervisorctl status
devpi-server RUNNING pid 4501, uptime 0:00:08
root ~ $ curl http://localhost:8080
{
"type": "list:userconfig",
"result": {
"root": {
"username": "root",
"indexes": {
"pypi": {
"type": "mirror",
"acl_upload": [
"root"
],
"bases": [],
"volatile": false,
"uploadtrigger_jenkins": null
}
}
}
}
}
If you saw that json, devpi is ok. If devpi has issues, you will see 502 bad gateway error. If nginx has issues, you will see curl error 7. In both cases, check what happened in the logs.
You need devpi-client to manage indexes and users. You can do it in your own machine, not in server. I'm doing this in my notebook with system wide install, and asserting that use python 2.7 instead python 3.3:
felipe ~/ $ sudo pip-2.7 install devpi-client
.
.
.
Successfully installed devpi-client tox devpi-common pkginfo twine py requests
Cleaning up...
After installed, set devpi to use server you created (here I added one entry in /etc/hosts called devpi-server, so I can use a name instead IP):
felipe ~/ $ devpi use http://devpi-server:8080
using server: http://devpi-server/ (not logged in)
no current index: type 'devpi use -l' to discover indices
~/.pydistutils.cfg : no config file exists
~/.pip/pip.conf : no index server configured
always-set-cfg: no
here it fail
felipe ~/ $ devpi login root --password '123'
WARN: devpi-client-1.2.1 got an unversioned reply, assuming API-VERSION 1 (as implemented by devpi-server-1.1 and 1.2)
POST http://devpi-server/+login
405 Not Allowed