mirror of
https://github.com/rancher/os.git
synced 2025-09-04 00:04:25 +00:00
Bump libcompose and its dependencies
This commit is contained in:
293
vendor/github.com/docker/libcompose/cli/app/app.go
generated
vendored
293
vendor/github.com/docker/libcompose/cli/app/app.go
generated
vendored
@@ -3,12 +3,17 @@ package app
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/docker/libcompose/project"
|
||||
"github.com/docker/libcompose/project/options"
|
||||
)
|
||||
|
||||
// ProjectAction is an adapter to allow the use of ordinary functions as libcompose actions.
|
||||
@@ -19,7 +24,7 @@ import (
|
||||
// Usage: "List containers",
|
||||
// Action: app.WithProject(factory, app.ProjectPs),
|
||||
// }
|
||||
type ProjectAction func(project *project.Project, c *cli.Context)
|
||||
type ProjectAction func(project project.APIProject, c *cli.Context) error
|
||||
|
||||
// BeforeApp is an action that is executed before any cli command.
|
||||
func BeforeApp(c *cli.Context) error {
|
||||
@@ -30,200 +35,268 @@ func BeforeApp(c *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// WithProject is an helper function to create a cli.Command action with a ProjectFactory.
|
||||
func WithProject(factory ProjectFactory, action ProjectAction) func(context *cli.Context) {
|
||||
return func(context *cli.Context) {
|
||||
// WithProject is a helper function to create a cli.Command action with a ProjectFactory.
|
||||
func WithProject(factory ProjectFactory, action ProjectAction) func(context *cli.Context) error {
|
||||
return func(context *cli.Context) error {
|
||||
p, err := factory.Create(context)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Failed to read project: %v", err)
|
||||
}
|
||||
action(p, context)
|
||||
return action(p, context)
|
||||
}
|
||||
}
|
||||
|
||||
// ProjectPs lists the containers.
|
||||
func ProjectPs(p *project.Project, c *cli.Context) {
|
||||
allInfo := project.InfoSet{}
|
||||
func ProjectPs(p project.APIProject, c *cli.Context) error {
|
||||
qFlag := c.Bool("q")
|
||||
for name := range p.Configs {
|
||||
service, err := p.CreateService(name)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
info, err := service.Info(qFlag)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
allInfo = append(allInfo, info...)
|
||||
allInfo, err := p.Ps(context.Background(), qFlag, c.Args()...)
|
||||
if err != nil {
|
||||
return cli.NewExitError(err.Error(), 1)
|
||||
}
|
||||
|
||||
os.Stdout.WriteString(allInfo.String(!qFlag))
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProjectPort prints the public port for a port binding.
|
||||
func ProjectPort(p *project.Project, c *cli.Context) {
|
||||
func ProjectPort(p project.APIProject, c *cli.Context) error {
|
||||
if len(c.Args()) != 2 {
|
||||
logrus.Fatalf("Please pass arguments in the form: SERVICE PORT")
|
||||
return cli.NewExitError("Please pass arguments in the form: SERVICE PORT", 1)
|
||||
}
|
||||
|
||||
index := c.Int("index")
|
||||
protocol := c.String("protocol")
|
||||
serviceName := c.Args()[0]
|
||||
privatePort := c.Args()[1]
|
||||
|
||||
service, err := p.CreateService(c.Args()[0])
|
||||
port, err := p.Port(context.Background(), index, protocol, serviceName, privatePort)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
return cli.NewExitError(err.Error(), 1)
|
||||
}
|
||||
|
||||
containers, err := service.Containers()
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if index < 1 || index > len(containers) {
|
||||
logrus.Fatalf("Invalid index %d", index)
|
||||
}
|
||||
|
||||
output, err := containers[index-1].Port(fmt.Sprintf("%s/%s", c.Args()[1], protocol))
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
fmt.Println(output)
|
||||
fmt.Println(port)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProjectDown brings all services down.
|
||||
func ProjectDown(p *project.Project, c *cli.Context) {
|
||||
err := p.Down(c.Args()...)
|
||||
// ProjectStop stops all services.
|
||||
func ProjectStop(p project.APIProject, c *cli.Context) error {
|
||||
err := p.Stop(context.Background(), c.Int("timeout"), c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
return cli.NewExitError(err.Error(), 1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProjectDown brings all services down (stops and clean containers).
|
||||
func ProjectDown(p project.APIProject, c *cli.Context) error {
|
||||
options := options.Down{
|
||||
RemoveVolume: c.Bool("volumes"),
|
||||
RemoveImages: options.ImageType(c.String("rmi")),
|
||||
RemoveOrphans: c.Bool("remove-orphans"),
|
||||
}
|
||||
err := p.Down(context.Background(), options, c.Args()...)
|
||||
if err != nil {
|
||||
return cli.NewExitError(err.Error(), 1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProjectBuild builds or rebuilds services.
|
||||
func ProjectBuild(p *project.Project, c *cli.Context) {
|
||||
err := p.Build(c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
func ProjectBuild(p project.APIProject, c *cli.Context) error {
|
||||
config := options.Build{
|
||||
NoCache: c.Bool("no-cache"),
|
||||
ForceRemove: c.Bool("force-rm"),
|
||||
Pull: c.Bool("pull"),
|
||||
}
|
||||
err := p.Build(context.Background(), config, c.Args()...)
|
||||
if err != nil {
|
||||
return cli.NewExitError(err.Error(), 1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProjectCreate creates all services but do not start them.
|
||||
func ProjectCreate(p *project.Project, c *cli.Context) {
|
||||
err := p.Create(c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
func ProjectCreate(p project.APIProject, c *cli.Context) error {
|
||||
options := options.Create{
|
||||
NoRecreate: c.Bool("no-recreate"),
|
||||
ForceRecreate: c.Bool("force-recreate"),
|
||||
NoBuild: c.Bool("no-build"),
|
||||
}
|
||||
err := p.Create(context.Background(), options, c.Args()...)
|
||||
if err != nil {
|
||||
return cli.NewExitError(err.Error(), 1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProjectUp brings all services up.
|
||||
func ProjectUp(p *project.Project, c *cli.Context) {
|
||||
err := p.Up(c.Args()...)
|
||||
func ProjectUp(p project.APIProject, c *cli.Context) error {
|
||||
options := options.Up{
|
||||
Create: options.Create{
|
||||
NoRecreate: c.Bool("no-recreate"),
|
||||
ForceRecreate: c.Bool("force-recreate"),
|
||||
NoBuild: c.Bool("no-build"),
|
||||
},
|
||||
}
|
||||
ctx, cancelFun := context.WithCancel(context.Background())
|
||||
err := p.Up(ctx, options, c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
return cli.NewExitError(err.Error(), 1)
|
||||
}
|
||||
if !c.Bool("d") {
|
||||
signalChan := make(chan os.Signal, 1)
|
||||
cleanupDone := make(chan bool)
|
||||
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
|
||||
errChan := make(chan error)
|
||||
go func() {
|
||||
errChan <- p.Log(ctx, true, c.Args()...)
|
||||
}()
|
||||
go func() {
|
||||
select {
|
||||
case <-signalChan:
|
||||
fmt.Printf("\nGracefully stopping...\n")
|
||||
cancelFun()
|
||||
ProjectStop(p, c)
|
||||
cleanupDone <- true
|
||||
case err := <-errChan:
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
cleanupDone <- true
|
||||
}
|
||||
}()
|
||||
<-cleanupDone
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProjectRun runs a given command within a service's container.
|
||||
func ProjectRun(p project.APIProject, c *cli.Context) error {
|
||||
if len(c.Args()) == 1 {
|
||||
logrus.Fatal("No service specified")
|
||||
}
|
||||
|
||||
if !c.Bool("d") {
|
||||
wait()
|
||||
serviceName := c.Args()[0]
|
||||
commandParts := c.Args()[1:]
|
||||
|
||||
exitCode, err := p.Run(context.Background(), serviceName, commandParts)
|
||||
if err != nil {
|
||||
return cli.NewExitError(err.Error(), 1)
|
||||
}
|
||||
return cli.NewExitError("", exitCode)
|
||||
}
|
||||
|
||||
// ProjectStart starts services.
|
||||
func ProjectStart(p *project.Project, c *cli.Context) {
|
||||
err := p.Start(c.Args()...)
|
||||
func ProjectStart(p project.APIProject, c *cli.Context) error {
|
||||
err := p.Start(context.Background(), c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
return cli.NewExitError(err.Error(), 1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProjectRestart restarts services.
|
||||
func ProjectRestart(p *project.Project, c *cli.Context) {
|
||||
err := p.Restart(c.Args()...)
|
||||
func ProjectRestart(p project.APIProject, c *cli.Context) error {
|
||||
err := p.Restart(context.Background(), c.Int("timeout"), c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
return cli.NewExitError(err.Error(), 1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProjectLog gets services logs.
|
||||
func ProjectLog(p *project.Project, c *cli.Context) {
|
||||
err := p.Log(c.Args()...)
|
||||
func ProjectLog(p project.APIProject, c *cli.Context) error {
|
||||
err := p.Log(context.Background(), c.Bool("follow"), c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
return cli.NewExitError(err.Error(), 1)
|
||||
}
|
||||
wait()
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProjectPull pulls images for services.
|
||||
func ProjectPull(p *project.Project, c *cli.Context) {
|
||||
err := p.Pull(c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
func ProjectPull(p project.APIProject, c *cli.Context) error {
|
||||
err := p.Pull(context.Background(), c.Args()...)
|
||||
if err != nil && !c.Bool("ignore-pull-failures") {
|
||||
return cli.NewExitError(err.Error(), 1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProjectDelete delete services.
|
||||
func ProjectDelete(p *project.Project, c *cli.Context) {
|
||||
if !c.Bool("force") && len(c.Args()) == 0 {
|
||||
logrus.Fatal("Will not remove all services without --force")
|
||||
// ProjectDelete deletes services.
|
||||
func ProjectDelete(p project.APIProject, c *cli.Context) error {
|
||||
options := options.Delete{
|
||||
RemoveVolume: c.Bool("v"),
|
||||
}
|
||||
err := p.Delete(c.Args()...)
|
||||
if !c.Bool("force") {
|
||||
options.BeforeDeleteCallback = func(stoppedContainers []string) bool {
|
||||
fmt.Printf("Going to remove %v\nAre you sure? [yN]\n", strings.Join(stoppedContainers, ", "))
|
||||
var answer string
|
||||
_, err := fmt.Scanln(&answer)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return false
|
||||
}
|
||||
if answer != "y" && answer != "Y" {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
err := p.Delete(context.Background(), options, c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
return cli.NewExitError(err.Error(), 1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProjectKill forces stop service containers.
|
||||
func ProjectKill(p *project.Project, c *cli.Context) {
|
||||
err := p.Kill(c.Args()...)
|
||||
func ProjectKill(p project.APIProject, c *cli.Context) error {
|
||||
err := p.Kill(context.Background(), c.String("signal"), c.Args()...)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
return cli.NewExitError(err.Error(), 1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProjectPause pauses service containers.
|
||||
func ProjectPause(p project.APIProject, c *cli.Context) error {
|
||||
err := p.Pause(context.Background(), c.Args()...)
|
||||
if err != nil {
|
||||
return cli.NewExitError(err.Error(), 1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProjectUnpause unpauses service containers.
|
||||
func ProjectUnpause(p project.APIProject, c *cli.Context) error {
|
||||
err := p.Unpause(context.Background(), c.Args()...)
|
||||
if err != nil {
|
||||
return cli.NewExitError(err.Error(), 1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProjectScale scales services.
|
||||
func ProjectScale(p *project.Project, c *cli.Context) {
|
||||
// This code is a bit verbose but I wanted to parse everything up front
|
||||
order := make([]string, 0, 0)
|
||||
serviceScale := make(map[string]int)
|
||||
services := make(map[string]project.Service)
|
||||
|
||||
func ProjectScale(p project.APIProject, c *cli.Context) error {
|
||||
servicesScale := map[string]int{}
|
||||
for _, arg := range c.Args() {
|
||||
kv := strings.SplitN(arg, "=", 2)
|
||||
if len(kv) != 2 {
|
||||
logrus.Fatalf("Invalid scale parameter: %s", arg)
|
||||
return cli.NewExitError(fmt.Sprintf("Invalid scale parameter: %s", arg), 2)
|
||||
}
|
||||
|
||||
name := kv[0]
|
||||
|
||||
count, err := strconv.Atoi(kv[1])
|
||||
if err != nil {
|
||||
logrus.Fatalf("Invalid scale parameter: %v", err)
|
||||
return cli.NewExitError(fmt.Sprintf("Invalid scale parameter: %v", err), 2)
|
||||
}
|
||||
|
||||
if _, ok := p.Configs[name]; !ok {
|
||||
logrus.Fatalf("%s is not defined in the template", name)
|
||||
}
|
||||
|
||||
service, err := p.CreateService(name)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Failed to lookup service: %s: %v", service, err)
|
||||
}
|
||||
|
||||
order = append(order, name)
|
||||
serviceScale[name] = count
|
||||
services[name] = service
|
||||
servicesScale[name] = count
|
||||
}
|
||||
|
||||
for _, name := range order {
|
||||
scale := serviceScale[name]
|
||||
logrus.Infof("Setting scale %s=%d...", name, scale)
|
||||
err := services[name].Scale(scale)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Failed to set the scale %s=%d: %v", name, scale, err)
|
||||
}
|
||||
err := p.Scale(context.Background(), c.Int("timeout"), servicesScale)
|
||||
if err != nil {
|
||||
return cli.NewExitError(err.Error(), 1)
|
||||
}
|
||||
}
|
||||
|
||||
func wait() {
|
||||
<-make(chan interface{})
|
||||
return nil
|
||||
}
|
||||
|
2
vendor/github.com/docker/libcompose/cli/app/types.go
generated
vendored
2
vendor/github.com/docker/libcompose/cli/app/types.go
generated
vendored
@@ -8,5 +8,5 @@ import (
|
||||
// ProjectFactory is an interface that helps creating libcompose project.
|
||||
type ProjectFactory interface {
|
||||
// Create creates a libcompose project from the command line options (codegangsta cli context).
|
||||
Create(c *cli.Context) (*project.Project, error)
|
||||
Create(c *cli.Context) (project.APIProject, error)
|
||||
}
|
||||
|
52
vendor/github.com/docker/libcompose/cli/app/version.go
generated
vendored
Normal file
52
vendor/github.com/docker/libcompose/cli/app/version.go
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"text/template"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/docker/libcompose/version"
|
||||
)
|
||||
|
||||
var versionTemplate = `Version: {{.Version}} ({{.GitCommit}})
|
||||
Go version: {{.GoVersion}}
|
||||
Built: {{.BuildTime}}
|
||||
OS/Arch: {{.Os}}/{{.Arch}}`
|
||||
|
||||
// Version prints the libcompose version number and additionnal informations.
|
||||
func Version(c *cli.Context) {
|
||||
if c.Bool("short") {
|
||||
fmt.Println(version.VERSION)
|
||||
return
|
||||
}
|
||||
|
||||
tmpl, err := template.New("").Parse(versionTemplate)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
v := struct {
|
||||
Version string
|
||||
GitCommit string
|
||||
GoVersion string
|
||||
BuildTime string
|
||||
Os string
|
||||
Arch string
|
||||
}{
|
||||
Version: version.VERSION,
|
||||
GitCommit: version.GITCOMMIT,
|
||||
GoVersion: runtime.Version(),
|
||||
BuildTime: version.BUILDTIME,
|
||||
Os: runtime.GOOS,
|
||||
Arch: runtime.GOARCH,
|
||||
}
|
||||
|
||||
if err := tmpl.Execute(os.Stdout, v); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user