Beispiel #1
0
func (command *PublishCommand) Run(args []string) int {

	flagSet := flag.NewFlagSet("publish", flag.ExitOnError)
	flagSet.Usage = func() { fmt.Println(command.Help()) }
	if err := flagSet.Parse(args); err != nil {
		log.Errorln(err)
		return -1
	}

	args = flagSet.Args()
	if len(args) != 4 {
		log.Errorln(errors.New("Insufficient argument. Please pass container image file, s3 region, bucket and key"))
		return -1
	}
	if err := specification.Publish(args[0], args[1], args[2], args[3]); err != nil {
		log.Errorln(err)
		return -1
	}
	return 0
}
Beispiel #2
0
func (command *BuildCommand) Run(args []string) int {

	flagSet := flag.NewFlagSet("build", flag.ExitOnError)
	flagSet.Usage = func() { fmt.Println(command.Help()) }

	file := flagSet.String("specfile", "Dockerfile", "Container build specification file")
	stopAfterBuild := flagSet.Bool("stop", false, "Stop container after build")
	ephemeral := flagSet.Bool("ephemeral", false, "Destroy the container after creating it")
	name := flagSet.String("name", "", "Name of the resulting container (defaults to randomly generated UUID)")
	export := flagSet.String("export", "", "File path for the container tarball")
	exportSudo := flagSet.Bool("export-sudo", false, "Use sudo while invoking tar")
	volume := flagSet.String("volume", "", "Mount host directory inside container. Format: '[host_directory:]container_directory[:mount options]")
	publish := flagSet.String("publish", "", "Publish tarball in s3 (assumes -stop, -export)")

	flagSet.Parse(args)
	if *publish != "" {
		if *export == "" {
			uuid, err := specification.UUID()
			if err != nil {
				log.Errorln(err)
				return -1
			}
			*export = uuid
		}
	}

	if *export != "" {
		*stopAfterBuild = true
	}
	if *name == "" {
		uuid, err := specification.UUID()
		if err != nil {
			log.Errorln(err)
			return -1
		}
		name = &uuid
	}

	spec := specification.New(*name, *file)

	if err := spec.Parse(); err != nil {
		log.Errorf("Failed to parse dockerfile. Error: %s\n", err)
		return -1
	}

	if err := spec.Build(*volume); err != nil {
		log.Errorf("Failed to build container from dockerfile. Error: %s\n", err)
		return -1
	}

	if *stopAfterBuild {
		log.Infof("Stopping container")
		if err := spec.Stop(); err != nil {
			log.Errorf("Failed to stop container. Error: %s\n", err)
			return -1
		}
	}

	if *export != "" {
		log.Infof("Exporting container")
		if err := spec.Export(*export, *exportSudo); err != nil {
			log.Errorf("Failed to export container. Error: %s\n", err)
			return -1
		}
	}

	if *ephemeral {
		log.Infof("Ephemeral mode. Destroying the container")
		if err := spec.Destroy(); err != nil {
			log.Errorf("Failed to destroy container. Error: %s\n", err)
			return -1
		}
	}
	if *publish != "" {
		parts := strings.Split(*publish, "/")
		bucket := parts[0]
		key := strings.Join(parts[1:], "/")
		if err := specification.Publish(*export, "us-west-1", bucket, key); err != nil {
			log.Errorln(err)
			return -1
		}
	}
	return 0
}