1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Move pkg to cli/compose/convert

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2016-12-05 16:14:08 -05:00
parent 4664dd06f1
commit 643fd775ed
10 changed files with 33 additions and 33 deletions

View file

@ -6,26 +6,26 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/cli/compose/convert"
"github.com/docker/docker/client"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/composetransform"
)
func getStackFilter(namespace string) filters.Args {
filter := filters.NewArgs()
filter.Add("label", composetransform.LabelNamespace+"="+namespace)
filter.Add("label", convert.LabelNamespace+"="+namespace)
return filter
}
func getStackFilterFromOpt(namespace string, opt opts.FilterOpt) filters.Args {
filter := opt.Value()
filter.Add("label", composetransform.LabelNamespace+"="+namespace)
filter.Add("label", convert.LabelNamespace+"="+namespace)
return filter
}
func getAllStacksFilter() filters.Args {
filter := filters.NewArgs()
filter.Add("label", composetransform.LabelNamespace)
filter.Add("label", convert.LabelNamespace)
return filter
}

View file

@ -17,8 +17,8 @@ import (
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/cli"
"github.com/docker/docker/cli/command"
"github.com/docker/docker/cli/compose/convert"
dockerclient "github.com/docker/docker/client"
"github.com/docker/docker/pkg/composetransform"
)
const (
@ -115,16 +115,16 @@ func deployCompose(ctx context.Context, dockerCli *command.DockerCli, opts deplo
return err
}
namespace := composetransform.NewNamespace(opts.namespace)
namespace := convert.NewNamespace(opts.namespace)
networks, externalNetworks := composetransform.ConvertNetworks(namespace, config.Networks)
networks, externalNetworks := convert.Networks(namespace, config.Networks)
if err := validateExternalNetworks(ctx, dockerCli, externalNetworks); err != nil {
return err
}
if err := createNetworks(ctx, dockerCli, namespace, networks); err != nil {
return err
}
services, err := composetransform.ConvertServices(namespace, config)
services, err := convert.Services(namespace, config)
if err != nil {
return err
}
@ -198,7 +198,7 @@ func validateExternalNetworks(
func createNetworks(
ctx context.Context,
dockerCli *command.DockerCli,
namespace composetransform.Namespace,
namespace convert.Namespace,
networks map[string]types.NetworkCreate,
) error {
client := dockerCli.Client()
@ -236,7 +236,7 @@ func deployServices(
ctx context.Context,
dockerCli *command.DockerCli,
services map[string]swarm.ServiceSpec,
namespace composetransform.Namespace,
namespace convert.Namespace,
sendAuth bool,
) error {
apiClient := dockerCli.Client()

View file

@ -6,7 +6,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/cli/command"
"github.com/docker/docker/pkg/composetransform"
"github.com/docker/docker/cli/compose/convert"
)
func deployBundle(ctx context.Context, dockerCli *command.DockerCli, opts deployOptions) error {
@ -19,13 +19,13 @@ func deployBundle(ctx context.Context, dockerCli *command.DockerCli, opts deploy
return err
}
namespace := composetransform.NewNamespace(opts.namespace)
namespace := convert.NewNamespace(opts.namespace)
networks := make(map[string]types.NetworkCreate)
for _, service := range bundle.Services {
for _, networkName := range service.Networks {
networks[networkName] = types.NetworkCreate{
Labels: composetransform.AddStackLabel(namespace, nil),
Labels: convert.AddStackLabel(namespace, nil),
}
}
}
@ -53,7 +53,7 @@ func deployBundle(ctx context.Context, dockerCli *command.DockerCli, opts deploy
serviceSpec := swarm.ServiceSpec{
Annotations: swarm.Annotations{
Name: name,
Labels: composetransform.AddStackLabel(namespace, service.Labels),
Labels: convert.AddStackLabel(namespace, service.Labels),
},
TaskTemplate: swarm.TaskSpec{
ContainerSpec: swarm.ContainerSpec{
@ -64,7 +64,7 @@ func deployBundle(ctx context.Context, dockerCli *command.DockerCli, opts deploy
// Service Labels will not be copied to Containers
// automatically during the deployment so we apply
// it here.
Labels: composetransform.AddStackLabel(namespace, nil),
Labels: convert.AddStackLabel(namespace, nil),
},
},
EndpointSpec: &swarm.EndpointSpec{

View file

@ -11,8 +11,8 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/cli"
"github.com/docker/docker/cli/command"
"github.com/docker/docker/cli/compose/convert"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/composetransform"
"github.com/spf13/cobra"
)
@ -90,10 +90,10 @@ func getStacks(
m := make(map[string]*stack, 0)
for _, service := range services {
labels := service.Spec.Labels
name, ok := labels[composetransform.LabelNamespace]
name, ok := labels[convert.LabelNamespace]
if !ok {
return nil, fmt.Errorf("cannot get label %s for service %s",
composetransform.LabelNamespace, service.ID)
convert.LabelNamespace, service.ID)
}
ztack, ok := m[name]
if !ok {

View file

@ -1,4 +1,4 @@
package composetransform
package convert
import (
composetypes "github.com/aanand/compose-file/types"
@ -42,8 +42,8 @@ func AddStackLabel(namespace Namespace, labels map[string]string) map[string]str
type networkMap map[string]composetypes.NetworkConfig
// ConvertNetworks from the compose-file type to the engine API type
func ConvertNetworks(namespace Namespace, networks networkMap) (map[string]types.NetworkCreate, []string) {
// Networks from the compose-file type to the engine API type
func Networks(namespace Namespace, networks networkMap) (map[string]types.NetworkCreate, []string) {
if networks == nil {
networks = make(map[string]composetypes.NetworkConfig)
}

View file

@ -1,4 +1,4 @@
package composetransform
package convert
import (
"testing"
@ -26,7 +26,7 @@ func TestAddStackLabel(t *testing.T) {
assert.DeepEqual(t, actual, expected)
}
func TestConvertNetworks(t *testing.T) {
func TestNetworks(t *testing.T) {
namespace := Namespace{name: "foo"}
source := networkMap{
"normal": composetypes.NetworkConfig{
@ -79,7 +79,7 @@ func TestConvertNetworks(t *testing.T) {
},
}
networks, externals := ConvertNetworks(namespace, source)
networks, externals := Networks(namespace, source)
assert.DeepEqual(t, networks, expected)
assert.DeepEqual(t, externals, []string{"special"})
}

View file

@ -1,4 +1,4 @@
package composetransform
package convert
import (
"fmt"
@ -12,8 +12,8 @@ import (
"github.com/docker/go-connections/nat"
)
// ConvertServices from compose-file types to engine API types
func ConvertServices(
// Services from compose-file types to engine API types
func Services(
namespace Namespace,
config *composetypes.Config,
) (map[string]swarm.ServiceSpec, error) {
@ -52,7 +52,7 @@ func convertService(
return swarm.ServiceSpec{}, err
}
mounts, err := ConvertVolumes(service.Volumes, volumes, namespace)
mounts, err := Volumes(service.Volumes, volumes, namespace)
if err != nil {
// TODO: better error message (include service name)
return swarm.ServiceSpec{}, err

View file

@ -1,4 +1,4 @@
package composetransform
package convert
import (
"sort"

View file

@ -1,4 +1,4 @@
package composetransform
package convert
import (
"fmt"
@ -10,8 +10,8 @@ import (
type volumes map[string]composetypes.VolumeConfig
// ConvertVolumes from compose-file types to engine api types
func ConvertVolumes(serviceVolumes []string, stackVolumes volumes, namespace Namespace) ([]mount.Mount, error) {
// Volumes from compose-file types to engine api types
func Volumes(serviceVolumes []string, stackVolumes volumes, namespace Namespace) ([]mount.Mount, error) {
var mounts []mount.Mount
for _, volumeSpec := range serviceVolumes {

View file

@ -1,4 +1,4 @@
package composetransform
package convert
import (
"testing"