pypi同步并搭建私有源
程序员文章站
2022-05-07 23:08:16
...
Dockerfile
FROM alpine:3.12
RUN apk update && apk add --no-cache ca-certificates dcron bash gcc python3 py3-pip \
tzdata libxml2-dev libxslt-dev python3-dev linux-headers libc-dev && \
rm -rf /var/cache/apk/* && \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone && \
pip3 install bandersnatch -i http://pypi.douban.com/simple --trusted-host pypi.douban.com && \
touch /var/log/pypi.log && \
touch /var/log/cron.log && \
mkdir /mirrors
ADD crontab /etc/crontabs/root
ADD bandersnatch.conf /etc/bandersnatch.conf
# 一定要使用root权限
CMD chown root:root /etc/crontabs/root && crond -L /var/log/cron.log && tail -f /var/log/cron.log
crontab
0 5 * * 1 bandersnatch mirror >> /var/log/pypi.log
# Don't remove this line .
bandersnatch.conf
[mirror]
; The directory where the mirror data will be stored.
directory = /mirrors/pypi
; The PyPI server which will be mirrored.
; master = https://testpypi.python.org
; scheme for PyPI server MUST be https
master = https://pypi.python.org
; The network socket timeout to use for all connections. This is set to a
; somewhat aggressively low value: rather fail quickly temporarily and re-run
; the client soon instead of having a process hang infinitely and have TCP not
; catching up for ages.
timeout = 10
; Number of worker threads to use for parallel downloads.
; Recommendations for worker thread setting:
; - leave the default of 3 to avoid overloading the pypi master
; - official servers located in data centers could run 10 workers
; - anything beyond 10 is probably unreasonable and avoided by bandersnatch
workers = 3
; Whether to hash package indexes
; Note that package index directory hashing is incompatible with pip, and so
; this should only be used in an environment where it is behind an application
; that can translate URIs to filesystem locations. For example, with the
; following Apache RewriteRule:
; RewriteRule ^([^/])([^/]*)/$ /mirror/pypi/web/simple/$1/$1$2/
; RewriteRule ^([^/])([^/]*)/([^/]+)$/ /mirror/pypi/web/simple/$1/$1$2/$3
; Setting this to true would put the package 'abc' index in simple/a/abc.
; Recommended setting: the default of false for full pip/pypi compatability.
hash-index = false
; Whether to stop a sync quickly after an error is found or whether to continue
; syncing but not marking the sync as successful. Value should be "true" or
; "false".
stop-on-error = false
; Whether or not files that have been deleted on the master should be deleted
; on the mirror, too.
; IMPORTANT: if you are running an official mirror than you *need* to leave
; this on.
delete-packages = true
; Advanced logging configuration. Uncomment and set to the location of a
; python logging format logging config file.
; log-config = /etc/bandersnatch-log.conf
[statistics]
; A glob pattern matching all access log files that should be processed to
; generate daily access statistics that will be aggregated on the master PyPI.
access-log-pattern = /var/log/nginx/*.pypi.python.org*access*
; vim: set ft=cfg:
docker-compose
version: "3"
services:
pypi-sync:
image: pypi-sync:1.0.0
container_name: pypi-sync
privileged: true
restart: always
volumes:
- /data/pypi-sync:/mirrors/pypi
- ./crontab:/etc/crontabs/root
- ./log:/var/log
pypi-nginx:
image: nginx:1.18
container_name: pypi-nginx
ports:
- 2120:80
volumes:
- /data/pypi-sync/web:/usr/share/nginx/html
- ./log:/var/log/nginx
restart: always
privileged: true
测试
C:\Windows\system32>pip install xlwt -i http://192.168.2.3:2120/simple/ --trusted-host 192.168.2.3
Looking in indexes: http://10.0.7.36:2120/simple/
Collecting xlwt
Downloading http://10.0.7.36:2120/packages/44/48/def306413b25c3d01753603b1a222a011b8621aed27cd7f89cbc27e6b0f4/xlwt-1.3.0-py2.py3-none-any.whl (99 kB)
|████████████████████████████████| 99 kB 6.4 MB/s
Installing collected packages: xlwt
Successfully installed xlwt-1.3.0
推荐阅读