访问Docker V2注册表的包

python-dxf的Python项目详细描述


Build StatusCoverage StatusPyPI version

python模块和命令行工具,用于在 码头登记处。

  • 存储任意数据(blob store)
  • 内容可寻址
  • 将命名别名设置为blob
  • 支持Docker注册表架构v1和v2
  • 适用于Python2.7和3.6

请注意dxf不会生成Docker容器 配置,因此您将无法存储docker pull数据 使用dxf。有关详细信息,请参见this issue

命令行示例:

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

这与:

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)

模块示例:

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)

用法

描述了模块api here

dxf命令行工具使用以下环境变量:

  • DXF_HOST-运行Docker注册表的主机。
  • DXF_INSECURE-如果要连接到 使用http而不是https(默认值)的注册表。
  • DXF_USERNAME-要作为身份验证的用户的名称。
  • DXF_PASSWORD-用户密码。
  • DXF_AUTHORIZATION-httpAuthorization头值。
  • DXF_AUTH_HOST-如果已设置,则始终执行令牌身份验证 此主机,重写注册表返回的值。
  • DXF_PROGRESS-如果设置为1,则进度条为 在push-blobpull-blob期间显示(标准错误)。 如果设置为0,则不显示进度条。如果这是 设置为任何其他值时,只有在标准 错误是一个终端。
  • DXF_BLOB_INFO-如果希望pull-blob设置为1。 在每个blob前面加上摘要和大小(以纯文本打印, 由空格分隔,后跟换行符)。
  • DXF_CHUNK_SIZE-字节数pull-blob应在下载 一次。默认为8192。
  • DXF_SKIPTLSVERIFY-将此设置为1以跳过TLS证书 验证。
  • DXF_TLSVERIFY-用于tls的自定义ca包的可选路径 验证。

您可以对dxf使用以下选项。提供 您希望在每种情况下使用的存储库作为第二个参数。

  • 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 ^{tt18}$.

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

    Download blobs from the registry to standard output. For each blob you can specify its hash, prefixed by ^{tt32}$ (remember the registry is content-addressable) or an alias you’ve given it (using ^{tt17}$ or ^{tt34}$).

  • 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 ^{tt37}$ for that.

  • 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 ^{tt39}$) 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 ^{tt42}$ for that), but their hashes will be printed.

  • 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.

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

    For each alias you specify, print the hash of its configuration blob. For an alias created using ^{tt1}$, this is the hash of the first blob it points to. For a Docker image tag, this is the same as ^{tt47}$.

证书

如果您的注册表使用带有自颁发证书的ssl,则需要 为dxf提供一组受信任的证书颁发机构。

REQUESTS_CA_BUNDLE环境变量设置为PEM的路径 包含受信任证书颁发机构证书的文件。

模块和命令行工具都支持REQUESTS_CA_BUNDLE

或者,可以设置DXF_TLSVERIFY环境变量 对于命令行工具或将tlsverify选项传递给 模块

身份验证令牌

dxf自动获取Docker注册表身份验证令牌 使用DXF_USERNAMEDXF_PASSWORD,或 DXF_AUTHORIZATION,必要时提供环境变量。

但是,如果您希望覆盖它,则可以使用以下命令 命令:

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

    Authenticate to the registry using ^{tt10}$ and ^{tt11}$, or ^{tt12}$, and print the resulting token.

    ^{tt61}$ can be ^{tt62}$, ^{tt63}$ or ^{tt64}$.

如果将令牌分配给DXF_TOKEN环境变量,则 示例:

DXF_TOKEN=$(dxf auth fred/datalogger pull)

随后的dxf命令将不需要 DXF_USERNAMEDXF_PASSWORD,或DXF_AUTHORIZATION,将 准备好了。

但是请注意,令牌在几分钟后过期,之后 {TT1}$将以^ {TT72} $退出。

Docker云认证

你可以使用 ^{TT73}$<;https://github.com/docker/python-dockercloud>;。`_ 从Docker中读取身份验证信息的库 配置文件并将其传递给dxf

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()

谢谢s到cyrilleverrier的 这个提示。

安装

pip install python-dxf

许可证

MIT

测试

make test

棉绒

make lint

代码覆盖率

make coverage

coverage.py结果是 可获得的 here

工作服页面是here

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何使用运行时从JAVA运行openssl命令?   不使用线程安全类(如AtomicInteger和SynchronizedList)的java ProducerConsumer问题   匹配字符串的java模式   在java中使用泛型接口作为返回类型   java将可能具有序列化JSON值的hashmap作为节点添加到JSON字符串中   Eclipse无法从Java8流推断正确的类型   java无法了解标准JButton的大小   java我能用一个循环优化这个函数吗(在第一种方法中)?   Apache CXF中基于WebSocket的java SOAP?   java想要运行奇偶和求和三步   矩阵上随机元素的java集值   java布尔相等:0==a,操作数顺序重要吗?   java Eclipse不会退出我的插件   java如何在spring的SOAP拦截器中获取HttpServletRequest和HttpServletResponse