怎样使用Docker搭建pypi私有仓库

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

怎样使用Docker搭建pypi私有仓库

大碗油泼   2020-11-27 我要评论

一、搭建

1、准备htpasswd.txt文件

该文件内容包含上传包至仓库时验证的用户名和密码

pip install htpasswd
htpasswd -sc htpasswd.txt <username>

2、启动容器

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
#需在宿主机上提前建立好data目录及htpasswd.txt文件

3、设置nginx反向代理

cat /usr/local/nginx/conf/exten/pypi.conf
upstream 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、建立测试项目

# 建立项目目录
mkdir -p linode_example/linode_example
# 建立setup.py
cat linode_example/setup.py
from setuptools import setup
setup(
   name='linode_example',
   packages=['linode_example'], #上传到仓库后的目录,如http://pypi.local.me/linode_example
   description='Hello world enterprise edition',
   version='0.1', # 版本号
   url='http://github.com/example/linode_example',
   author='Linode',
   keywords=['pip','linode','example']
   )
# 该文件内容为说明性内容,可根据自己的包的情况进行设置
 
# 建立__init__.py 主程序
cat linode_example/linode_example/__init__.py
def hello_word():
   print("hello world")
 
# 打包并上传
python3.7 setup.py sdist # 打包,执行完后会在dist目录下有个tar包
twine upload --repository-url http://pypi.local.me dist/* # 上传时需要输入用户名和密码:admin/admin123

2、使用上传至仓库的包

pip install -i http://pypi.local.me --trusted-host pypi.local.me linode_example

打包注意事项:

1、所有需要打包的项目在git仓库中的目录结构必须一致,便于jenkinsfile自动化集成;

2、所有需要打包的项目的setup.py文件必须位于项目根目录下;

3、python使用统一版本,每个项目的版本需要固定,便于迭代。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们