Package: python-dxf
Python module and command-line tool for storing and retrieving data in a
Docker registry.Store arbitrary data (blob-store)Content addressableSet up named aliases to blobsSupports Docker registry schemas v1 and v2Works on Python 3.6+Please note thatdxfdoesnotgenerate Docker container
configuration, so you won’t be able todocker pulldata you store
usingdxf. Seethis
issuefor more details.Command-line example:dxfpush-blobfred/dataloggerlogger.dat@may15-readingsdxfpull-blobfred/datalogger@may15-readingswhich is the same as:dxfset-aliasfred/dataloggermay15-readings$(dxfpush-blobfred/dataloggerlogger.dat)dxfpull-blobfred/datalogger$(dxfget-aliasfred/dataloggermay15-readings)Module example:fromdxfimportDXFdefauth(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)assertdxf.get_alias('may15-readings')==[dgst]forchunkindxf.pull_blob(dgst):sys.stdout.write(chunk)UsageThe module API is describedhere.Thedxfcommand-line tool uses the following environment variables:DXF_HOST- Host where Docker registry is running.DXF_INSECURE- Set this to1if you want to connect to the
registry usinghttprather thanhttps(which is the default).DXF_USERNAME- Name of user to authenticate as.DXF_PASSWORD- User’s password.DXF_AUTHORIZATION- HTTPAuthorizationheader value.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 to1, a progress bar is
displayed (on standard error) duringpush-blobandpull-blob.
If this is set to0, 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 to1if you wantpull-blobto
prepend each blob with its digest and size (printed in plain text,
separated by a space and followed by a newline).DXF_CHUNK_SIZE- Number of bytespull-blobshould download at
a time. Defaults to 8192.DXF_SKIPTLSVERIFY- Set this to1to skip TLS certificate
verification.DXF_TLSVERIFY- Optional path to custom CA bundle to use for TLS
verification.DXF_PLATFORM- Optional platform (e.g.linux/amd64) to use
for multi-arch manifests. If a multi-arch manifest is encountered and
this is not set then a dict containing entries for each platform will
be displayed.You can use the following options withdxf. Supply the name of the
repository you wish to work with in each case as the second argument.dxfpush-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 usingpull-blob.dxfpull-blob<repo><hash>|<@alias>...Download blobs from the registry to standard output. For each blob
you can specify its hash, prefixed bysha256:(remember the
registry is content-addressable) or an alias you’ve given it
(usingpush-bloborset-alias).dxfblob-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.dxfmount-blob<repo><from-repo><hash> [@alias]Cross mount a blob from another repository and optionally give it
an alias. Specify the blob by its hash, prefixed bysha256:.This is useful to avoid having to upload a blob to your repository
if you know it already exists in the registry.dxfdel-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. Usedel-aliasfor that.dxfset-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 bypush-bloborget-alias) or, if you have the blob’s contents on disk, its
filename (including a path separator to distinguish it from a
hash).dxfget-alias<repo><alias>...For each alias you specify, print the hashes of all the blobs it
points to.dxfdel-alias<repo><alias>...Delete each specified alias. The blobs they point to won’t be
deleted (usedel-blobfor that), but their hashes will be
printed.dxfget-digest<repo><alias>...For each alias you specify, print the hash of its configuration
blob. For an alias created usingdxf, this is the hash of the
first blob it points to. For a Docker image tag, this is the same
asdocker inspect alias--format='{{.Id}}'.dxfget-manifest<repo><alias>...For each alias you specify, print its manifest obtained from the
registry.dxflist-aliases<repo>Print all the aliases defined in the repository.dxflist-reposPrint the names of all the repositories in the registry. Not all
versions of the registry support this.CertificatesIf your registry uses SSL with a self-issued certificate, you’ll need to
supplydxfwith a set of trusted certificate authorities.Set theREQUESTS_CA_BUNDLEenvironment variable to the path of a PEM
file containing the trusted certificate authority certificates.Both the module and command-line tool supportREQUESTS_CA_BUNDLE.Alternatively, you can set theDXF_TLSVERIFYenvironment variable
for the command-line tool or pass thetlsverifyoption to the
module.Authentication tokensdxfautomatically obtains Docker registry authentication tokens
using yourDXF_USERNAMEandDXF_PASSWORD, orDXF_AUTHORIZATION, 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 usingDXF_USERNAMEandDXF_PASSWORD, orDXF_AUTHORIZATION, and print the
resulting token.actioncan bepull,pushor*.If you assign the token to theDXF_TOKENenvironment variable, for
example:DXF_TOKEN=$(dxfauth fred/datalogger pull)then subsequentdxfcommands will use the token without needingDXF_USERNAMEandDXF_PASSWORD, orDXF_AUTHORIZATION, to be
set.Note however that the token expires after a few minutes, after whichdxfwill exit withEACCES.Docker Cloud authenticationYou can use the`dockercloud<https://github.com/docker/python-dockercloud>`__
library to read authentication information from your Docker
configuration file and pass it todxf:auth='Basic '+dockercloud.api.auth.load_from_file()dxf_obj=dxf.DXF('index.docker.io',repo='myorganization/myimage')dxf_obj.authenticate(authorization=auth,actions=['pull'])dxf_obj.list_aliases()Thanks tocyrilleverrierfor
this tip.Installationpipinstallpython-dxfLicenceMITOther projects that use DXFDocker-charonhttps://github.com/gabrieldemarmiesse/docker-charonThis package allows you to transfer Docker images from one registry to
another. The second one being disconnected from the internet.Unlikedocker saveanddocker load, it creates the payload
directly from the registry (it’s faster) and is able to compute diffs to
only take the layers needed, hence reducing the size.TestsmaketestLintmakelintCode Coveragemakecoveragecoverage.pyresults are
availablehere.Coveralls page ishere.