mirror of
https://github.com/rancher/os.git
synced 2025-09-01 06:40:31 +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
|
||||
}
|
149
vendor/github.com/docker/libcompose/cli/command/command.go
generated
vendored
149
vendor/github.com/docker/libcompose/cli/command/command.go
generated
vendored
@@ -3,7 +3,6 @@ package command
|
||||
import (
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/docker/libcompose/cli/app"
|
||||
"github.com/docker/libcompose/project"
|
||||
)
|
||||
|
||||
// CreateCommand defines the libcompose create subcommand.
|
||||
@@ -12,6 +11,20 @@ func CreateCommand(factory app.ProjectFactory) cli.Command {
|
||||
Name: "create",
|
||||
Usage: "Create all services but do not start",
|
||||
Action: app.WithProject(factory, app.ProjectCreate),
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "no-recreate",
|
||||
Usage: "If containers already exist, don't recreate them. Incompatible with --force-recreate.",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "force-recreate",
|
||||
Usage: "Recreate containers even if their configuration and image haven't changed. Incompatible with --no-recreate.",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "no-build",
|
||||
Usage: "Don't build an image, even if it's missing.",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +34,20 @@ func BuildCommand(factory app.ProjectFactory) cli.Command {
|
||||
Name: "build",
|
||||
Usage: "Build or rebuild services.",
|
||||
Action: app.WithProject(factory, app.ProjectBuild),
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "no-cache",
|
||||
Usage: "Do not use cache when building the image",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "force-rm",
|
||||
Usage: "Always remove intermediate containers",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "pull",
|
||||
Usage: "Always attempt to pull a newer version of the image",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +98,10 @@ func UpCommand(factory app.ProjectFactory) cli.Command {
|
||||
Name: "d",
|
||||
Usage: "Do not block and log",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "no-build",
|
||||
Usage: "Don't build an image, even if it's missing.",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "no-recreate",
|
||||
Usage: "If containers already exist, don't recreate them. Incompatible with --force-recreate.",
|
||||
@@ -98,12 +129,28 @@ func StartCommand(factory app.ProjectFactory) cli.Command {
|
||||
}
|
||||
}
|
||||
|
||||
// RunCommand defines the libcompose run subcommand.
|
||||
func RunCommand(factory app.ProjectFactory) cli.Command {
|
||||
return cli.Command{
|
||||
Name: "run",
|
||||
Usage: "Run a one-off command",
|
||||
Action: app.WithProject(factory, app.ProjectRun),
|
||||
Flags: []cli.Flag{},
|
||||
}
|
||||
}
|
||||
|
||||
// PullCommand defines the libcompose pull subcommand.
|
||||
func PullCommand(factory app.ProjectFactory) cli.Command {
|
||||
return cli.Command{
|
||||
Name: "pull",
|
||||
Usage: "Pulls images for services",
|
||||
Action: app.WithProject(factory, app.ProjectPull),
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "ignore-pull-failures",
|
||||
Usage: "Pull what it can and ignores images with pull failures.",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,6 +166,10 @@ func LogsCommand(factory app.ProjectFactory) cli.Command {
|
||||
Usage: "number of lines to tail",
|
||||
Value: 100,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "follow",
|
||||
Usage: "Follow log output.",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -142,10 +193,9 @@ func RestartCommand(factory app.ProjectFactory) cli.Command {
|
||||
// StopCommand defines the libcompose stop subcommand.
|
||||
func StopCommand(factory app.ProjectFactory) cli.Command {
|
||||
return cli.Command{
|
||||
Name: "stop",
|
||||
ShortName: "down",
|
||||
Usage: "Stop services",
|
||||
Action: app.WithProject(factory, app.ProjectDown),
|
||||
Name: "stop",
|
||||
Usage: "Stop services",
|
||||
Action: app.WithProject(factory, app.ProjectStop),
|
||||
Flags: []cli.Flag{
|
||||
cli.IntFlag{
|
||||
Name: "timeout,t",
|
||||
@@ -156,6 +206,29 @@ func StopCommand(factory app.ProjectFactory) cli.Command {
|
||||
}
|
||||
}
|
||||
|
||||
// DownCommand defines the libcompose stop subcommand.
|
||||
func DownCommand(factory app.ProjectFactory) cli.Command {
|
||||
return cli.Command{
|
||||
Name: "down",
|
||||
Usage: "Stop and remove containers, networks, images, and volumes",
|
||||
Action: app.WithProject(factory, app.ProjectDown),
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "volumes,v",
|
||||
Usage: "Remove data volumes",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "rmi",
|
||||
Usage: "Remove images, type may be one of: 'all' to remove all images, or 'local' to remove only images that don't have an custom name set by the `image` field",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "remove-orphans",
|
||||
Usage: "Remove containers for services not defined in the Compose file",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// ScaleCommand defines the libcompose scale subcommand.
|
||||
func ScaleCommand(factory app.ProjectFactory) cli.Command {
|
||||
return cli.Command{
|
||||
@@ -207,41 +280,57 @@ func KillCommand(factory app.ProjectFactory) cli.Command {
|
||||
}
|
||||
}
|
||||
|
||||
// PauseCommand defines the libcompose pause subcommand.
|
||||
func PauseCommand(factory app.ProjectFactory) cli.Command {
|
||||
return cli.Command{
|
||||
Name: "pause",
|
||||
Usage: "Pause services.",
|
||||
// ArgsUsage: "[SERVICE...]",
|
||||
Action: app.WithProject(factory, app.ProjectPause),
|
||||
}
|
||||
}
|
||||
|
||||
// UnpauseCommand defines the libcompose unpause subcommand.
|
||||
func UnpauseCommand(factory app.ProjectFactory) cli.Command {
|
||||
return cli.Command{
|
||||
Name: "unpause",
|
||||
Usage: "Unpause services.",
|
||||
// ArgsUsage: "[SERVICE...]",
|
||||
Action: app.WithProject(factory, app.ProjectUnpause),
|
||||
}
|
||||
}
|
||||
|
||||
// VersionCommand defines the libcompose version subcommand.
|
||||
func VersionCommand(factory app.ProjectFactory) cli.Command {
|
||||
return cli.Command{
|
||||
Name: "version",
|
||||
Usage: "Show version informations",
|
||||
Action: app.Version,
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "short",
|
||||
Usage: "Shows only Compose's version number.",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// CommonFlags defines the flags that are in common for all subcommands.
|
||||
func CommonFlags() []cli.Flag {
|
||||
return []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "verbose,debug",
|
||||
},
|
||||
cli.StringFlag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "file,f",
|
||||
Usage: "Specify an alternate compose file (default: docker-compose.yml)",
|
||||
Value: "docker-compose.yml",
|
||||
Usage: "Specify one or more alternate compose files (default: docker-compose.yml)",
|
||||
Value: &cli.StringSlice{},
|
||||
EnvVar: "COMPOSE_FILE",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "project-name,p",
|
||||
Usage: "Specify an alternate project name (default: directory name)",
|
||||
Name: "project-name,p",
|
||||
Usage: "Specify an alternate project name (default: directory name)",
|
||||
EnvVar: "COMPOSE_PROJECT_NAME",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Populate updates the specified project context based on command line arguments and subcommands.
|
||||
func Populate(context *project.Context, c *cli.Context) {
|
||||
context.ComposeFile = c.GlobalString("file")
|
||||
context.ProjectName = c.GlobalString("project-name")
|
||||
|
||||
if c.Command.Name == "logs" {
|
||||
context.Log = true
|
||||
} else if c.Command.Name == "up" {
|
||||
context.Log = !c.Bool("d")
|
||||
context.NoRecreate = c.Bool("no-recreate")
|
||||
context.ForceRecreate = c.Bool("force-recreate")
|
||||
} else if c.Command.Name == "stop" || c.Command.Name == "restart" || c.Command.Name == "scale" {
|
||||
context.Timeout = uint(c.Int("timeout"))
|
||||
} else if c.Command.Name == "kill" {
|
||||
context.Signal = c.Int("signal")
|
||||
} else if c.Command.Name == "rm" {
|
||||
context.Volume = c.Bool("v")
|
||||
}
|
||||
}
|
||||
|
6
vendor/github.com/docker/libcompose/cli/docker/app/commands.go
generated
vendored
6
vendor/github.com/docker/libcompose/cli/docker/app/commands.go
generated
vendored
@@ -4,6 +4,8 @@ import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/docker/libcompose/docker"
|
||||
"github.com/docker/libcompose/docker/client"
|
||||
"github.com/docker/libcompose/project"
|
||||
)
|
||||
|
||||
// DockerClientFlags defines the flags that are specific to the docker client,
|
||||
@@ -42,14 +44,14 @@ func DockerClientFlags() []cli.Flag {
|
||||
func Populate(context *docker.Context, c *cli.Context) {
|
||||
context.ConfigDir = c.String("configdir")
|
||||
|
||||
opts := docker.ClientOpts{}
|
||||
opts := client.Options{}
|
||||
opts.TLS = c.GlobalBool("tls")
|
||||
opts.TLSVerify = c.GlobalBool("tlsverify")
|
||||
opts.TLSOptions.CAFile = c.GlobalString("tlscacert")
|
||||
opts.TLSOptions.CertFile = c.GlobalString("tlscert")
|
||||
opts.TLSOptions.KeyFile = c.GlobalString("tlskey")
|
||||
|
||||
clientFactory, err := docker.NewDefaultClientFactory(opts)
|
||||
clientFactory, err := project.NewDefaultClientFactory(opts)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Failed to construct Docker client: %v", err)
|
||||
}
|
||||
|
21
vendor/github.com/docker/libcompose/cli/docker/app/factory.go
generated
vendored
21
vendor/github.com/docker/libcompose/cli/docker/app/factory.go
generated
vendored
@@ -1,23 +1,34 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/docker/libcompose/cli/command"
|
||||
"github.com/docker/libcompose/cli/logger"
|
||||
"github.com/docker/libcompose/docker"
|
||||
"github.com/docker/libcompose/project"
|
||||
)
|
||||
|
||||
// ProjectFactory is a struct that hold the app.ProjectFactory implementation.
|
||||
// ProjectFactory is a struct that holds the app.ProjectFactory implementation.
|
||||
type ProjectFactory struct {
|
||||
}
|
||||
|
||||
// Create implements ProjectFactory.Create using docker client.
|
||||
func (p *ProjectFactory) Create(c *cli.Context) (*project.Project, error) {
|
||||
func (p *ProjectFactory) Create(c *cli.Context) (project.APIProject, error) {
|
||||
context := &docker.Context{}
|
||||
context.LoggerFactory = logger.NewColorLoggerFactory()
|
||||
Populate(context, c)
|
||||
command.Populate(&context.Context, c)
|
||||
|
||||
return docker.NewProject(context)
|
||||
context.ComposeFiles = c.GlobalStringSlice("file")
|
||||
|
||||
if len(context.ComposeFiles) == 0 {
|
||||
context.ComposeFiles = []string{"docker-compose.yml"}
|
||||
if _, err := os.Stat("docker-compose.override.yml"); err == nil {
|
||||
context.ComposeFiles = append(context.ComposeFiles, "docker-compose.override.yml")
|
||||
}
|
||||
}
|
||||
|
||||
context.ProjectName = c.GlobalString("project-name")
|
||||
|
||||
return docker.NewProject(context, nil)
|
||||
}
|
||||
|
Reference in New Issue
Block a user