Skip to content

Instantly share code, notes, and snippets.

@efekarakus
Created Sep 12, 2021
Embed
What would you like to do?
Prototyping dependency removal
// parse parses the contents of a Dockerfile into a Dockerfile struct.
func parse(content string) (*Dockerfile, error) {
var df Dockerfile
//df.ExposedPorts = []portConfig{}
//
//ast, err := parser.Parse(strings.NewReader(content))
//if err != nil {
// return nil, fmt.Errorf("parse reader: %w", err)
//}
//
//for _, child := range ast.AST.Children {
// // ParseInstruction converts an AST to a typed instruction.
// // Does prevalidation checks before parsing
// // Example of an instruction is HEALTHCHECK CMD curl -f http://localhost/ || exit 1.
// instruction, err := instructions.ParseInstruction(child)
// if err != nil {
// return nil, fmt.Errorf("parse instructions: %w", err)
// }
// inst := fmt.Sprint(instruction)
//
// // Getting the value at a children will return the Dockerfile directive
// switch d := child.Value; d {
// case "expose":
// currentPorts := parseExpose(inst)
// df.ExposedPorts = append(df.ExposedPorts, currentPorts...)
// case "healthcheck":
// healthcheckOptions, err := parseHealthCheck(inst)
// if err != nil {
// return nil, err
// }
// df.HealthCheck = healthcheckOptions
// }
//}
return &df, nil
}
- github.com/moby/buildkit v0.8.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment