Expand description
Dockerfile parser, written in Rust.
§Usage
To use this crate as a library, add this to your Cargo.toml:
[dependencies]
parse-dockerfile = { version = "0.1", default-features = false }ⓘ Note
We recommend disabling default features because they enable CLI-related dependencies which the library part does not use.
§Examples
use parse_dockerfile::{parse, Instruction};
let text = r#"
ARG UBUNTU_VERSION=latest
FROM ubuntu:${UBUNTU_VERSION}
RUN echo
"#;
let dockerfile = parse(text).unwrap();
// Iterate over all instructions.
let mut instructions = dockerfile.instructions.iter();
assert!(matches!(instructions.next(), Some(Instruction::Arg(..))));
assert!(matches!(instructions.next(), Some(Instruction::From(..))));
assert!(matches!(instructions.next(), Some(Instruction::Run(..))));
assert!(matches!(instructions.next(), None));
// Iterate over global args.
let mut global_args = dockerfile.global_args();
let global_arg1 = global_args.next().unwrap();
assert_eq!(global_arg1.arguments.value, "UBUNTU_VERSION=latest");
assert!(matches!(global_args.next(), None));
// Iterate over stages.
let mut stages = dockerfile.stages();
let stage1 = stages.next().unwrap();
assert_eq!(stage1.from.image.value, "ubuntu:${UBUNTU_VERSION}");
let mut stage1_instructions = stage1.instructions.iter();
assert!(matches!(stage1_instructions.next(), Some(Instruction::Run(..))));
assert!(matches!(stage1_instructions.next(), None));
assert!(matches!(stages.next(), None));§Optional features
serde— Implementsserde::Serializetrait for parse-dockerfile types.
Structs§
- AddInstruction
- An
ADDinstruction. - ArgInstruction
- An
ARGinstruction. - CmdInstruction
- A
CMDinstruction. - Copy
Instruction - A
COPYinstruction. - Dockerfile
- A dockerfile.
- Entrypoint
Instruction - An
ENTRYPOINTinstruction. - EnvInstruction
- An
ENVinstruction. - Error
- An error that occurred during parsing the dockerfile.
- Expose
Instruction - An
EXPOSEinstruction. - Flag
- An option flag.
- From
Instruction - A
FROMinstruction. - Healthcheck
Instruction - A
HEALTHCHECKinstruction. - HereDoc
- A here-document.
- Keyword
- A keyword.
- Label
Instruction - A
LABELinstruction. - Maintainer
Instruction - A
MAINTAINERinstruction (deprecated). - Onbuild
Instruction - A
ONBUILDinstruction. - Parse
Iter - An iterator over instructions.
- Parser
Directive - A parser directive.
- Parser
Directives - Parser directives.
- RunInstruction
- A
RUNinstruction. - Shell
Instruction - A
SHELLinstruction. - Spanned
- A spanned value.
- Stage
- A stage.
- Stopsignal
Instruction - A
STOPSIGNALinstruction. - Unescaped
String - An unescaped string.
- User
Instruction - A
USERinstruction. - Volume
Instruction - A
VOLUMEinstruction. - Workdir
Instruction - A
WORKDIRinstruction.
Enums§
- Command
- A command.
- Healthcheck
Arguments - Arguments of the
HEALTHCHECKinstruction. - Instruction
- An instruction.
- Json
OrString Array - A JSON array or space-separated string.
- Source
- A enum that represents source value of
ARGinstruction andCOPYinstruction.
Functions§
- parse
- Parses dockerfile from the given
text. - parse_
iter - Returns an iterator over instructions in the given
text.