mirror of
https://github.com/docker/compose.git
synced 2026-08-28 04:18:05 +00:00
Add compose up and down
Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
parent
f32235b8ba
commit
03e418cbbb
12 changed files with 135 additions and 21 deletions
58
cli/cmd/compose/compose.go
Normal file
58
cli/cmd/compose/compose.go
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
package compose
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/docker/api/client"
|
||||
"github.com/docker/api/compose"
|
||||
)
|
||||
|
||||
func Command() *cobra.Command {
|
||||
command := &cobra.Command{
|
||||
Short: "Docker Compose",
|
||||
Use: "compose",
|
||||
}
|
||||
command.AddCommand(
|
||||
upCommand(),
|
||||
downCommand(),
|
||||
)
|
||||
return command
|
||||
}
|
||||
|
||||
func upCommand() *cobra.Command {
|
||||
opts := &compose.ProjectOptions{}
|
||||
upCmd := &cobra.Command{
|
||||
Use: "up",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
c, err := client.New(cmd.Context())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.AciService().Up(cmd.Context(), *opts)
|
||||
},
|
||||
}
|
||||
upCmd.Flags().StringVar(&opts.Name, "name", "", "Project name")
|
||||
upCmd.Flags().StringVar(&opts.WorkDir, "workdir", ".", "Work dir")
|
||||
upCmd.Flags().StringArrayVarP(&opts.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
|
||||
upCmd.Flags().StringArrayVarP(&opts.Environment, "environment", "e", []string{}, "Environment variables")
|
||||
|
||||
return upCmd
|
||||
}
|
||||
|
||||
func downCommand() *cobra.Command {
|
||||
opts := &compose.ProjectOptions{}
|
||||
downCmd := &cobra.Command{
|
||||
Use: "down",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
c, err := client.New(cmd.Context())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.AciService().Down(cmd.Context(), *opts)
|
||||
},
|
||||
}
|
||||
downCmd.Flags().StringVar(&opts.Name, "name", "", "Project name")
|
||||
downCmd.Flags().StringVar(&opts.WorkDir, "workdir", ".", "Work dir")
|
||||
|
||||
return downCmd
|
||||
}
|
||||
|
|
@ -62,5 +62,5 @@ func runExec(ctx context.Context, opts execOpts, name string, command string) er
|
|||
stdout = con
|
||||
}
|
||||
|
||||
return c.ContainerService().Exec(ctx, name, command, os.Stdin, stdout)
|
||||
return c.AciService().Exec(ctx, name, command, os.Stdin, stdout)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,5 +46,5 @@ func runLogs(ctx context.Context, containerName string, opts logsOpts) error {
|
|||
Writer: os.Stdout,
|
||||
}
|
||||
|
||||
return c.ContainerService().Logs(ctx, containerName, req)
|
||||
return c.AciService().Logs(ctx, containerName, req)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ var PsCommand = cobra.Command{
|
|||
return errors.Wrap(err, "cannot connect to backend")
|
||||
}
|
||||
|
||||
containers, err := c.ContainerService().List(ctx)
|
||||
containers, err := c.AciService().List(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "fetch containers")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,5 +65,5 @@ func runRun(ctx context.Context, image string, opts runOpts) error {
|
|||
return err
|
||||
}
|
||||
|
||||
return c.ContainerService().Run(ctx, project)
|
||||
return c.AciService().Run(ctx, project)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import (
|
|||
|
||||
// Backend registrations
|
||||
_ "github.com/docker/api/azure"
|
||||
"github.com/docker/api/cli/cmd/compose"
|
||||
_ "github.com/docker/api/example"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
|
@ -102,6 +103,7 @@ func main() {
|
|||
run.Command(),
|
||||
cmd.ExecCommand(),
|
||||
cmd.LogsCommand(),
|
||||
compose.Command(),
|
||||
)
|
||||
|
||||
helpFunc := root.HelpFunc()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue