Skip to content

oleks/docker-pypi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minimal PyPI Docker Infrastructure

A minimal PyPI Docker container on top of an Alpine Linux base image.

Server

There are really two Dockerfiles. One for running PyPI, and one for authentication configuration. The PyPI container uses a read/write Docker volume for the Python packages (called pypi). This allows your packages to be persisted and shared across container instances. Authentication settings (user accounts) are kept in a separate volume (called pypi-auth) which is mounted read-only by the PyPI container. The purpose of the auth container is to set up a pypi-auth volume for use with this container.

Authentication

PyPI uses Apache-style htpasswd files for authentication. These can be generated using the htpasswd utility found in your local Apache httpd package. If you don't want to bother with installing the Apache utilities, the auth container gets them inside the box. To use this option, you can let auth/htpasswd be an empty file and type make -C auth interact (from here) to drop into a shell with htpasswd installed.

(The Dockerfile installs bcrypt in the PyPI container. Let's use it.)

To create an auth/htpasswd file,

[ ! -f auth/htpasswd ] && htpasswd -c -B auth/htpasswd <username>

(The [ ! -f auth/htpasswd ] will ensure not to write over the file if it already exists.)

You will be prompted for a password.

To add a user to an existing auth/htpasswd,

htpasswd auth/htpasswd <username>

You will be prompted for a password.

Build and Run

To make things quick and painless, both a Makefile and an auth/Makefile is provided. Type make run to do everything. If it goes well, you can go to http://localhost:8080. make build will just build (both) containers. make -C auth ineract will drop you into a shell in the auth container with htpasswd installed.

Client

Registering and Uploading Packages

You need to create or edit a PyPI configuration file, ~/.pypirc.

A baseline configuration can look like this:

[distutils]
index-servers =
  <servername>

[<servername>]
repository=<url>
username=<username>
password=<password>

Where you choose <servername>, <url>, <username>, and <password>. <servername> is not important, it is a name for local use (see below).

Now, navigate to your fancy Python package, having a setup.py and setup.cfg.

First register your package:

python3 setup.py register -r <servername>

Then you can upload it:

python3 setup.py sdist upload -r <servername>

Downloading Packages

Create or modify a PIP configuration file, ~/.config/pip/pip.conf:

[global]
extra-index-url=<url>/simple/

Where <url> points to your PyPI server.

Now try and download a fancy package:

pip3 install --user <package>

About

Minimal Docker infrastructure for hosting your own Python Package Index.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors