Exemple #1
0
func (c *Builder) CreateContainer(original string) (*lxc.Container, error) {
	cloned, err := util.UUID()
	if err != nil {
		log.Errorf("Failed to generate uuid. Error: %v", err)
		return nil, err
	}
	ct, err := util.CloneAndStartContainer(original, cloned)
	if err != nil {
		log.Errorf("Failed to clone container %s as %s. Error: %v", original, cloned, err)
		return nil, err
	}
	return ct, nil
}
Exemple #2
0
func (spec *Spec) Build() error {
	for _, statement := range spec.Statements {
		log.Infof("Proecssing:|%s|\n", statement)
		words := strings.Fields(statement)
		switch words[0] {
		case "FROM":
			if spec.State.Container != nil {
				log.Errorf("Container already built. Multiple FROM declaration?\n")
				return errors.New("Container already built. Multiple FROM declaration?")
			}
			var err error
			spec.State.Container, err = util.CloneAndStartContainer(words[1], spec.ID)
			if err != nil {
				log.Errorf("Failed to clone container. Error: %s\n", err)
				return err
			}
		case "RUN":
			if spec.State.Container == nil {
				log.Error("No container has been created yet. Use FROM directive")
				return errors.New("No container has been created yet. Use FROM directive")
			}
			command := words[1:len(words)]
			log.Debugf("Attempting to execute: %#v\n", command)
			if err := spec.runCommand(command); err != nil {
				log.Errorf("Failed to run command inside container. Error: %s\n", err)
				return err
			}
		case "ENV":
			for i := 1; i < len(words); i++ {
				if strings.Contains(words[i], "=") {
					spec.State.Env = append(spec.State.Env, words[i])
				} else {
					spec.State.Env = append(spec.State.Env, words[i]+"="+words[i+1])
					i++
				}
			}
		case "WORKDIR":
			spec.State.Cwd = words[1]
		case "ADD":
			// setup bind mount
		case "COPY":
			// copy over files
		case "LABEL":
			// FIXME
		case "USER":
			// set exec user id
		case "VOLUME":
			// FIXME
		case "STOPSIGNAL":
			// FIXME
		case "MAINTAINER":
			// FIXME
		case "CMD":
			// FIXME
		case "ENTRYPOINT":
			// FIXME
		case "EXPOSE":
			// FIXME

		}
	}
	return nil
}