예제 #1
0
// NewRockerfile reads parses Rockerfile from an io.Reader
func NewRockerfile(name string, in io.Reader, vars template.Vars, funs template.Funs) (r *Rockerfile, err error) {
	r = &Rockerfile{
		Name: name,
		Vars: vars,
		Funs: funs,
	}

	var (
		source  []byte
		content *bytes.Buffer
	)

	if source, err = ioutil.ReadAll(in); err != nil {
		return nil, fmt.Errorf("Failed to read Rockerfile %s, error: %s", name, err)
	}

	r.Source = string(source)

	if content, err = template.Process(name, bytes.NewReader(source), vars, funs); err != nil {
		return nil, err
	}

	r.Content = content.String()

	// TODO: update parser from Docker

	if r.rootNode, err = parser.Parse(content); err != nil {
		return nil, err
	}

	return r, nil
}
예제 #2
0
func parseOnbuildCommands(onBuildTriggers []string) ([]ConfigCommand, error) {
	commands := []ConfigCommand{}

	for _, step := range onBuildTriggers {

		ast, err := parser.Parse(strings.NewReader(step))
		if err != nil {
			return commands, err
		}

		for _, n := range ast.Children {
			switch strings.ToUpper(n.Value) {
			case "ONBUILD":
				return commands, fmt.Errorf("Chaining ONBUILD via `ONBUILD ONBUILD` isn't allowed")
			case "MAINTAINER", "FROM":
				return commands, fmt.Errorf("%s isn't allowed as an ONBUILD trigger", n.Value)
			}

			commands = append(commands, parseCommand(n, true))
		}
	}

	return commands, nil
}