Dockerを使用したdevpiパッケージマネージャーの構築

Dockerfileイメージ構築

  1. Dockerfile
FROM python:3.12.2-slim

WORKDIR /app
COPY startup.sh ./
COPY package-sources /etc/apt/sources.list
COPY debian-repo /etc/apt/sources.list.d/

RUN apt-get update &&\
  apt-get install -y vim net-tools procps nginx &&\
  pip install devpi devpi-web supervisor &&\
  chmod +x /app/startup.sh

ENTRYPOINT ["/app/startup.sh"]

  1. startup.sh
#!/bin/bash
devpi-init --serverdir=/app/pypi-repo
/usr/local/bin/devpi-server --host=0.0.0.0 --port=3141 --serverdir /app/pypi-repo

  1. debian-repo
Types: deb
URIs: http://mirrors.aliyun.com/debian
Suites: bookworm bookworm-updates
Components: main non-free contrib
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

Types: deb
URIs: http://mirrors.aliyun.com/debian-security
Suites: bookworm-security
Components: main
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

  1. package-sources
deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb-src https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib

  1. docker build -t pypi-server:1.8 .

docker-compose 設定ファイル

  1. ppi-server.yml (マウントディレクトリは適宜変更してください)
version: "3"
services:
    pypi-server:
        container_name: "pypi-server"
        privileged: true
        image: "pypi-server:1.8"
        restart: always
        network_mode: host
        volumes:
            - /data/pypi-server/packages:/app/pypi-repo

  1. docker-compose -f ppi-server.yml up -d

devpi-server 環境の初期化

  1. devpi-clientのインストール (localhostはご自身のIPに置き換えてください。初期化は一度だけ必要です。ネットワークに接続できていれば pip3 install -i "http://localhost:3141/root/pypi/+simple/" jwt --trusted-host localhost が使用できます)
pip3 install devpi-client -i https://mirrors.aliyun.com/pypi/simple/
dev use http://localhost:3141/root/py
# 初期パスワードは空でEnterキーを押す
devpi login root
# アリババクラウドのミラーソースに変更
devpi index root/pypi "mirror_web_url_fmt=https://mirrors.aliyun.com/pypi/simple/{name}/" \
"mirror_url=https://mirrors.aliyun.com/pypi/simple/"
# これでパッケージをインストールできるようになります
pip3 install -i "http://localhost:3141/root/pypi/+simple/" jwt --trusted-host localhost

  1. 動作確認画面

  2. Web管理画面

注意点

  1. devpi-serverはインデックスを取得するためにしばらく時間がかかります
  2. Pythonパッケージのインストール中のログを確認してください

参考リンク

  1. https://devpi.net/docs/devpi/devpi/stable/+doc/quickstart-releaseprocess.html#installing-devpi-client-and-server

タグ: Docker devpi パッケージマネージャー Python コンテナ

5月25日 12:47 投稿