Python : Création d'un repository python Devpi-server
De www.yakakliker.org
Création d'un environnement virtuel python
- L'utilisateur créé sera "devpi-user"
su -l devpi-user
curl https://pyenv.run | bash
Edition du fichier ~/.bashrc
nano .bashrc
export PATH="~/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Redémarrer la session SSH pour prendre en compte les modifications du fichier
Installation des versions Python
pyenv install 3.14.0
pyenv versions
* system (set by /home/franck/.pyenv/version)
3.14.0
Création de l'environnement virtuel
pyenv virtualenv 3.14.0 devpi-3.14.0
Looking in links: /tmp/tmphg0jxgpf
Requirement already satisfied: setuptools in /home/devpi-user/.pyenv/versions/3.14.0/envs/devpi-3.14.0/lib/python3.14/site-packages (49.2.1)
Requirement already satisfied: pip in /home/devpi-user/.pyenv/versions/3.14.0/envs/devpi-3.14.0/lib/python3.14/site-packages (20.2.3)
pyenv virtualenvs
3.14.0/envs/devpi-3.14.0 (created from /home/devpi-user/.pyenv/versions/3.14.0)
devpi-3.14.0 (created from /home/devpi-user/.pyenv/versions/3.14.0)
Activation de l'environnement
pyenv activate devpi-3.14.0
(devpi-3.14.0) devpi-user@VLIN:~$
Installation de devpi-server
pip install -U devpi-server devpi-client devpi-web
devpi-gen-config --port 3141 --serverdir /home/devpi-user/www
devpi-init --serverdir /home/devpi-user/www --root-passwd azerty
devpi use http://localhost:3141
devpi login root --password=azerty
devpi user -c entreprise password=azerty
devpi index -c entreprise/release bases=root/pypi
devpi index -c entreprise/snapshot bases=entreprise/release
devpi user -c franck password=azerty email=franck@yakakliker
devpi index -y entreprise/release acl_upload=entreprise,franck,root
devpi index -y entreprise/snapshot acl_upload=entreprise,franck,root
devpi logout
Création du service devpi-user.service
- /etc/systemd/system/devpi-user.service
[Unit]
Description=Devpi Server
Requires=network-online.target
After=network-online.target
[Service]
Restart=on-success
# ExecStart:
# - shall point to existing devpi-server executable
# - shall not use the deprecated `--start`. We want the devpi-server to start in foreground
ExecStart=/home/devpi-user/.pyenv/versions/devpi-3.14.0/bin/devpi-server --port 3141 --serverdir /home/devpi-user/www
# set User according to user which is able to run the devpi-server
User=devpi-user
[Install]
WantedBy=multi-user.target
Installation du service nginx
apt-get install nginx
Configuration nginx
- /etc/nginx/sites-available/nginx-devpi.conf
map $http_x_forwarded_proto $x_scheme {
default $scheme;
http http;
https https;
}
server {
server_name localhost $hostname "";
listen 80;
gzip on;
gzip_min_length 2000;
gzip_proxied any;
# add application/vnd.pypi.simple.v1+json to the gzip_types
gzip_types text/plain text/css text/xml
application/json application/vnd.pypi.simple.v1+json
application/javascript text/javascript
application/xml application/xml+rss;
proxy_read_timeout 60s;
client_max_body_size 64M;
# set to where your devpi-server state is on the filesystem
root /home/devpi-user/www;
# try serving static files directly
location ~ /\+f/ {
# workaround to pass non-GET/HEAD requests through to the named location below
error_page 418 = @proxy_to_app;
if ($request_method !~ (GET)|(HEAD)) {
return 418;
}
expires max;
try_files /+files$uri @proxy_to_app;
}
# try serving docs directly
location ~ /\+doc/ {
# if the --documentation-path option of devpi-web is used,
# then the root must be set accordingly here
root /home/devpi-user/www;
try_files $uri @proxy_to_app;
}
location / {
# workaround to pass all requests to / through to the named location below
error_page 418 = @proxy_to_app;
return 418;
}
location @proxy_to_app {
proxy_pass http://localhost:3141;
# the $x_scheme variable is only required if nginx is behind another
# proxy (often the case in container environments),
# if your nginx is the only proxy server, the $scheme variable can be
# used and the map $http_x_forwarded_proto $x_scheme above be removed
proxy_set_header X-Forwarded-Proto $x_scheme;
proxy_set_header X-outside-url $x_scheme://$http_host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Installation de haproxy
apt-get install haproxy hatop
Configuration de haproxy
- /etc/haproxy/haproxy.cfg
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
daemon
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
# See: https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate
ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256
ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
frontend https
bind *:443 ssl crt /etc/haproxy/certs/wildcard.yakakliker.org.pem
mode http
option httplog
http-request redirect scheme https code 301 unless { ssl_fc }
acl devpi_acl hdr(host) python-repo.yakakliker.org
use_backend devpi if devpi_acl
backend devpi
mode http
option httpchk GET /
option forwardfor
http-request add-header X-Forwarded-Proto https if { ssl_fc }
server devpi 127.0.0.1:80 check
Sortie de l'environnement
pyenv deactivate
Arrêt / démarrage des services
## Démarrage des services
systemctl start devpi-user.service
systemctl start nginx
systemctl start haproxy
## Arrêt des services
systemctl stop devpi-user.service
systemctl stop nginx
systemctl stop haproxy
## Activation du démarrage automatique des services
systemctl enable devpi-user.service
systemctl enable nginx
systemctl enable haproxy
Liens
- https://pypi.org/org/devpi/
- https://www.devpi.net/
- https://devpi.net/docs/devpi/devpi/stable/+doc/quickstart-server.html
- https://dev.to/cwprogram/private-python-packages-with-devpi-3iai
- Python : Création d'un environnement virtuel Python / Gunicorn