Skip to main content

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

Project description

Build Status Build 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.ParseError: 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.ParseError: 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-2.1.0.tar.gz (17.3 kB view hashes)

Uploaded Source

Built Distributions

dockerfile-2.1.0-cp37-cp37m-manylinux1_x86_64.whl (1.8 MB view hashes)

Uploaded CPython 3.7m

dockerfile-2.1.0-cp37-cp37m-macosx_10_9_x86_64.whl (1.7 MB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

dockerfile-2.1.0-cp36-cp36m-manylinux1_x86_64.whl (1.8 MB view hashes)

Uploaded CPython 3.6m

dockerfile-2.1.0-cp36-cp36m-macosx_10_14_x86_64.whl (1.7 MB view hashes)

Uploaded CPython 3.6m macOS 10.14+ x86-64

dockerfile-2.1.0-cp35-cp35m-manylinux1_x86_64.whl (1.8 MB view hashes)

Uploaded CPython 3.5m

dockerfile-2.1.0-cp34-cp34m-manylinux1_x86_64.whl (1.8 MB view hashes)

Uploaded CPython 3.4m

dockerfile-2.1.0-cp27-cp27mu-manylinux1_x86_64.whl (1.8 MB view hashes)

Uploaded CPython 2.7mu

dockerfile-2.1.0-cp27-cp27m-macosx_10_14_intel.whl (1.7 MB view hashes)

Uploaded CPython 2.7m macOS 10.14+ intel

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