pypi 私有源搭建

背景

提高研发装包构建基础镜像的速度,特搭建此 pypi 私有源

搭建流程,使用k8s 方式来部署集群

  • Dockerfile (官方python:3.9-slim 基础镜像即可,CMD命令即是无账号密码访问私有源)
FROM uhub.service.ucloud.cn/deeplang/python:3.9-slim
RUN pip install pypiserver
EXPOSE 8080
CMD ["pypi-server", "-p", "8080", "--disable-fallback", "-a", ".", "-P", ".", "/data/packages"]

docker build -t uhub.service.ucloud.cn/deeplang/my-pypiserver:v4 . 
  • deployment 配置文件
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: pypiserver
  name: pypiserver
spec:
  replicas: 1
  selector:
    matchLabels:
      app: pypiserver
  template:
    metadata:
      labels:
        app: pypiserver
    spec:
      containers:
      - name: pypiserver
        image: uhub.service.ucloud.cn/deeplang/my-pypiserver:v4
        imagePullPolicy: IfNotPresent
        livenessProbe:
          failureThreshold: 5
          initialDelaySeconds: 10
          periodSeconds: 6
          successThreshold: 1
          tcpSocket:
            port: 8080
          timeoutSeconds: 5
        ports:
        - containerPort: 8080
        readinessProbe:
          failureThreshold: 5
          initialDelaySeconds: 10
          periodSeconds: 6
          successThreshold: 1
          tcpSocket:
            port: 8080
          timeoutSeconds: 5
        volumeMounts:
        - mountPath: /data/packages
          name: packages-volume
      volumes:
      - name: packages-volume
        nfs:
          path: /private/pypiserver
          server: 172.x.x.x
  • service 配置文件
kind: Service
apiVersion: v1
metadata:
  name: pypiserver
  namespace: pypiserver
  labels:
    name: pypiserver
spec:
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
  selector:
   app: pypiserver
  • ingress 配置文件准备
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: 1024m
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "601"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "601"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "601"
    nginx.ingress.kubernetes.io/whitelist-source-range: 39.98.1.1
  name: pypiserver
  namespace: pypiserver
spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - test.example.com
    secretName: pypiserver-tls  
  rules:
  - host: test.example.com
    http:
      paths:
      - backend:
          service:
            name: pypiserver
            port:
              number: 80
        path: /
        pathType: Prefix
posted @ 2024-07-08 16:23  lixinliang  阅读(45)  评论(0编辑  收藏  举报