dockerfile

package module
Version: v3.1.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2020 License: MIT Imports: 5 Imported by: 6

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllCmds

func AllCmds() []string

List all legal cmds in a dockerfile

Types

type Command

type Command struct {
	Cmd       string   // lowercased command name (ex: `from`)
	SubCmd    string   // for ONBUILD only this holds the sub-command
	Json      bool     // whether the value is written in json form
	Original  string   // The original source line
	StartLine int      // The original source line number which starts this command
	EndLine   int      // The original source line number which ends this command
	Flags     []string // Any flags such as `--from=...` for `COPY`.
	Value     []string // The contents of the command (ex: `ubuntu:xenial`)
}

Represents a single line (layer) in a Dockerfile. For example `FROM ubuntu:xenial`

func ParseFile

func ParseFile(filename string) ([]Command, error)

Parse a Dockerfile from a filename. An IOError or ParseError may occur.

func ParseReader

func ParseReader(file io.Reader) ([]Command, error)

Parse a Dockerfile from a reader. A ParseError may occur.

type IOError

type IOError struct {
	Msg string
}

A failure in opening a file for reading.

func (IOError) Error

func (e IOError) Error() string

type ParseError

type ParseError struct {
	Msg string
}

A failure in parsing the file as a dockerfile.

func (ParseError) Error

func (e ParseError) Error() string

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL