Skip to main content

Package for accessing a Docker v2 registry

Project description

Build Status Coverage Status PyPI version

Python module and command-line tool for storing and retrieving data in a Docker registry.

  • Store arbitrary data (blob-store)

  • Content addressable

  • Set up named aliases to blobs

  • Supports Docker registry version 2

  • Works on Python 2.7 and 3.4

Command-line example:

dxf push-blob fred/datalogger logger.dat @may15-readings
dxf pull-blob fred/datalogger @may15-readings

which is the same as:

dxf set-alias fred/datalogger may15-readings $(dxf push-blob fred/datalogger logger.dat)
dxf pull-blob fred/datalogger $(dxf get-alias fred/datalogger may15-readings)

Module example:

from dxf import DXF

def auth(dxf, response):
    dxf.authenticate('fred', 'somepassword', response=response)

dxf = DXF('registry-1.docker.io', 'fred/datalogger', auth)

dgst = dxf.push_blob('logger.dat')
dxf.set_alias('may15-readings', dgst)

assert dxf.get_alias('may15-readings') == [dgst]

for chunk in dxf.pull_blob(dgst):
    sys.stdout.write(chunk)

Usage

The module API is described here.

The dxf command-line tool uses the following environment variables:

  • DXF_HOST - Host where Docker registry is running

  • DXF_INSECURE - Set this to 1 if you want to connect to the registry using http rather than https (which is the default).

  • DXF_USERNAME - Name of user to authenticate as

  • DXF_PASSWORD - User’s password

  • DXF_AUTH_HOST - If set, always perform token authentication to this host, overriding the value returned by the registry.

  • DXF_PROGRESS - If this is set to 1, a progress bar is displayed (on standard error) during push-blob and pull-blob. If this is set to 0, a progress bar is not displayed. If this is set to any other value, a progress bar is only displayed if standard error is a terminal.

  • DXF_BLOB_INFO - Set this to 1 if you want pull-blob to prepend each blob with its digest and size (printed in plain text, separated by a space and followed by a newline).

You can use the following options with dxf. Supply the name of the repository you wish to work with in each case as the second argument.

  • dxf push-blob <repo> <file> [@alias]

    Upload a file to the registry and optionally give it a name (alias). The blob’s hash is printed to standard output.

    The hash or the alias can be used to fetch the blob later using pull-blob.

  • dxf pull-blob <repo> <hash>|<@alias>...

    Download blobs from the registry to standard output. For each blob you can specify its hash (remember the registry is content-addressable) or an alias you’ve given it (using push-blob or set-alias).

  • dxf blob-size <repo> <hash>|<@alias>...

    Print the size of blobs in the registry. If you specify an alias, the sum of all the blobs it points to will be printed.

  • dxf del-blob <repo> <hash>|<@alias>...

    Delete blobs from the registry. If you specify an alias the blobs it points to will be deleted, not the alias itself. Use del-alias for that.

    Note that the Docker registry doesn’t support deletes yet so expect an error.

  • dxf set-alias <repo> <alias> <hash>|<file>...

    Give a name (alias) to a set of blobs. For each blob you can either specify its hash (as printed by get-blob) or, if you have the blob’s contents on disk, its filename (including a path separator to distinguish it from a hash).

  • dxf get-alias <repo> <alias>...

    For each alias you specify, print the hashes of all the blobs it points to.

  • dxf del-alias <repo> <alias>...

    Delete each specified alias. The blobs they point to won’t be deleted (use del-blob for that), but their hashes will be printed.

    Note that the Docker registry doesn’t support deletes yet so expect an error.

  • dxf list-aliases <repo>

    Print all the aliases defined in the repository.

  • dxf list-repos

    Print the names of all the repositories in the registry. Not all versions of the registry support this.

Authentication tokens

dxf automatically obtains Docker registry authentication tokens using your DXF_USERNAME and DXF_PASSWORD environment variables as necessary.

However, if you wish to override this then you can use the following command:

  • dxf auth <repo> <action>...

    Authenticate to the registry using DXF_USERNAME and DXF_PASSWORD, and print the resulting token.

    action can be pull, push or *.

If you assign the token to the DXF_TOKEN environment variable, for example:

DXF_TOKEN=$(dxf auth fred/datalogger pull)

then subsequent dxf commands will use the token without needing DXF_USERNAME and DXF_PASSWORD to be set.

Note however that the token expires after a few minutes, after which dxf will exit with EACCES.

Installation

pip install python_dxf

Licence

MIT

Tests

make test

Lint

make lint

Code Coverage

make coverage

coverage.py results are available here.

Coveralls page is here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_dxf-2.0.3.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_dxf-2.0.3-py2.py3-none-any.whl (46.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file python_dxf-2.0.3.tar.gz.

File metadata

  • Download URL: python_dxf-2.0.3.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for python_dxf-2.0.3.tar.gz
Algorithm Hash digest
SHA256 dcb353032ae2f33162bd474d7b713521de9c117c3e5764d3fa5e81f81fea95c8
MD5 9593bf7325a0ec4ffecee59b043780d0
BLAKE2b-256 e3b3eaf4ed88bde98f765ba8545f32c23d9f5750fd9edf100cbc99ce7ae339e9

See more details on using hashes here.

File details

Details for the file python_dxf-2.0.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for python_dxf-2.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 91bb57a82c61d08ab257243c7302ab59e527c47b2c3e5e9b4ef89df37fe1673f
MD5 d17693c86a17c565ab536c4e1e2df7a9
BLAKE2b-256 3d216de15efea9c38c0f48fc8ee7b1382efcdcbd2c09793e65c78ce72b71c20a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page