Skip to content

Instantly share code, notes, and snippets.

@efekarakus
Created September 12, 2021 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save efekarakus/038e3e576cd66e159e83088fe68055d0 to your computer and use it in GitHub Desktop.
Save efekarakus/038e3e576cd66e159e83088fe68055d0 to your computer and use it in GitHub Desktop.
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