pypi-server: 1.4.2 linux: alpine3.14 python: 3.9.7

Dockerfile

  1. FROM python:3.9.7-alpine3.14
  2. LABEL Author="caoxiangpeng"
  3. RUN set -ex \
  4. # 替换国内源
  5. && echo "" > /root/.pypipasswd \
  6. && echo http://mirrors.aliyun.com/alpine/v3.14/main/ > /etc/apk/repositories \
  7. && echo http://mirrors.aliyun.com/alpine/v3.14/community/ >> /etc/apk/repositories \
  8. && apk update \
  9. && apk add --no-cache --virtual .build-deps gcc musl-dev libffi-dev make openssl ca-certificates libressl-dev apache2-utils\
  10. && pip install pypiserver; pip install passlib \
  11. && mkdir -p /data \
  12. && rm -rf /var/cache/apk/* \
  13. && rm -rf ~/.ash_history ~/.python_history
  14. EXPOSE 80
  15. VOLUME ["/data", "/root/.pypipasswd"]
  16. # 保留此系统的编译能力,为以后安装做基础
  17. ENTRYPOINT ["pypi-server"]
  18. CMD ["-P", "/root/.pypipasswd", "-p", "80", "/data"]

docker 运行命令

  1. # 当前路径
  2. pwd
  3. /Users/johntoms/docker/pypi-server
  4. # 创建 数据存储目录及登录用户密码文件
  5. mkdir packages && touch pypipasswd
  6. # 运行 容器
  7. docker run --name mypypi-server -v <pwd>/pacakages:/data -v <pwd>/pypipasswd -p 80:80 -itd registry.cn-hangzhou.aliyuncs.com/private_app/mypypi-server-1.4.2:latest
  8. # 添加或更新pypi用户及密码
  9. docker exec -it mypypi-server htpasswd -b /root/.pypipasswd root PypiServer@123

本地相关配置

  1. # ~/.pypirc
  2. cat ~/.pypirc
  3. [distutils]
  4. index-servers =
  5. install
  6. internal
  7. [global]
  8. index-url =
  9. http://127.0.0.1:2199/simple
  10. http://pypi.douban.com/simple
  11. [install]
  12. trusted-host=http://127.0.0.1:2199/simple
  13. username: root
  14. password: <password>
  15. [internal]
  16. repository: http://127.0.0.1:2199
  17. username: root
  18. password: <password>

编译和上传本地私有包

  1. # 在 setup.py 同级目录下,创建 package.sh
  2. #清理数据
  3. rm -rf dist/*
  4. rm -rf build/*
  5. rm -rf flask_framework.egg-info
  6. #打包
  7. # python3 -m pip install --upgrade setuptools wheel
  8. python3 setup.py sdist bdist_wheel
  9. # 上传
  10. python setup.py sdist register -r local upload -r local
  11. 运行脚本
  12. sh package.sh

安装

  1. # --extral-index-url
  2. pip install flask_framework --extral-index-url http://127.0.0.1:2199/simple
  3. # -i
  4. pip install flask_framework -i install