Exemple #1
0
func runRun(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}

	lockfile, err := getLock()
	if err != nil {
		stderr("run: %v", err)
		return 1
	}
	defer func() {
		if err := releaseLock(lockfile); err != nil {
			stderr("run: %v", err)
			exit = 1
		}
	}()

	if debug {
		stderr("Running: %v", args)
	}

	err = lib.Run(tmpacipath(), depstorepath(), targetpath(), scratchpath(), workpath(), args, insecure)

	if err != nil {
		stderr("run: %v", err)
		return 1
	}

	return 0
}
Exemple #2
0
func runCopy(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 2 {
		stderr("copy: incorrect number of arguments")
		return 1
	}

	lockfile, err := getLock()
	if err != nil {
		stderr("copy: %v", err)
		return 1
	}
	defer func() {
		if err := releaseLock(lockfile); err != nil {
			stderr("copy: %v", err)
			exit = 1
		}
	}()

	if debug {
		stderr("Copying host:%s to aci:%s", args[0], args[1])
	}

	err = lib.Copy(tmpacipath(), args[0], args[1])

	if err != nil {
		stderr("copy: %v", err)
		return 1
	}

	return 0
}
Exemple #3
0
func runSetGroup(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 1 {
		stderr("set-group: incorrect number of arguments")
		return 1
	}

	lockfile, err := getLock()
	if err != nil {
		stderr("set-group: %v", err)
		return 1
	}
	defer func() {
		if err := releaseLock(lockfile); err != nil {
			stderr("set-group: %v", err)
			exit = 1
		}
	}()

	if debug {
		stderr("Setting group to %s", args[0])
	}

	err = lib.SetGroup(tmpacipath(), args[0])

	if err != nil {
		stderr("set-group: %v", err)
		return 1
	}

	return 0
}
Exemple #4
0
func runRmDep(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 1 {
		stderr("dependency remove: incorrect number of arguments")
		return 1
	}

	lockfile, err := getLock()
	if err != nil {
		stderr("dependency remove: %v", err)
		return 1
	}
	defer func() {
		if err := releaseLock(lockfile); err != nil {
			stderr("dependency remove: %v", err)
			exit = 1
		}
	}()

	if debug {
		stderr("Removing dependency %q", args[0])
	}

	err = lib.RemoveDependency(tmpacipath(), args[0])

	if err != nil {
		stderr("dependency remove: %v", err)
		return 1
	}

	return 0
}
Exemple #5
0
func runAddMount(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 2 {
		stderr("mount add: incorrect number of arguments")
		return 1
	}

	if debug {
		if readOnly {
			stderr("Adding read only mount point %q=%q", args[0], args[1])
		} else {
			stderr("Adding mount point %q=%q", args[0], args[1])
		}
	}

	err := newACBuild().AddMount(args[0], args[1], readOnly)

	if err != nil {
		stderr("mount add: %v", err)
		return 1
	}

	return 0
}
Exemple #6
0
func runAddPort(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 3 {
		stderr("port add: incorrect number of arguments")
		return 1
	}
	port, err := strconv.ParseUint(args[2], 10, 16)
	if err != nil {
		stderr("port add: port must be a positive number between 0 and 65535")
		return 1
	}

	if debug {
		stderr("Adding port %q=%q", args[0], args[1])
	}

	err = newACBuild().AddPort(args[0], args[1], uint(port), count, socketActivated)

	if err != nil {
		stderr("port add: %v", err)
		return getErrorCode(err)
	}

	return 0
}
Exemple #7
0
func runRemoveEnv(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) > 1 {
		stderr("environment remove: incorrect number of arguments")
		return 1
	}

	lockfile, err := getLock()
	if err != nil {
		stderr("environment remove: %v", err)
		return 1
	}
	defer func() {
		if err := releaseLock(lockfile); err != nil {
			stderr("environment remove: %v", err)
			exit = 1
		}
	}()

	if debug {
		stderr("Removing environment variable %q", args[0])
	}

	err = lib.RemoveEnv(tmpacipath(), args[0])

	if err != nil {
		stderr("environment remove: %v", err)
		return 1
	}

	return 0
}
Exemple #8
0
func runAddLabel(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 2 {
		stderr("label add: incorrect number of arguments")
		return 1
	}

	lockfile, err := getLock()
	if err != nil {
		stderr("label add: %v", err)
		return 1
	}
	defer func() {
		if err := releaseLock(lockfile); err != nil {
			stderr("label add: %v", err)
			exit = 1
		}
	}()

	if debug {
		stderr("Adding label %q=%q", args[0], args[1])
	}

	err = lib.AddLabel(tmpacipath(), args[0], args[1])

	if err != nil {
		stderr("label add: %v", err)
		return 1
	}

	return 0
}
Exemple #9
0
func runCopy(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if (!toDir && len(args) != 2) || (toDir && len(args) < 2) {
		stderr("copy: incorrect number of arguments")
		return 1
	}

	if debug {
		stderr("Copying host:%s to aci:%s", args[0], args[1])
	}

	var err error
	if toDir {
		err = newACBuild().CopyToDir(args[:len(args)-1], args[len(args)-1])
	} else {
		err = newACBuild().CopyToTarget(args[0], args[1])
	}

	if err != nil {
		stderr("copy: %v", err)
		return getErrorCode(err)
	}

	return 0
}
Exemple #10
0
func runAddDep(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 1 {
		stderr("dependency add: incorrect number of arguments")
		return 1
	}

	if debug {
		stderr("Adding dependency %q", args[0])
	}

	app, err := discovery.NewAppFromString(args[0])
	if err != nil {
		stderr("dependency add: couldn't parse dependency name: %v", err)
		return 1
	}

	appcLabels := types.Labels(labels)

	for name, value := range app.Labels {
		if _, ok := appcLabels.Get(string(name)); ok {
			stderr("multiple %s labels specified", name)
			return 1
		}
		appcLabels = append(appcLabels, types.Label{
			Name:  name,
			Value: value,
		})
	}

	var hash *types.Hash
	if imageId != "" {
		var err error
		hash, err = types.NewHash(imageId)
		if err != nil {
			stderr("dependency add: couldn't parse image ID: %v", err)
			return 1
		}
	}

	err = newACBuild().AddDependency(app.Name, hash, appcLabels, size)

	if err != nil {
		stderr("dependency add: %v", err)
		return getErrorCode(err)
	}

	return 0
}
Exemple #11
0
func runCat(cmd *cobra.Command, args []string) (exit int) {
	if len(args) != 0 {
		cmd.Usage()
		return 1
	}

	if debug {
		stderr("Printing manifest from current build")
	}

	err := newACBuild().CatManifest(prettyPrint)
	if err != nil {
		stderr("cat-manifest: %v", err)
		return 1
	}

	return 0
}
Exemple #12
0
func runSetPreStart(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}

	if debug {
		stderr("Setting pre-start event handler to %v", args)
	}

	err := newACBuild().SetPreStart(args)

	if err != nil {
		stderr("pre-start: %v", err)
		return 1
	}

	return 0
}
Exemple #13
0
func runWrite(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}

	if debug {
		stderr("Writing ACI to %s", args[0])
	}

	err := newACBuild().Write(args[0], overwrite, sign, args[1:])

	if err != nil {
		stderr("write: %v", err)
		return 1
	}

	return 0
}
Exemple #14
0
func runSetPostStop(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}

	if debug {
		stderr("Setting post-stop event handler to %v", args)
	}

	err := newACBuild().SetPostStop(args)

	if err != nil {
		stderr("post-stop: %v", err)
		return 1
	}

	return 0
}
Exemple #15
0
func runRun(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}

	if debug {
		stderr("Running: %v", args)
	}

	err := lib.Run(tmpacipath(), depstorepath(), targetpath(), scratchpath(), workpath(), args, insecure)

	if err != nil {
		stderr("run: %v", err)
		return 1
	}

	return 0
}
Exemple #16
0
func runAddIso(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 2 {
		stderr("isolator add: incorrect number of arguments")
		return 1
	}

	var r io.Reader
	var err error
	if args[1] == "-" {
		r = os.Stdin
	} else {
		file, err := os.Open(args[1])
		if err != nil {
			stderr("isolator add: %v", err)
			return 1
		}
		defer file.Close()
		r = file
	}

	val, err := ioutil.ReadAll(r)
	if err != nil {
		stderr("isolator add: %v", err)
		return 1
	}

	if debug {
		stderr("Adding isolator %q=%q", args[0], string(val))
	}

	err = newACBuild().AddIsolator(args[0], val)

	if err != nil {
		stderr("isolator add: %v", err)
		return 1
	}

	return 0
}
Exemple #17
0
func runRun(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}

	if debug {
		stderr("Running: %v", args)
	}

	err := newACBuild().Run(args, insecure)

	if err != nil {
		stderr("run: %v", err)
		return 1
	}

	return 0
}
Exemple #18
0
func runSetExec(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}

	if debug {
		stderr("Setting exec command %v", args)
	}

	err := newACBuild().SetExec(args)

	if err != nil {
		stderr("set-exec: %v", err)
		return 1
	}

	return 0
}
Exemple #19
0
func runAddPort(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 3 {
		stderr("port add: incorrect number of arguments")
		return 1
	}
	port, err := strconv.ParseUint(args[2], 10, 16)
	if err != nil {
		stderr("port add: port must be a positive number between 0 and 65535")
		return 1
	}

	lockfile, err := getLock()
	if err != nil {
		stderr("port add: %v", err)
		return 1
	}
	defer func() {
		if err := releaseLock(lockfile); err != nil {
			stderr("port add: %v", err)
			exit = 1
		}
	}()

	if debug {
		stderr("Adding port %q=%q", args[0], args[1])
	}

	err = lib.AddPort(tmpacipath(), args[0], args[1], uint(port), count, socketActivated)

	if err != nil {
		stderr("port add: %v", err)
		return 1
	}

	return 0
}
Exemple #20
0
func runSetName(cmd *cobra.Command, args []string) (exit int) {
	if len(args) > 1 {
		stderr("set-name: incorrect number of arguments")
		return 1
	}
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}

	if debug {
		stderr("Setting name of ACI to %s", args[0])
	}

	err := newACBuild().SetName(args[0])

	if err != nil {
		stderr("set-name: %v", err)
		return 1
	}

	return 0
}
Exemple #21
0
func runSetGroup(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 1 {
		stderr("set-group: incorrect number of arguments")
		return 1
	}

	if debug {
		stderr("Setting group to %s", args[0])
	}

	err := lib.SetGroup(tmpacipath(), args[0])

	if err != nil {
		stderr("set-group: %v", err)
		return 1
	}

	return 0
}
Exemple #22
0
func runRmAnno(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 1 {
		stderr("annotation remove: incorrect number of arguments")
		return 1
	}

	if debug {
		stderr("Removing annotation %q", args[0])
	}

	err := newACBuild().RemoveAnnotation(args[0])

	if err != nil {
		stderr("annotation remove: %v", err)
		return getErrorCode(err)
	}

	return 0
}
Exemple #23
0
func runAddAnno(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 2 {
		stderr("annotation add: incorrect number of arguments")
		return 1
	}

	if debug {
		stderr("Adding annotation %q=%q", args[0], args[1])
	}

	err := newACBuild().AddAnnotation(args[0], args[1])

	if err != nil {
		stderr("annotation add: %v", err)
		return getErrorCode(err)
	}

	return 0
}
Exemple #24
0
func runRemoveIso(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) > 1 {
		stderr("isolator remove: incorrect number of arguments")
		return 1
	}

	if debug {
		stderr("Removing isolator %q", args[0])
	}

	err := newACBuild().RemoveIsolator(args[0])

	if err != nil {
		stderr("isolator remove: %v", err)
		return 1
	}

	return 0
}
Exemple #25
0
func runSetUser(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 1 {
		stderr("set-user: incorrect number of arguments")
		return 1
	}

	if debug {
		stderr("Setting user to %s", args[0])
	}

	err := newACBuild().SetUser(args[0])

	if err != nil {
		stderr("set-user: %v", err)
		return 1
	}

	return 0
}
Exemple #26
0
func runSetGroup(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 1 {
		stderr("set-group: incorrect number of arguments")
		return 1
	}

	if debug {
		stderr("Setting group to %s", args[0])
	}

	err := newACBuild().SetGroup(args[0])

	if err != nil {
		stderr("set-group: %v", err)
		return getErrorCode(err)
	}

	return 0
}
Exemple #27
0
func runRmDep(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 1 {
		stderr("dependency remove: incorrect number of arguments")
		return 1
	}

	if debug {
		stderr("Removing dependency %q", args[0])
	}

	err := lib.RemoveDependency(tmpacipath(), args[0])

	if err != nil {
		stderr("dependency remove: %v", err)
		return 1
	}

	return 0
}
Exemple #28
0
func runReplaceMan(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 1 {
		stderr("replace-manifest: incorrect number of arguments")
		return 1
	}

	if debug {
		stderr("Replacing manifest in ACI with the manifest at ", args[0])
	}

	err := newACBuild().ReplaceManifest(args[0])

	if err != nil {
		stderr("replace-manifest: %v", err)
		return 1
	}

	return 0
}
Exemple #29
0
func runCopy(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 2 {
		stderr("copy: incorrect number of arguments")
		return 1
	}

	if debug {
		stderr("Copying host:%s to aci:%s", args[0], args[1])
	}

	err := newACBuild().Copy(args[0], args[1])

	if err != nil {
		stderr("copy: %v", err)
		return 1
	}

	return 0
}
Exemple #30
0
func runAddEnv(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 2 {
		stderr("environment add: incorrect number of arguments")
		return 1
	}

	if debug {
		stderr("Adding environment variable %q=%q", args[0], args[1])
	}

	err := lib.AddEnv(tmpacipath(), args[0], args[1])

	if err != nil {
		stderr("environment add: %v", err)
		return 1
	}

	return 0
}