mirror of
https://github.com/rancher/os.git
synced 2025-08-01 06:59:05 +00:00
Merge pull request #592 from ibuildthecloud/really-move-compose
Move ros compose to ros service sub commands
This commit is contained in:
commit
13d0241b7e
@ -40,13 +40,7 @@ func Main() {
|
|||||||
SkipFlagParsing: true,
|
SkipFlagParsing: true,
|
||||||
Action: envAction,
|
Action: envAction,
|
||||||
},
|
},
|
||||||
{
|
serviceCommand(),
|
||||||
Name: "service",
|
|
||||||
ShortName: "s",
|
|
||||||
Usage: "service settings",
|
|
||||||
HideHelp: true,
|
|
||||||
Subcommands: serviceSubCommands(),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Name: "os",
|
Name: "os",
|
||||||
Usage: "operating system upgrade/downgrade",
|
Usage: "operating system upgrade/downgrade",
|
||||||
@ -60,7 +54,6 @@ func Main() {
|
|||||||
Subcommands: tlsConfCommands(),
|
Subcommands: tlsConfCommands(),
|
||||||
},
|
},
|
||||||
installCommand,
|
installCommand,
|
||||||
composeCommand(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Run(os.Args)
|
app.Run(os.Args)
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
package control
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/Sirupsen/logrus"
|
|
||||||
"github.com/codegangsta/cli"
|
|
||||||
"github.com/docker/libcompose/cli/command"
|
|
||||||
dockerApp "github.com/docker/libcompose/cli/docker/app"
|
|
||||||
"github.com/docker/libcompose/project"
|
|
||||||
"github.com/rancherio/os/compose"
|
|
||||||
"github.com/rancherio/os/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
type projectFactory struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *projectFactory) Create(c *cli.Context) (*project.Project, error) {
|
|
||||||
cfg, err := config.LoadConfig()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return compose.GetProject(cfg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func beforeApp(c *cli.Context) error {
|
|
||||||
if c.GlobalBool("verbose") {
|
|
||||||
logrus.SetLevel(logrus.DebugLevel)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func composeCommand() cli.Command {
|
|
||||||
factory := &projectFactory{}
|
|
||||||
|
|
||||||
app := cli.Command{}
|
|
||||||
app.Name = "compose"
|
|
||||||
app.Usage = "Command line interface for libcompose."
|
|
||||||
app.Before = beforeApp
|
|
||||||
app.Flags = append(command.CommonFlags(), dockerApp.DockerClientFlags()...)
|
|
||||||
app.Subcommands = []cli.Command{
|
|
||||||
command.BuildCommand(factory),
|
|
||||||
command.CreateCommand(factory),
|
|
||||||
command.UpCommand(factory),
|
|
||||||
command.StartCommand(factory),
|
|
||||||
command.LogsCommand(factory),
|
|
||||||
command.RestartCommand(factory),
|
|
||||||
command.StopCommand(factory),
|
|
||||||
command.ScaleCommand(factory),
|
|
||||||
command.RmCommand(factory),
|
|
||||||
command.PullCommand(factory),
|
|
||||||
command.KillCommand(factory),
|
|
||||||
command.PortCommand(factory),
|
|
||||||
command.PsCommand(factory),
|
|
||||||
}
|
|
||||||
|
|
||||||
return app
|
|
||||||
}
|
|
@ -2,15 +2,65 @@ package control
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
log "github.com/Sirupsen/logrus"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
|
"github.com/docker/libcompose/cli/command"
|
||||||
|
dockerApp "github.com/docker/libcompose/cli/docker/app"
|
||||||
|
"github.com/docker/libcompose/project"
|
||||||
"github.com/rancherio/os/compose"
|
"github.com/rancherio/os/compose"
|
||||||
"github.com/rancherio/os/config"
|
"github.com/rancherio/os/config"
|
||||||
"github.com/rancherio/os/util"
|
"github.com/rancherio/os/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type projectFactory struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *projectFactory) Create(c *cli.Context) (*project.Project, error) {
|
||||||
|
cfg, err := config.LoadConfig()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return compose.GetProject(cfg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func beforeApp(c *cli.Context) error {
|
||||||
|
if c.GlobalBool("verbose") {
|
||||||
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func serviceCommand() cli.Command {
|
||||||
|
factory := &projectFactory{}
|
||||||
|
|
||||||
|
app := cli.Command{}
|
||||||
|
app.Name = "service"
|
||||||
|
app.ShortName = "s"
|
||||||
|
app.Usage = "Command line interface for services and compose."
|
||||||
|
app.Before = beforeApp
|
||||||
|
app.Flags = append(command.CommonFlags(), dockerApp.DockerClientFlags()...)
|
||||||
|
app.Subcommands = append(serviceSubCommands(),
|
||||||
|
command.BuildCommand(factory),
|
||||||
|
command.CreateCommand(factory),
|
||||||
|
command.UpCommand(factory),
|
||||||
|
command.StartCommand(factory),
|
||||||
|
command.LogsCommand(factory),
|
||||||
|
command.RestartCommand(factory),
|
||||||
|
command.StopCommand(factory),
|
||||||
|
command.ScaleCommand(factory),
|
||||||
|
command.RmCommand(factory),
|
||||||
|
command.PullCommand(factory),
|
||||||
|
command.KillCommand(factory),
|
||||||
|
command.PortCommand(factory),
|
||||||
|
command.PsCommand(factory),
|
||||||
|
)
|
||||||
|
|
||||||
|
return app
|
||||||
|
}
|
||||||
|
|
||||||
func serviceSubCommands() []cli.Command {
|
func serviceSubCommands() []cli.Command {
|
||||||
return []cli.Command{
|
return []cli.Command{
|
||||||
{
|
{
|
||||||
@ -40,7 +90,7 @@ func disable(c *cli.Context) {
|
|||||||
changed := false
|
changed := false
|
||||||
cfg, err := config.LoadConfig()
|
cfg, err := config.LoadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, service := range c.Args() {
|
for _, service := range c.Args() {
|
||||||
@ -54,7 +104,7 @@ func disable(c *cli.Context) {
|
|||||||
|
|
||||||
if changed {
|
if changed {
|
||||||
if err = cfg.Save(); err != nil {
|
if err = cfg.Save(); err != nil {
|
||||||
log.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,7 +113,7 @@ func del(c *cli.Context) {
|
|||||||
changed := false
|
changed := false
|
||||||
cfg, err := config.LoadConfig()
|
cfg, err := config.LoadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, service := range c.Args() {
|
for _, service := range c.Args() {
|
||||||
@ -76,7 +126,7 @@ func del(c *cli.Context) {
|
|||||||
|
|
||||||
if changed {
|
if changed {
|
||||||
if err = cfg.Save(); err != nil {
|
if err = cfg.Save(); err != nil {
|
||||||
log.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,16 +135,16 @@ func enable(c *cli.Context) {
|
|||||||
changed := false
|
changed := false
|
||||||
cfg, err := config.LoadConfig()
|
cfg, err := config.LoadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, service := range c.Args() {
|
for _, service := range c.Args() {
|
||||||
if val, ok := cfg.Rancher.ServicesInclude[service]; !ok || !val {
|
if val, ok := cfg.Rancher.ServicesInclude[service]; !ok || !val {
|
||||||
if strings.HasPrefix(service, "/") && !strings.HasPrefix(service, "/var/lib/rancher/conf") {
|
if strings.HasPrefix(service, "/") && !strings.HasPrefix(service, "/var/lib/rancher/conf") {
|
||||||
log.Fatalf("ERROR: Service should be in path /var/lib/rancher/conf")
|
logrus.Fatalf("ERROR: Service should be in path /var/lib/rancher/conf")
|
||||||
}
|
}
|
||||||
if _, err := compose.LoadServiceResource(service, true, cfg); err != nil {
|
if _, err := compose.LoadServiceResource(service, true, cfg); err != nil {
|
||||||
log.Fatalf("could not load service %s", service)
|
logrus.Fatalf("could not load service %s", service)
|
||||||
}
|
}
|
||||||
cfg.Rancher.ServicesInclude[service] = true
|
cfg.Rancher.ServicesInclude[service] = true
|
||||||
changed = true
|
changed = true
|
||||||
@ -103,7 +153,7 @@ func enable(c *cli.Context) {
|
|||||||
|
|
||||||
if changed {
|
if changed {
|
||||||
if err := cfg.Save(); err != nil {
|
if err := cfg.Save(); err != nil {
|
||||||
log.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,7 +161,7 @@ func enable(c *cli.Context) {
|
|||||||
func list(c *cli.Context) {
|
func list(c *cli.Context) {
|
||||||
cfg, err := config.LoadConfig()
|
cfg, err := config.LoadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
clone := make(map[string]bool)
|
clone := make(map[string]bool)
|
||||||
@ -121,7 +171,7 @@ func list(c *cli.Context) {
|
|||||||
|
|
||||||
services, err := util.GetServices(cfg.Rancher.Repositories.ToArray())
|
services, err := util.GetServices(cfg.Rancher.Repositories.ToArray())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to get services: %v", err)
|
logrus.Fatalf("Failed to get services: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, service := range services {
|
for _, service := range services {
|
||||||
|
Loading…
Reference in New Issue
Block a user