grim/convey

closing closed branch again
multiple-images
2018-01-26, Gary Kramlich
8e45b1f8ccff
closing closed branch again
/*
* Convey
* Copyright 2016-2017 Gary Kramlich <grim@reaperworld.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package main
import (
"fmt"
"os"
"github.com/alecthomas/kingpin"
"github.com/aphistic/gomol"
"bitbucket.org/rw_grim/convey/config"
"bitbucket.org/rw_grim/convey/environment"
"bitbucket.org/rw_grim/convey/logging"
"bitbucket.org/rw_grim/convey/options"
"bitbucket.org/rw_grim/convey/runners"
)
const (
version = "0.3.2dev"
)
var (
app = kingpin.New("convey", "container runner").Version(version)
color = app.Flag("color", "Enable colorized output").Default("true").Bool()
configFile = app.Flag("config", "The config file name to use").Short('f').Default("convey.yml").String()
cpuShares = app.Flag("cpu-shares", "The amount of cpu shares to give to a run task").Short('c').String()
env = app.Flag("env", "Set environment variables").Short('e').Strings()
forceSequential = app.Flag("force-sequential", "Don't run anything concurrently").Short('S').Default("False").Bool()
graphviz = app.Flag("graphviz", "Output a graphviz diagram of the config file").Short('g').Default("False").Bool()
keep = app.Flag("keep", "Keep the workspace volume").Short('k').Hidden().Default("False").Bool()
listTasks = app.Flag("list-tasks", "List the supported tasks").Short('L').Default("false").Bool()
memory = app.Flag("memory", "The ammount of memor to give the run task").Short('m').String()
showConfig = app.Flag("show-config", "Show a dump of the config file").Short('C').Hidden().Default("false").Bool()
sshAgent = app.Flag("ssh-agent", "Enabled ssh-agent support for tasks").Default("false").Bool()
taskTimeout = app.Flag("timeout", "The maximum amount of time a task can run in seconds. 0 to disable").Default("15m").Duration()
verbose = app.Flag("verbose", "Be more verbose").Short('v').Default("False").Bool()
planName = app.Arg("plan", "The plan or list of plans to run in specified order").Default("default").Strings()
)
func main() {
exitCode := 0
defer func() {
os.Exit(exitCode)
}()
app.Parse(os.Args[1:])
// now load the config
config, err := config.LoadFile(*configFile)
if err != nil {
fmt.Printf("%s\n", err)
os.Exit(1)
}
if err = logging.Setup(*color, *verbose); err != nil {
fmt.Printf("failed to setup logging: %s\n", err)
os.Exit(1)
}
defer gomol.ShutdownLoggers()
// find our default environment variables and then update them with the
// values from the command line
defEnv := environment.Initialize()
opts := &options.Options{
KeepWorkspace: *keep,
ForceSequential: *forceSequential,
EnableSSHAgent: *sshAgent,
TaskTimeout: *taskTimeout,
Environment: environment.Merge(defEnv, *env),
CPUShares: *cpuShares,
Memory: *memory,
}
if err = opts.Valid(); err != nil {
fmt.Printf("%s\n", err)
exitCode = 1
return
}
var runner runners.Runner
if *graphviz {
runner = &runners.Graphviz{}
} else if *listTasks {
runner = &runners.ListTasks{}
} else if *showConfig {
runner = &runners.ShowConfig{}
} else {
runner = &runners.Default{}
}
exitCode = runner.Run(config, *planName, *env, opts)
}