如何使用Docker搭建pypi私有倉(cāng)庫(kù)
一、搭建
1、準(zhǔn)備htpasswd.txt文件
該文件內(nèi)容包含上傳包至倉(cāng)庫(kù)時(shí)驗(yàn)證的用戶名和密碼
pip install htpasswdhtpasswd -sc htpasswd.txt <username>
2、啟動(dòng)容器
docker run --name pypiserver --restart=always -v /data/pypi/packages:/data/packages -v /root/htpasswd.txt:/data/htpasswd.txt -p 8080:8080 -d pypiserver/pypiserver -P htpasswd.txt packages#需在宿主機(jī)上提前建立好data目錄及htpasswd.txt文件
3、設(shè)置nginx反向代理
cat /usr/local/nginx/conf/exten/pypi.confupstream pypi { server 127.0.0.1:8080; } server { listen 80; server_name pypi.local.me; location / { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_pass http://pypi; }}
二、使用
1、建立測(cè)試項(xiàng)目
# 建立項(xiàng)目目錄mkdir -p linode_example/linode_example# 建立setup.pycat linode_example/setup.pyfrom setuptools import setupsetup( name=’linode_example’, packages=[’linode_example’], #上傳到倉(cāng)庫(kù)后的目錄,如http://pypi.local.me/linode_example description=’Hello world enterprise edition’, version=’0.1’, # 版本號(hào) url=’http://github.com/example/linode_example’, author=’Linode’, keywords=[’pip’,’linode’,’example’] )# 該文件內(nèi)容為說明性內(nèi)容,可根據(jù)自己的包的情況進(jìn)行設(shè)置 # 建立__init__.py 主程序cat linode_example/linode_example/__init__.pydef hello_word(): print('hello world') # 打包并上傳python3.7 setup.py sdist # 打包,執(zhí)行完后會(huì)在dist目錄下有個(gè)tar包twine upload --repository-url http://pypi.local.me dist/* # 上傳時(shí)需要輸入用戶名和密碼:admin/admin123
2、使用上傳至倉(cāng)庫(kù)的包
pip install -i http://pypi.local.me --trusted-host pypi.local.me linode_example
打包注意事項(xiàng):
1、所有需要打包的項(xiàng)目在git倉(cāng)庫(kù)中的目錄結(jié)構(gòu)必須一致,便于jenkinsfile自動(dòng)化集成;
2、所有需要打包的項(xiàng)目的setup.py文件必須位于項(xiàng)目根目錄下;
3、python使用統(tǒng)一版本,每個(gè)項(xiàng)目的版本需要固定,便于迭代。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 完美解決vue 中多個(gè)echarts圖表自適應(yīng)的問題2. SpringBoot+TestNG單元測(cè)試的實(shí)現(xiàn)3. vue實(shí)現(xiàn)web在線聊天功能4. idea配置jdk的操作方法5. Springboot 全局日期格式化處理的實(shí)現(xiàn)6. python 浮點(diǎn)數(shù)四舍五入需要注意的地方7. Docker容器如何更新打包并上傳到阿里云8. IntelliJ IDEA設(shè)置默認(rèn)瀏覽器的方法9. Java GZip 基于內(nèi)存實(shí)現(xiàn)壓縮和解壓的方法10. JAMon(Java Application Monitor)備忘記
