pypi同步并搭建私有源

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

llc的足迹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值