如何使用Docker搭建pypi私有倉庫
一、搭建
1、準(zhǔn)備htpasswd.txt文件
該文件內(nèi)容包含上傳包至倉庫時(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、建立測試項(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’], #上傳到倉庫后的目錄,如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、使用上傳至倉庫的包
pip install -i http://pypi.local.me --trusted-host pypi.local.me linode_example
打包注意事項(xiàng):
1、所有需要打包的項(xiàng)目在git倉庫中的目錄結(jié)構(gòu)必須一致,便于jenkinsfile自動(dòng)化集成;
2、所有需要打包的項(xiàng)目的setup.py文件必須位于項(xiàng)目根目錄下;
3、python使用統(tǒng)一版本,每個(gè)項(xiàng)目的版本需要固定,便于迭代。
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP新手必備的基礎(chǔ)知識(shí)2. ASP.NET Core按用戶等級(jí)授權(quán)的方法3. vue-electron中修改表格內(nèi)容并修改樣式4. .NET 中配置從xml轉(zhuǎn)向json方法示例詳解5. 推薦一個(gè)好看Table表格的css樣式代碼詳解6. ASP常用日期格式化函數(shù) FormatDate()7. 利用FastReport傳遞圖片參數(shù)在報(bào)表上展示簽名信息的實(shí)現(xiàn)方法8. phpstudy apache開啟ssi使用詳解9. HTML中的XML數(shù)據(jù)島記錄編輯與添加10. 微信小程序?qū)崿F(xiàn)商品分類頁過程結(jié)束
