python私有仓库_pypi私有镜像仓库部署

一、pypi私有镜像仓库

pypi私有镜像仓库可由pypi-web镜像提供服务,该镜像一般运行两个容器:

- pypi-web: 该容器运行web服务nginx负责为python包管理程序pip提供服务,一般长期运行;

- pypi-sync:该容器运行bandersnatch同步程序,负责从http://pypi.org同步数据,周期性运行。

二、服务管理

1.docker-compose.yml文件如下:

version:"3"services:pypi-web:build:context:./dockerfile:Dockerfileimage:pypi-web:20190723environment:DATA:/dataports:- 8080:80volumes:- /data/pypi:/datapypi-sync:depends_on:- pypi-webimage:pypi-web:20190723environment:DATA:/datavolumes:- /data/pypi:/datacommand:/usr/local/bin/entrypoint.sh sync

2.构建pypi-web镜像,进入docker-compose.yml文件所在目录执行:

# docker-compose build

3.启动服务:

# docker-compose up -d

4.查看服务运行状态:

# docker-compose top

5.停止服务:

# docker-compose down

6.一般bandersnatch程序运行结束后pypi-sync容器就会停止,如果需要再次同步可以单独启动pypi-sync容器:

# docker-compose up -d pypi-sync

7.查看同步日志:

# docker-compose logs -f --tail 100 pypi-sync

三、配置pip使用私有镜像

1.创建pip配置文件(此处url为ip地址,如果有域名解析建设使用域名)

# cat ~/.pip/pip.conf

[global]

index-url = http://192.168.9.120:8080/simple/

[install]

trusted-host = 192.168.9.120

2.使用私有仓库安装python包

# pip install XXXX

四、Dockerfile文件如下:

FROM scratch

ADD centos-7-x86_64-docker.tar.xz /

COPY set_mirror.sh /usr/local/bin

COPY entrypoint.sh /usr/local/bin

RUN set -x \

&& find /etc/yum.repos.d -name "*.repo" -exec unlink {} \; \

&& set_mirror.sh \

&& yum clean all \

&& yum install -y gcc make file net-tools wget libffi-devel openssl-devel zlib-devel pcre-devel readline-devel 2>/dev/null \

&& wget -O /tmp/nginx-1.16.0.tar.gz http://nginx.org/download/nginx-1.16.0.tar.gz 2>/dev/null \

&& tar zxf /tmp/nginx-1.16.0.tar.gz -C /tmp \

&& cd /tmp/nginx-1.16.0 \

&& ./configure \

--prefix=/usr/local/nginx \

--with-http_ssl_module \

--with-http_v2_module \

--with-http_realip_module \

--with-http_addition_module \

--with-http_sub_module \

--with-http_dav_module \

--with-http_flv_module \

--with-http_gzip_static_module \

--with-http_stub_status_module \

--with-pcre \

&& make \

&& make install \

&& wget -O /tmp/Python-3.6.6.tgz https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz 2>/dev/null \

&& tar zxf /tmp/Python-3.6.6.tgz -C /tmp \

&& cd /tmp/Python-3.6.6 \

&& ./configure --prefix=/usr/local/python3 \

&& make \

&& make install \

&& echo "PATH=/usr/local/nginx/sbin:/usr/local/python3/bin:\$PATH" >>/etc/profile \

&& source /etc/profile \

&& pip3 install --upgrade pip \

&& pip3 install pyparsing==2.4.0 bandersnatch==3.4.0 \

&& wget -O /tmp/tini_0.18.0-amd64.rpm https://github.com/krallin/tini/releases/download/v0.18.0/tini_0.18.0-amd64.rpm 2>/dev/null \

&& rpm -ivh /tmp/tini_0.18.0-amd64.rpm \

&& rpm -e gcc \

&& yum clean all \

&& rm -fr /tmp/nginx* /tmp/Python* /tmp/tini*

ENTRYPOINT ["/usr/bin/tini", "--"]

CMD ["/usr/local/bin/entrypoint.sh"]

五、entrypoint脚本文件如下:

#!/bin/bash

#

source /etc/profile

# Define the data storage directory, default is "/data".

DATA=${DATA:=/data}

function run_web() {

cat > /usr/local/nginx/conf/nginx.conf <

user nobody;

worker_processes 8;

worker_rlimit_nofile 65535;

events {

use epoll;

worker_connections 65535;

}

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

keepalive_timeout 10;

server_tokens off;

server {

listen 80 default_server;

root $DATA/web;

autoindex on;

autoindex_exact_size off;

autoindex_localtime on;

charset utf-8;

}

}

EOF

if [ ! -d "$DATA/web" ]; then

mkdir -p "$DATA/web"

fi

exec nginx -g "daemon off;"

}

function run_sync() {

cat > /etc/bandersnatch.conf <

[mirror]

directory = $DATA

json = true

master = https://pypi.org

timeout = 15

workers = 10

hash-index = false

stop-on-error = false

verifiers = 3

EOF

exec bandersnatch mirror

}

case $1 in

"sync")

run_sync

;;

*)

run_web

;;

esac

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值