forked from LaconicNetwork/kompose
add komposeObject struct, remove factory, refactor cli/app
This commit is contained in:
parent
3164cd8abb
commit
7a41edb65e
889
cli/app/app.go
889
cli/app/app.go
File diff suppressed because it is too large
Load Diff
@ -16,13 +16,57 @@ limitations under the License.
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli"
|
||||
"github.com/docker/libcompose/project"
|
||||
)
|
||||
//
|
||||
//// 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)
|
||||
//}
|
||||
|
||||
// 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)
|
||||
type KomposeObject struct {
|
||||
ServiceConfigs map[string]ServiceConfig
|
||||
}
|
||||
|
||||
type ServiceConfig struct {
|
||||
ContainerName string
|
||||
Image string
|
||||
Environment []EnvVar
|
||||
Port []Ports
|
||||
Command []string
|
||||
WorkingDir string
|
||||
Args []string
|
||||
//Volume []Volumes
|
||||
Network []string
|
||||
Labels map[string]string
|
||||
CPUSet string
|
||||
CPUShares int64
|
||||
CPUQuota int64
|
||||
CapAdd []string
|
||||
CapDrop []string
|
||||
Entrypoint []string
|
||||
Expose []string
|
||||
Privileged bool
|
||||
Restart string
|
||||
User string
|
||||
}
|
||||
|
||||
type EnvVar struct {
|
||||
Name string
|
||||
Value string
|
||||
}
|
||||
|
||||
type Ports struct {
|
||||
HostPort int32
|
||||
ContainerPort int32
|
||||
Protocol Protocol
|
||||
}
|
||||
|
||||
// Protocol defines network protocols supported for things like container ports.
|
||||
type Protocol string
|
||||
|
||||
const (
|
||||
// ProtocolTCP is the TCP protocol.
|
||||
ProtocolTCP Protocol = "TCP"
|
||||
// ProtocolUDP is the UDP protocol.
|
||||
ProtocolUDP Protocol = "UDP"
|
||||
)
|
||||
@ -17,17 +17,18 @@ limitations under the License.
|
||||
package command
|
||||
|
||||
import (
|
||||
"github.com/docker/libcompose/project"
|
||||
"github.com/skippbox/kompose/cli/app"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// ConvertCommand defines the kompose convert subcommand.
|
||||
func ConvertCommand(factory app.ProjectFactory) cli.Command {
|
||||
func ConvertCommand() cli.Command {
|
||||
return cli.Command{
|
||||
Name: "convert",
|
||||
Usage: "Convert docker-compose.yml to Kubernetes objects",
|
||||
Action: app.WithProject(factory, app.ProjectKuberConvert),
|
||||
Action: func (c *cli.Context) {
|
||||
app.Convert(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "file,f",
|
||||
@ -79,20 +80,24 @@ func ConvertCommand(factory app.ProjectFactory) cli.Command {
|
||||
}
|
||||
|
||||
// UpCommand defines the kompose up subcommand.
|
||||
func UpCommand(factory app.ProjectFactory) cli.Command {
|
||||
func UpCommand() cli.Command {
|
||||
return cli.Command{
|
||||
Name: "up",
|
||||
Usage: "Submit rc, svc objects to kubernetes API endpoint",
|
||||
Action: app.WithProject(factory, app.ProjectKuberUp),
|
||||
Action: func (c *cli.Context) {
|
||||
app.Up(c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// PsCommand defines the kompose ps subcommand.
|
||||
func PsCommand(factory app.ProjectFactory) cli.Command {
|
||||
func PsCommand() cli.Command {
|
||||
return cli.Command{
|
||||
Name: "ps",
|
||||
Usage: "Get active data in the kubernetes cluster",
|
||||
Action: app.WithProject(factory, app.ProjectKuberPS),
|
||||
Action: func (c *cli.Context) {
|
||||
app.Ps(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "service,svc",
|
||||
@ -107,11 +112,13 @@ func PsCommand(factory app.ProjectFactory) cli.Command {
|
||||
}
|
||||
|
||||
// DeleteCommand defines the kompose delete subcommand.
|
||||
func DeleteCommand(factory app.ProjectFactory) cli.Command {
|
||||
func DeleteCommand() cli.Command {
|
||||
return cli.Command{
|
||||
Name: "delete",
|
||||
Usage: "Remove instantiated services/rc from kubernetes",
|
||||
Action: app.WithProject(factory, app.ProjectKuberDelete),
|
||||
Action: func (c *cli.Context) {
|
||||
app.Delete(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "replicationcontroller,rc",
|
||||
@ -130,11 +137,13 @@ func DeleteCommand(factory app.ProjectFactory) cli.Command {
|
||||
}
|
||||
|
||||
// ScaleCommand defines the kompose up subcommand.
|
||||
func ScaleCommand(factory app.ProjectFactory) cli.Command {
|
||||
func ScaleCommand() cli.Command {
|
||||
return cli.Command{
|
||||
Name: "scale",
|
||||
Usage: "Globally scale instantiated replication controllers",
|
||||
Action: app.WithProject(factory, app.ProjectKuberScale),
|
||||
Action: func (c *cli.Context) {
|
||||
app.Scale(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
cli.IntFlag{
|
||||
Name: "scale",
|
||||
@ -162,19 +171,18 @@ func CommonFlags() []cli.Flag {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// 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 == "scale" {
|
||||
context.Timeout = uint(c.Int("timeout"))
|
||||
}
|
||||
}
|
||||
//
|
||||
//// Populate updates the specified project context based on command line arguments and subcommands.
|
||||
//func Populate(context *project.Context, c *cli.Context) {
|
||||
// context.ComposeFiles = append(context.ComposeFiles, c.GlobalString("file"))
|
||||
//
|
||||
// //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 == "scale" {
|
||||
// // context.Timeout = uint(c.Int("timeout"))
|
||||
// //}
|
||||
//}
|
||||
|
||||
@ -1,39 +0,0 @@
|
||||
/*
|
||||
Copyright 2016 Skippbox, Ltd All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli"
|
||||
"github.com/skippbox/kompose/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.
|
||||
type ProjectFactory struct {
|
||||
}
|
||||
|
||||
// Create implements ProjectFactory.Create using docker client.
|
||||
func (p *ProjectFactory) Create(c *cli.Context) (*project.Project, error) {
|
||||
context := &docker.Context{}
|
||||
context.LoggerFactory = logger.NewColorLoggerFactory()
|
||||
//Populate(context, c)
|
||||
command.Populate(&context.Context, c)
|
||||
|
||||
return docker.NewProject(context)
|
||||
}
|
||||
@ -20,15 +20,12 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
dockerApp "github.com/skippbox/kompose/cli/docker/app"
|
||||
"github.com/skippbox/kompose/version"
|
||||
"github.com/skippbox/kompose/cli/command"
|
||||
cliApp "github.com/skippbox/kompose/cli/app"
|
||||
)
|
||||
|
||||
func main() {
|
||||
factory := &dockerApp.ProjectFactory{}
|
||||
|
||||
app := cli.NewApp()
|
||||
app.Name = "kompose"
|
||||
app.Usage = "Command line interface for Skippbox."
|
||||
@ -39,11 +36,11 @@ func main() {
|
||||
app.Before = cliApp.BeforeApp
|
||||
app.Flags = append(command.CommonFlags())
|
||||
app.Commands = []cli.Command{
|
||||
command.ConvertCommand(factory),
|
||||
command.UpCommand(factory),
|
||||
command.PsCommand(factory),
|
||||
command.DeleteCommand(factory),
|
||||
command.ScaleCommand(factory),
|
||||
command.ConvertCommand(),
|
||||
command.UpCommand(),
|
||||
command.PsCommand(),
|
||||
command.DeleteCommand(),
|
||||
command.ScaleCommand(),
|
||||
}
|
||||
|
||||
app.Run(os.Args)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user