Skip to main content

Parse a dockerfile into a high-level representation using the official go parser.

Project description

build status pre-commit.ci status

dockerfile

The goal of this repository is to provide a wrapper around docker/docker's parser for dockerfiles.

python library

Installation

This project uses setuptools-golang when built from source. To build from source you'll need a go compiler.

If you're using linux and sufficiently new pip (>=8.1) you should be able to just download prebuilt manylinux1 wheels.

pip install dockerfile

Usage

There's three api functions provided by this library:

dockerfile.all_cmds()

List all of the known dockerfile cmds.

>>> dockerfile.all_cmds()
('add', 'arg', 'cmd', 'copy', 'entrypoint', 'env', 'expose', 'from', 'healthcheck', 'label', 'maintainer', 'onbuild', 'run', 'shell', 'stopsignal', 'user', 'volume', 'workdir')

dockerfile.parse_file(filename)

Parse a Dockerfile by filename. Returns a tuple of dockerfile.Command objects representing each layer of the Dockerfile. Possible exceptions:

  • dockerfile.GoIOError: The file could not be opened.
  • dockerfile.GoParseError: The Dockerfile was not parseable.
>>> pprint.pprint(dockerfile.parse_file('testfiles/Dockerfile.ok'))
(Command(cmd='from', sub_cmd=None, json=False, original='FROM ubuntu:xenial', start_line=1, flags=(), value=('ubuntu:xenial',)),
 Command(cmd='cmd', sub_cmd=None, json=True, original='CMD ["echo", "hi"]', start_line=2, flags=(), value=('echo', 'hi')))

dockerfile.parse_string(s)

Parse a dockerfile using a string. Returns a tuple of dockerfile.Command objects representing each layer of the Dockerfile. Possible exceptions:

  • dockerfile.GoParseError: The Dockerfile was not parseable.
>>> dockerfile.parse_string('FROM ubuntu:xenial')
(Command(cmd='from', sub_cmd=None, json=False, original='FROM ubuntu:xenial', start_line=1, flags=(), value=('ubuntu:xenial',)),)

go library

Slightly more convenient than the api provided by docker/docker? Might not be terribly useful -- the main point of this repository was a python wrapper.

Installation

go get github.com/asottile/dockerfile

Usage

godoc

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

dockerfile-3.3.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distributions

dockerfile-3.3.1-cp38-abi3-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.8+ Windows x86-64

dockerfile-3.3.1-cp38-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.5+ x86-64

dockerfile-3.3.1-cp38-abi3-macosx_13_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.8+ macOS 13.0+ ARM64

dockerfile-3.3.1-cp38-abi3-macosx_12_0_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.8+ macOS 12.0+ x86-64

File details

Details for the file dockerfile-3.3.1.tar.gz.

File metadata

  • Download URL: dockerfile-3.3.1.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for dockerfile-3.3.1.tar.gz
Algorithm Hash digest
SHA256 4790b3d96d1018302b27661f9624d851a4b7113bce1dbb2d7509991e81a387a9
MD5 3c7dcd948e92afacd66c9d6509734f38
BLAKE2b-256 5494754d7d016f4fbbadcd280b2f99fb9b86567ef9094b241affa40c75083fe4

See more details on using hashes here.

File details

Details for the file dockerfile-3.3.1-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for dockerfile-3.3.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 af88c99a1366622a288b663a660159b1e2c599bcad094563af7bbc3a1be3035f
MD5 ea27199bf9559bc18ef21c49092729a7
BLAKE2b-256 1bc03acb22254f005c9a1c90a26b95a60ac21bd7dd54058d59d34ba8638f0913

See more details on using hashes here.

File details

Details for the file dockerfile-3.3.1-cp38-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for dockerfile-3.3.1-cp38-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 16a0c353e8d41dfedcbbb39d2c3e911ed5379269ee9fddd7f2fd7dc8d43c957e
MD5 54eae8029f9cbd148fd28b2a832e88e3
BLAKE2b-256 ad6029cac20ce5d96022d0976cf562f4f28f18a224cd95e7a4558b9fd56ee08c

See more details on using hashes here.

File details

Details for the file dockerfile-3.3.1-cp38-abi3-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for dockerfile-3.3.1-cp38-abi3-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 93bc503ed34dbbb52214753c560942f59686b3f26d0ed392d6b48fa3c238c0b1
MD5 14c74940bce2af293bda4989bc0c3d39
BLAKE2b-256 97f5ae500b918d6cf4229f26ab40bfec06cad0af5425dd471e747c4fea26d0c9

See more details on using hashes here.

File details

Details for the file dockerfile-3.3.1-cp38-abi3-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for dockerfile-3.3.1-cp38-abi3-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 c222ee8b26017df0d9c5dcb9c4e02452f508137fc89e214758f68d57c50f5d2a
MD5 c2ebe2cc079a7a207aba232f337c6266
BLAKE2b-256 46c8bbc9cbfba6943a422b3c72a6e862665d7d811aed882fe2f0698cf6b2f008

See more details on using hashes here.

Supported by

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