Merge branch 'main' of github.com:docker/compose-cli into docker_compose_logs_since_option

This commit is contained in:
Afshin Paydar 2021-06-16 08:57:02 +08:00
commit df6d709aa5
177 changed files with 1160 additions and 1256 deletions

View File

@ -39,8 +39,8 @@ import (
"github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/client"
"github.com/docker/compose-cli/api/containers" "github.com/docker/compose-cli/api/containers"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/api/errdefs" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/api/progress" "github.com/docker/compose-cli/pkg/progress"
) )
func createACIContainers(ctx context.Context, aciContext store.AciContext, groupDefinition containerinstance.ContainerGroup) error { func createACIContainers(ctx context.Context, aciContext store.AciContext, groupDefinition containerinstance.ContainerGroup) error {
@ -85,7 +85,7 @@ func autocreateFileshares(ctx context.Context, project *types.Project) error {
} }
_, err = clt.VolumeService().Inspect(ctx, fmt.Sprintf("%s/%s", accountName, shareName)) _, err = clt.VolumeService().Inspect(ctx, fmt.Sprintf("%s/%s", accountName, shareName))
if err != nil { // Not found, autocreate fileshare if err != nil { // Not found, autocreate fileshare
if !errdefs.IsNotFoundError(err) { if !api.IsNotFoundError(err) {
return err return err
} }
aciVolumeOpts := &VolumeCreateOptions{ aciVolumeOpts := &VolumeCreateOptions{
@ -198,7 +198,7 @@ func stopACIContainerGroup(ctx context.Context, aciContext store.AciContext, con
result, err := containerGroupsClient.Stop(ctx, aciContext.ResourceGroup, containerGroupName) result, err := containerGroupsClient.Stop(ctx, aciContext.ResourceGroup, containerGroupName)
if result.IsHTTPStatus(http.StatusNotFound) { if result.IsHTTPStatus(http.StatusNotFound) {
return errdefs.ErrNotFound return api.ErrNotFound
} }
return err return err
} }

View File

@ -26,11 +26,11 @@ import (
"github.com/docker/compose-cli/aci/convert" "github.com/docker/compose-cli/aci/convert"
"github.com/docker/compose-cli/aci/login" "github.com/docker/compose-cli/aci/login"
"github.com/docker/compose-cli/api/backend" "github.com/docker/compose-cli/api/backend"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/containers" "github.com/docker/compose-cli/api/containers"
"github.com/docker/compose-cli/api/resources" "github.com/docker/compose-cli/api/resources"
"github.com/docker/compose-cli/api/secrets" "github.com/docker/compose-cli/api/secrets"
"github.com/docker/compose-cli/api/volumes" "github.com/docker/compose-cli/api/volumes"
"github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/api/cloud" "github.com/docker/compose-cli/api/cloud"
apicontext "github.com/docker/compose-cli/api/context" apicontext "github.com/docker/compose-cli/api/context"
@ -115,7 +115,7 @@ func (a *aciAPIService) ContainerService() containers.Service {
return a.aciContainerService return a.aciContainerService
} }
func (a *aciAPIService) ComposeService() compose.Service { func (a *aciAPIService) ComposeService() api.Service {
return a.aciComposeService return a.aciComposeService
} }

View File

@ -27,10 +27,9 @@ import (
"github.com/docker/compose-cli/aci/convert" "github.com/docker/compose-cli/aci/convert"
"github.com/docker/compose-cli/aci/login" "github.com/docker/compose-cli/aci/login"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/api/errdefs" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/api/progress" "github.com/docker/compose-cli/pkg/progress"
"github.com/docker/compose-cli/utils/formatter" "github.com/docker/compose-cli/utils/formatter"
) )
@ -46,47 +45,47 @@ func newComposeService(ctx store.AciContext) aciComposeService {
} }
} }
func (cs *aciComposeService) Build(ctx context.Context, project *types.Project, options compose.BuildOptions) error { func (cs *aciComposeService) Build(ctx context.Context, project *types.Project, options api.BuildOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (cs *aciComposeService) Push(ctx context.Context, project *types.Project, options compose.PushOptions) error { func (cs *aciComposeService) Push(ctx context.Context, project *types.Project, options api.PushOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (cs *aciComposeService) Pull(ctx context.Context, project *types.Project, options compose.PullOptions) error { func (cs *aciComposeService) Pull(ctx context.Context, project *types.Project, options api.PullOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (cs *aciComposeService) Create(ctx context.Context, project *types.Project, opts compose.CreateOptions) error { func (cs *aciComposeService) Create(ctx context.Context, project *types.Project, opts api.CreateOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (cs *aciComposeService) Start(ctx context.Context, project *types.Project, options compose.StartOptions) error { func (cs *aciComposeService) Start(ctx context.Context, project *types.Project, options api.StartOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (cs *aciComposeService) Restart(ctx context.Context, project *types.Project, options compose.RestartOptions) error { func (cs *aciComposeService) Restart(ctx context.Context, project *types.Project, options api.RestartOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (cs *aciComposeService) Stop(ctx context.Context, project *types.Project, options compose.StopOptions) error { func (cs *aciComposeService) Stop(ctx context.Context, project *types.Project, options api.StopOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (cs *aciComposeService) Pause(ctx context.Context, project string, options compose.PauseOptions) error { func (cs *aciComposeService) Pause(ctx context.Context, project string, options api.PauseOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (cs *aciComposeService) UnPause(ctx context.Context, project string, options compose.PauseOptions) error { func (cs *aciComposeService) UnPause(ctx context.Context, project string, options api.PauseOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (cs *aciComposeService) Copy(ctx context.Context, project *types.Project, options compose.CopyOptions) error { func (cs *aciComposeService) Copy(ctx context.Context, project *types.Project, options api.CopyOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (cs *aciComposeService) Up(ctx context.Context, project *types.Project, options compose.UpOptions) error { func (cs *aciComposeService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error {
return progress.Run(ctx, func(ctx context.Context) error { return progress.Run(ctx, func(ctx context.Context) error {
return cs.up(ctx, project) return cs.up(ctx, project)
}) })
@ -130,12 +129,12 @@ func (cs aciComposeService) warnKeepVolumeOnDown(ctx context.Context, projectNam
return nil return nil
} }
func (cs *aciComposeService) Down(ctx context.Context, projectName string, options compose.DownOptions) error { func (cs *aciComposeService) Down(ctx context.Context, projectName string, options api.DownOptions) error {
if options.Volumes { if options.Volumes {
return errors.Wrap(errdefs.ErrNotImplemented, "--volumes option is not supported on ACI") return errors.Wrap(api.ErrNotImplemented, "--volumes option is not supported on ACI")
} }
if options.Images != "" { if options.Images != "" {
return errors.Wrap(errdefs.ErrNotImplemented, "--rmi option is not supported on ACI") return errors.Wrap(api.ErrNotImplemented, "--rmi option is not supported on ACI")
} }
return progress.Run(ctx, func(ctx context.Context) error { return progress.Run(ctx, func(ctx context.Context) error {
logrus.Debugf("Down on project with name %q", projectName) logrus.Debugf("Down on project with name %q", projectName)
@ -149,14 +148,14 @@ func (cs *aciComposeService) Down(ctx context.Context, projectName string, optio
return err return err
} }
if cg.IsHTTPStatus(http.StatusNoContent) { if cg.IsHTTPStatus(http.StatusNoContent) {
return errdefs.ErrNotFound return api.ErrNotFound
} }
return err return err
}) })
} }
func (cs *aciComposeService) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) { func (cs *aciComposeService) Ps(ctx context.Context, projectName string, options api.PsOptions) ([]api.ContainerSummary, error) {
groupsClient, err := login.NewContainerGroupsClient(cs.ctx.SubscriptionID) groupsClient, err := login.NewContainerGroupsClient(cs.ctx.SubscriptionID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -171,15 +170,15 @@ func (cs *aciComposeService) Ps(ctx context.Context, projectName string, options
return nil, fmt.Errorf("no containers found in ACI container group %s", projectName) return nil, fmt.Errorf("no containers found in ACI container group %s", projectName)
} }
res := []compose.ContainerSummary{} res := []api.ContainerSummary{}
for _, container := range *group.Containers { for _, container := range *group.Containers {
if isContainerVisible(container, group, false) { if isContainerVisible(container, group, false) {
continue continue
} }
var publishers []compose.PortPublisher var publishers []api.PortPublisher
urls := formatter.PortsToStrings(convert.ToPorts(group.IPAddress, *container.Ports), convert.FQDN(group, cs.ctx.Location)) urls := formatter.PortsToStrings(convert.ToPorts(group.IPAddress, *container.Ports), convert.FQDN(group, cs.ctx.Location))
for i, p := range *container.Ports { for i, p := range *container.Ports {
publishers = append(publishers, compose.PortPublisher{ publishers = append(publishers, api.PortPublisher{
URL: urls[i], URL: urls[i],
TargetPort: int(*p.Port), TargetPort: int(*p.Port),
PublishedPort: int(*p.Port), PublishedPort: int(*p.Port),
@ -187,7 +186,7 @@ func (cs *aciComposeService) Ps(ctx context.Context, projectName string, options
}) })
} }
id := getContainerID(group, container) id := getContainerID(group, container)
res = append(res, compose.ContainerSummary{ res = append(res, api.ContainerSummary{
ID: id, ID: id,
Name: id, Name: id,
Project: projectName, Project: projectName,
@ -199,26 +198,26 @@ func (cs *aciComposeService) Ps(ctx context.Context, projectName string, options
return res, nil return res, nil
} }
func (cs *aciComposeService) List(ctx context.Context, opts compose.ListOptions) ([]compose.Stack, error) { func (cs *aciComposeService) List(ctx context.Context, opts api.ListOptions) ([]api.Stack, error) {
containerGroups, err := getACIContainerGroups(ctx, cs.ctx.SubscriptionID, cs.ctx.ResourceGroup) containerGroups, err := getACIContainerGroups(ctx, cs.ctx.SubscriptionID, cs.ctx.ResourceGroup)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var stacks []compose.Stack var stacks []api.Stack
for _, group := range containerGroups { for _, group := range containerGroups {
if _, found := group.Tags[composeContainerTag]; !found { if _, found := group.Tags[composeContainerTag]; !found {
continue continue
} }
state := compose.RUNNING state := api.RUNNING
for _, container := range *group.ContainerGroupProperties.Containers { for _, container := range *group.ContainerGroupProperties.Containers {
containerState := convert.GetStatus(container, group) containerState := convert.GetStatus(container, group)
if containerState != compose.RUNNING { if containerState != api.RUNNING {
state = containerState state = containerState
break break
} }
} }
stacks = append(stacks, compose.Stack{ stacks = append(stacks, api.Stack{
ID: *group.ID, ID: *group.ID,
Name: *group.Name, Name: *group.Name,
Status: state, Status: state,
@ -227,41 +226,41 @@ func (cs *aciComposeService) List(ctx context.Context, opts compose.ListOptions)
return stacks, nil return stacks, nil
} }
func (cs *aciComposeService) Logs(ctx context.Context, projectName string, consumer compose.LogConsumer, options compose.LogOptions) error { func (cs *aciComposeService) Logs(ctx context.Context, projectName string, consumer api.LogConsumer, options api.LogOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (cs *aciComposeService) Convert(ctx context.Context, project *types.Project, options compose.ConvertOptions) ([]byte, error) { func (cs *aciComposeService) Convert(ctx context.Context, project *types.Project, options api.ConvertOptions) ([]byte, error) {
return nil, errdefs.ErrNotImplemented return nil, api.ErrNotImplemented
} }
func (cs *aciComposeService) Kill(ctx context.Context, project *types.Project, options compose.KillOptions) error { func (cs *aciComposeService) Kill(ctx context.Context, project *types.Project, options api.KillOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (cs *aciComposeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { func (cs *aciComposeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) {
return 0, errdefs.ErrNotImplemented return 0, api.ErrNotImplemented
} }
func (cs *aciComposeService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) error { func (cs *aciComposeService) Remove(ctx context.Context, project *types.Project, options api.RemoveOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (cs *aciComposeService) Exec(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { func (cs *aciComposeService) Exec(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) {
return 0, errdefs.ErrNotImplemented return 0, api.ErrNotImplemented
} }
func (cs *aciComposeService) Top(ctx context.Context, projectName string, services []string) ([]compose.ContainerProcSummary, error) { func (cs *aciComposeService) Top(ctx context.Context, projectName string, services []string) ([]api.ContainerProcSummary, error) {
return nil, errdefs.ErrNotImplemented return nil, api.ErrNotImplemented
} }
func (cs *aciComposeService) Events(ctx context.Context, project string, options compose.EventsOptions) error { func (cs *aciComposeService) Events(ctx context.Context, project string, options api.EventsOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (cs *aciComposeService) Port(ctx context.Context, project string, service string, port int, options compose.PortOptions) (string, int, error) { func (cs *aciComposeService) Port(ctx context.Context, project string, service string, port int, options api.PortOptions) (string, int, error) {
return "", 0, errdefs.ErrNotImplemented return "", 0, api.ErrNotImplemented
} }
func (cs *aciComposeService) Images(ctx context.Context, projectName string, options compose.ImagesOptions) ([]compose.ImageSummary, error) { func (cs *aciComposeService) Images(ctx context.Context, projectName string, options api.ImagesOptions) ([]api.ImageSummary, error) {
return nil, errdefs.ErrNotImplemented return nil, api.ErrNotImplemented
} }

View File

@ -33,7 +33,7 @@ import (
"github.com/docker/compose-cli/aci/login" "github.com/docker/compose-cli/aci/login"
"github.com/docker/compose-cli/api/containers" "github.com/docker/compose-cli/api/containers"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/api/errdefs" "github.com/docker/compose-cli/pkg/api"
) )
type aciContainerService struct { type aciContainerService struct {
@ -107,7 +107,7 @@ func (cs *aciContainerService) Start(ctx context.Context, containerID string) er
var aerr autorest.DetailedError var aerr autorest.DetailedError
if ok := errors.As(err, &aerr); ok { if ok := errors.As(err, &aerr); ok {
if aerr.StatusCode == http.StatusNotFound { if aerr.StatusCode == http.StatusNotFound {
return errdefs.ErrNotFound return api.ErrNotFound
} }
} }
return err return err
@ -207,7 +207,7 @@ func (cs *aciContainerService) Delete(ctx context.Context, containerID string, r
cg, err := containerGroupsClient.Get(ctx, cs.ctx.ResourceGroup, groupName) cg, err := containerGroupsClient.Get(ctx, cs.ctx.ResourceGroup, groupName)
if err != nil { if err != nil {
if cg.StatusCode == http.StatusNotFound { if cg.StatusCode == http.StatusNotFound {
return errdefs.ErrNotFound return api.ErrNotFound
} }
return err return err
} }
@ -216,7 +216,7 @@ func (cs *aciContainerService) Delete(ctx context.Context, containerID string, r
status := convert.GetStatus(container, cg) status := convert.GetStatus(container, cg)
if status == convert.StatusRunning { if status == convert.StatusRunning {
return errdefs.ErrForbidden return api.ErrForbidden
} }
} }
} }
@ -224,7 +224,7 @@ func (cs *aciContainerService) Delete(ctx context.Context, containerID string, r
cg, err := deleteACIContainerGroup(ctx, cs.ctx, groupName) cg, err := deleteACIContainerGroup(ctx, cs.ctx, groupName)
// Delete returns `StatusNoContent` if the group is not found // Delete returns `StatusNoContent` if the group is not found
if cg.IsHTTPStatus(http.StatusNoContent) { if cg.IsHTTPStatus(http.StatusNoContent) {
return errdefs.ErrNotFound return api.ErrNotFound
} }
if err != nil { if err != nil {
return err return err
@ -244,7 +244,7 @@ func (cs *aciContainerService) Inspect(ctx context.Context, containerID string)
return containers.Container{}, err return containers.Container{}, err
} }
if cg.IsHTTPStatus(http.StatusNoContent) || cg.ContainerGroupProperties == nil || cg.ContainerGroupProperties.Containers == nil { if cg.IsHTTPStatus(http.StatusNoContent) || cg.ContainerGroupProperties == nil || cg.ContainerGroupProperties.Containers == nil {
return containers.Container{}, errdefs.ErrNotFound return containers.Container{}, api.ErrNotFound
} }
var cc containerinstance.Container var cc containerinstance.Container
@ -257,7 +257,7 @@ func (cs *aciContainerService) Inspect(ctx context.Context, containerID string)
} }
} }
if !found { if !found {
return containers.Container{}, errdefs.ErrNotFound return containers.Container{}, api.ErrNotFound
} }
return convert.ContainerGroupToContainer(containerID, cg, cc, cs.ctx.Location), nil return convert.ContainerGroupToContainer(containerID, cg, cc, cs.ctx.Location), nil

View File

@ -28,8 +28,8 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/api/errdefs" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/utils/prompt" "github.com/docker/compose-cli/pkg/prompt"
) )
// ContextParams options for creating ACI context // ContextParams options for creating ACI context
@ -41,7 +41,7 @@ type ContextParams struct {
} }
// ErrSubscriptionNotFound is returned when a required subscription is not found // ErrSubscriptionNotFound is returned when a required subscription is not found
var ErrSubscriptionNotFound = errors.Wrapf(errdefs.ErrNotFound, "subscription") var ErrSubscriptionNotFound = errors.Wrapf(api.ErrNotFound, "subscription")
// IsSubscriptionNotFoundError returns true if the unwrapped error is IsSubscriptionNotFoundError // IsSubscriptionNotFoundError returns true if the unwrapped error is IsSubscriptionNotFoundError
func IsSubscriptionNotFoundError(err error) bool { func IsSubscriptionNotFoundError(err error) bool {
@ -145,7 +145,7 @@ func (helper contextCreateACIHelper) chooseGroup(ctx context.Context, subscripti
group, err := helper.selector.Select("Select a resource group", groupNames) group, err := helper.selector.Select("Select a resource group", groupNames)
if err != nil { if err != nil {
if err == terminal.InterruptErr { if err == terminal.InterruptErr {
return resources.Group{}, errdefs.ErrCanceled return resources.Group{}, api.ErrCanceled
} }
return resources.Group{}, err return resources.Group{}, err

View File

@ -31,9 +31,9 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/docker/compose-cli/aci/login" "github.com/docker/compose-cli/aci/login"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/containers" "github.com/docker/compose-cli/api/containers"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/utils/formatter" "github.com/docker/compose-cli/utils/formatter"
) )
@ -314,12 +314,12 @@ func gbToBytes(memInBytes float64) uint64 {
} }
// ContainerGroupToServiceStatus convert from an ACI container definition to service status // ContainerGroupToServiceStatus convert from an ACI container definition to service status
func ContainerGroupToServiceStatus(containerID string, group containerinstance.ContainerGroup, container containerinstance.Container, region string) compose.ServiceStatus { func ContainerGroupToServiceStatus(containerID string, group containerinstance.ContainerGroup, container containerinstance.Container, region string) api.ServiceStatus {
var replicas = 1 var replicas = 1
if GetStatus(container, group) != StatusRunning { if GetStatus(container, group) != StatusRunning {
replicas = 0 replicas = 0
} }
return compose.ServiceStatus{ return api.ServiceStatus{
ID: containerID, ID: containerID,
Name: *container.Name, Name: *container.Name,
Ports: formatter.PortsToStrings(ToPorts(group.IPAddress, *container.Ports), FQDN(group, region)), Ports: formatter.PortsToStrings(ToPorts(group.IPAddress, *container.Ports), FQDN(group, region)),
@ -452,5 +452,5 @@ func GetGroupStatus(group containerinstance.ContainerGroup) string {
if group.InstanceView != nil && group.InstanceView.State != nil { if group.InstanceView != nil && group.InstanceView.State != nil {
return "Node " + *group.InstanceView.State return "Node " + *group.InstanceView.State
} }
return compose.UNKNOWN return api.UNKNOWN
} }

View File

@ -28,9 +28,9 @@ import (
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/containers" "github.com/docker/compose-cli/api/containers"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/pkg/api"
) )
var ( var (
@ -258,7 +258,7 @@ func TestContainerGroupToServiceStatus(t *testing.T) {
}, },
} }
var expectedService = compose.ServiceStatus{ var expectedService = api.ServiceStatus{
ID: "myContainerID", ID: "myContainerID",
Name: "myContainerID", Name: "myContainerID",
Ports: []string{"42.42.42.42:80->80/tcp"}, Ports: []string{"42.42.42.42:80->80/tcp"},

View File

@ -22,15 +22,13 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/pkg/errors" "github.com/docker/compose-cli/aci/login"
"github.com/docker/compose-cli/pkg/api"
"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2019-12-01/containerinstance" "github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2019-12-01/containerinstance"
"github.com/Azure/go-autorest/autorest/to" "github.com/Azure/go-autorest/autorest/to"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/types"
"github.com/pkg/errors"
"github.com/docker/compose-cli/aci/login"
"github.com/docker/compose-cli/api/errdefs"
) )
const ( const (
@ -151,10 +149,10 @@ func (v *volumeInput) parse(name string, candidate string) error {
sourceTokens := strings.Split(tokens[0], "/") sourceTokens := strings.Split(tokens[0], "/")
if len(sourceTokens) != 2 || sourceTokens[0] == "" { if len(sourceTokens) != 2 || sourceTokens[0] == "" {
return errors.Wrapf(errdefs.ErrParsingFailed, "volume specification %q does not include a storage account before '/'", candidate) return errors.Wrapf(api.ErrParsingFailed, "volume specification %q does not include a storage account before '/'", candidate)
} }
if sourceTokens[1] == "" { if sourceTokens[1] == "" {
return errors.Wrapf(errdefs.ErrParsingFailed, "volume specification %q does not include a storage file fileshare after '/'", candidate) return errors.Wrapf(api.ErrParsingFailed, "volume specification %q does not include a storage file fileshare after '/'", candidate)
} }
v.storageAccount = sourceTokens[0] v.storageAccount = sourceTokens[0]
v.fileshare = sourceTokens[1] v.fileshare = sourceTokens[1]
@ -168,11 +166,11 @@ func (v *volumeInput) parse(name string, candidate string) error {
v.target = tokens[1] v.target = tokens[1]
permissions := strings.ToLower(tokens[2]) permissions := strings.ToLower(tokens[2])
if permissions != "ro" && permissions != "rw" { if permissions != "ro" && permissions != "rw" {
return errors.Wrapf(errdefs.ErrParsingFailed, "volume specification %q has an invalid mode %q", candidate, permissions) return errors.Wrapf(api.ErrParsingFailed, "volume specification %q has an invalid mode %q", candidate, permissions)
} }
v.readonly = permissions == "ro" v.readonly = permissions == "ro"
default: default:
return errors.Wrapf(errdefs.ErrParsingFailed, "volume specification %q has invalid format", candidate) return errors.Wrapf(api.ErrParsingFailed, "volume specification %q has invalid format", candidate)
} }
return nil return nil

View File

@ -35,25 +35,23 @@ import (
"testing" "testing"
"time" "time"
"github.com/Azure/azure-sdk-for-go/profiles/2019-03-01/resources/mgmt/resources"
"github.com/Azure/azure-storage-file-go/azfile"
"github.com/Azure/go-autorest/autorest/to"
"github.com/docker/docker/pkg/fileutils" "github.com/docker/docker/pkg/fileutils"
"github.com/prometheus/tsdb/fileutil"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/icmd" "gotest.tools/v3/icmd"
"gotest.tools/v3/poll" "gotest.tools/v3/poll"
"github.com/Azure/azure-sdk-for-go/profiles/2019-03-01/resources/mgmt/resources"
"github.com/Azure/azure-storage-file-go/azfile"
"github.com/Azure/go-autorest/autorest/to"
"github.com/prometheus/tsdb/fileutil"
"github.com/docker/compose-cli/aci" "github.com/docker/compose-cli/aci"
"github.com/docker/compose-cli/aci/convert" "github.com/docker/compose-cli/aci/convert"
"github.com/docker/compose-cli/aci/login" "github.com/docker/compose-cli/aci/login"
"github.com/docker/compose-cli/api/containers" "github.com/docker/compose-cli/api/containers"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/cli/cmd" "github.com/docker/compose-cli/cli/cmd"
"github.com/docker/compose-cli/pkg/api"
. "github.com/docker/compose-cli/utils/e2e" . "github.com/docker/compose-cli/utils/e2e"
) )
@ -128,7 +126,7 @@ func TestLoginLogout(t *testing.T) {
t.Run("create context fail", func(t *testing.T) { t.Run("create context fail", func(t *testing.T) {
res := c.RunDockerOrExitError("context", "create", "aci", "fail-context") res := c.RunDockerOrExitError("context", "create", "aci", "fail-context")
res.Assert(t, icmd.Expected{ res.Assert(t, icmd.Expected{
ExitCode: errdefs.ExitCodeLoginRequired, ExitCode: api.ExitCodeLoginRequired,
Err: `not logged in to azure, you need to run "docker login azure" first`, Err: `not logged in to azure, you need to run "docker login azure" first`,
}) })
}) })

View File

@ -30,8 +30,8 @@ import (
"github.com/Azure/go-autorest/autorest/date" "github.com/Azure/go-autorest/autorest/date"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/internal" "github.com/docker/compose-cli/internal"
"github.com/docker/compose-cli/pkg/api"
) )
// NewContainerGroupsClient get client toi manipulate containerGrouos // NewContainerGroupsClient get client toi manipulate containerGrouos
@ -88,7 +88,7 @@ func NewFileShareClient(subscriptionID string) (storage.FileSharesClient, error)
func NewSubscriptionsClient() (subscription.SubscriptionsClient, error) { func NewSubscriptionsClient() (subscription.SubscriptionsClient, error) {
authorizer, mgmtURL, err := getClientSetupData() authorizer, mgmtURL, err := getClientSetupData()
if err != nil { if err != nil {
return subscription.SubscriptionsClient{}, errors.Wrap(errdefs.ErrLoginRequired, err.Error()) return subscription.SubscriptionsClient{}, errors.Wrap(api.ErrLoginRequired, err.Error())
} }
subc := subscription.NewSubscriptionsClientWithBaseURI(mgmtURL) subc := subscription.NewSubscriptionsClientWithBaseURI(mgmtURL)
setupClient(&subc.Client, authorizer) setupClient(&subc.Client, authorizer)

View File

@ -25,12 +25,12 @@ import (
"os" "os"
"time" "time"
"github.com/docker/compose-cli/pkg/api"
"github.com/Azure/go-autorest/autorest/adal" "github.com/Azure/go-autorest/autorest/adal"
"github.com/Azure/go-autorest/autorest/azure/auth" "github.com/Azure/go-autorest/autorest/azure/auth"
"github.com/pkg/errors" "github.com/pkg/errors"
"golang.org/x/oauth2" "golang.org/x/oauth2"
"github.com/docker/compose-cli/api/errdefs"
) )
//go login process, derived from code sample provided by MS at https://github.com/devigned/go-az-cli-stuff //go login process, derived from code sample provided by MS at https://github.com/devigned/go-az-cli-stuff
@ -98,20 +98,20 @@ func (login *azureLoginService) LoginServicePrincipal(clientID string, clientSec
spToken, err := creds.ServicePrincipalToken() spToken, err := creds.ServicePrincipalToken()
if err != nil { if err != nil {
return errors.Wrapf(errdefs.ErrLoginFailed, "could not login with service principal: %s", err) return errors.Wrapf(api.ErrLoginFailed, "could not login with service principal: %s", err)
} }
err = spToken.Refresh() err = spToken.Refresh()
if err != nil { if err != nil {
return errors.Wrapf(errdefs.ErrLoginFailed, "could not login with service principal: %s", err) return errors.Wrapf(api.ErrLoginFailed, "could not login with service principal: %s", err)
} }
token, err := spToOAuthToken(spToken.Token()) token, err := spToOAuthToken(spToken.Token())
if err != nil { if err != nil {
return errors.Wrapf(errdefs.ErrLoginFailed, "could not read service principal token expiry: %s", err) return errors.Wrapf(api.ErrLoginFailed, "could not read service principal token expiry: %s", err)
} }
loginInfo := TokenInfo{TenantID: tenantID, Token: token, CloudEnvironment: cloudEnvironment} loginInfo := TokenInfo{TenantID: tenantID, Token: token, CloudEnvironment: cloudEnvironment}
if err := login.tokenStore.writeLoginInfo(loginInfo); err != nil { if err := login.tokenStore.writeLoginInfo(loginInfo); err != nil {
return errors.Wrapf(errdefs.ErrLoginFailed, "could not store login info: %s", err) return errors.Wrapf(api.ErrLoginFailed, "could not store login info: %s", err)
} }
return nil return nil
} }
@ -134,28 +134,28 @@ func (login *azureLoginService) getTenantAndValidateLogin(
) error { ) error {
bits, statusCode, err := login.apiHelper.queryAPIWithHeader(ctx, ce.GetTenantQueryURL(), fmt.Sprintf("Bearer %s", accessToken)) bits, statusCode, err := login.apiHelper.queryAPIWithHeader(ctx, ce.GetTenantQueryURL(), fmt.Sprintf("Bearer %s", accessToken))
if err != nil { if err != nil {
return errors.Wrapf(errdefs.ErrLoginFailed, "check auth failed: %s", err) return errors.Wrapf(api.ErrLoginFailed, "check auth failed: %s", err)
} }
if statusCode != http.StatusOK { if statusCode != http.StatusOK {
return errors.Wrapf(errdefs.ErrLoginFailed, "unable to login status code %d: %s", statusCode, bits) return errors.Wrapf(api.ErrLoginFailed, "unable to login status code %d: %s", statusCode, bits)
} }
var t tenantResult var t tenantResult
if err := json.Unmarshal(bits, &t); err != nil { if err := json.Unmarshal(bits, &t); err != nil {
return errors.Wrapf(errdefs.ErrLoginFailed, "unable to unmarshal tenant: %s", err) return errors.Wrapf(api.ErrLoginFailed, "unable to unmarshal tenant: %s", err)
} }
tenantID, err := getTenantID(t.Value, requestedTenantID) tenantID, err := getTenantID(t.Value, requestedTenantID)
if err != nil { if err != nil {
return errors.Wrap(errdefs.ErrLoginFailed, err.Error()) return errors.Wrap(api.ErrLoginFailed, err.Error())
} }
tToken, err := login.refreshToken(refreshToken, tenantID, ce) tToken, err := login.refreshToken(refreshToken, tenantID, ce)
if err != nil { if err != nil {
return errors.Wrapf(errdefs.ErrLoginFailed, "unable to refresh token: %s", err) return errors.Wrapf(api.ErrLoginFailed, "unable to refresh token: %s", err)
} }
loginInfo := TokenInfo{TenantID: tenantID, Token: tToken, CloudEnvironment: ce.Name} loginInfo := TokenInfo{TenantID: tenantID, Token: tToken, CloudEnvironment: ce.Name}
if err := login.tokenStore.writeLoginInfo(loginInfo); err != nil { if err := login.tokenStore.writeLoginInfo(loginInfo); err != nil {
return errors.Wrapf(errdefs.ErrLoginFailed, "could not store login info: %s", err) return errors.Wrapf(api.ErrLoginFailed, "could not store login info: %s", err)
} }
return nil return nil
} }
@ -177,7 +177,7 @@ func (login *azureLoginService) Login(ctx context.Context, requestedTenantID str
redirectURL := s.Addr() redirectURL := s.Addr()
if redirectURL == "" { if redirectURL == "" {
return errors.Wrap(errdefs.ErrLoginFailed, "empty redirect URL") return errors.Wrap(api.ErrLoginFailed, "empty redirect URL")
} }
deviceCodeFlowCh := make(chan deviceCodeFlowResponse, 1) deviceCodeFlowCh := make(chan deviceCodeFlowResponse, 1)
@ -190,17 +190,17 @@ func (login *azureLoginService) Login(ctx context.Context, requestedTenantID str
return ctx.Err() return ctx.Err()
case dcft := <-deviceCodeFlowCh: case dcft := <-deviceCodeFlowCh:
if dcft.err != nil { if dcft.err != nil {
return errors.Wrapf(errdefs.ErrLoginFailed, "could not get token using device code flow: %s", err) return errors.Wrapf(api.ErrLoginFailed, "could not get token using device code flow: %s", err)
} }
token := dcft.token token := dcft.token
return login.getTenantAndValidateLogin(ctx, token.AccessToken, token.RefreshToken, requestedTenantID, ce) return login.getTenantAndValidateLogin(ctx, token.AccessToken, token.RefreshToken, requestedTenantID, ce)
case q := <-queryCh: case q := <-queryCh:
if q.err != nil { if q.err != nil {
return errors.Wrapf(errdefs.ErrLoginFailed, "unhandled local login server error: %s", err) return errors.Wrapf(api.ErrLoginFailed, "unhandled local login server error: %s", err)
} }
code, hasCode := q.values["code"] code, hasCode := q.values["code"]
if !hasCode { if !hasCode {
return errors.Wrap(errdefs.ErrLoginFailed, "no login code") return errors.Wrap(api.ErrLoginFailed, "no login code")
} }
data := url.Values{ data := url.Values{
"grant_type": []string{"authorization_code"}, "grant_type": []string{"authorization_code"},
@ -211,7 +211,7 @@ func (login *azureLoginService) Login(ctx context.Context, requestedTenantID str
} }
token, err := login.apiHelper.queryToken(ce, data, "organizations") token, err := login.apiHelper.queryToken(ce, data, "organizations")
if err != nil { if err != nil {
return errors.Wrapf(errdefs.ErrLoginFailed, "access token request failed: %s", err) return errors.Wrapf(api.ErrLoginFailed, "access token request failed: %s", err)
} }
return login.getTenantAndValidateLogin(ctx, token.AccessToken, token.RefreshToken, requestedTenantID, ce) return login.getTenantAndValidateLogin(ctx, token.AccessToken, token.RefreshToken, requestedTenantID, ce)
} }

View File

@ -30,9 +30,9 @@ import (
"github.com/docker/compose-cli/aci/login" "github.com/docker/compose-cli/aci/login"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/api/progress"
"github.com/docker/compose-cli/api/volumes" "github.com/docker/compose-cli/api/volumes"
"github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/pkg/progress"
) )
type aciVolumeService struct { type aciVolumeService struct {
@ -138,7 +138,7 @@ func (cs *aciVolumeService) Create(ctx context.Context, name string, options int
fileShare, err := fileShareClient.Get(ctx, cs.aciContext.ResourceGroup, *account.Name, name, "") fileShare, err := fileShareClient.Get(ctx, cs.aciContext.ResourceGroup, *account.Name, name, "")
if err == nil { if err == nil {
w.Event(progress.ErrorEvent(name)) w.Event(progress.ErrorEvent(name))
return volumes.Volume{}, errors.Wrapf(errdefs.ErrAlreadyExists, "Azure fileshare %q already exists", name) return volumes.Volume{}, errors.Wrapf(api.ErrAlreadyExists, "Azure fileshare %q already exists", name)
} }
if !fileShare.HasHTTPStatus(http.StatusNotFound) { if !fileShare.HasHTTPStatus(http.StatusNotFound) {
w.Event(progress.ErrorEvent(name)) w.Event(progress.ErrorEvent(name))
@ -212,7 +212,7 @@ func (cs *aciVolumeService) Delete(ctx context.Context, id string, options inter
if _, ok := account.Tags[dockerVolumeTag]; ok { if _, ok := account.Tags[dockerVolumeTag]; ok {
result, err := storageAccountsClient.Delete(ctx, cs.aciContext.ResourceGroup, storageAccount) result, err := storageAccountsClient.Delete(ctx, cs.aciContext.ResourceGroup, storageAccount)
if result.IsHTTPStatus(http.StatusNoContent) { if result.IsHTTPStatus(http.StatusNoContent) {
return errors.Wrapf(errdefs.ErrNotFound, "storage account %s does not exist", storageAccount) return errors.Wrapf(api.ErrNotFound, "storage account %s does not exist", storageAccount)
} }
return err return err
} }
@ -221,7 +221,7 @@ func (cs *aciVolumeService) Delete(ctx context.Context, id string, options inter
result, err := fileShareClient.Delete(ctx, cs.aciContext.ResourceGroup, storageAccount, fileshare) result, err := fileShareClient.Delete(ctx, cs.aciContext.ResourceGroup, storageAccount, fileshare)
if result.HasHTTPStatus(http.StatusNoContent) { if result.HasHTTPStatus(http.StatusNoContent) {
return errors.Wrapf(errdefs.ErrNotFound, "fileshare %q", fileshare) return errors.Wrapf(api.ErrNotFound, "fileshare %q", fileshare)
} }
return err return err
} }
@ -238,7 +238,7 @@ func (cs *aciVolumeService) Inspect(ctx context.Context, id string) (volumes.Vol
res, err := fileShareClient.Get(ctx, cs.aciContext.ResourceGroup, storageAccount, fileshareName, "") res, err := fileShareClient.Get(ctx, cs.aciContext.ResourceGroup, storageAccount, fileshareName, "")
if err != nil { // Just checks if it exists if err != nil { // Just checks if it exists
if res.HasHTTPStatus(http.StatusNotFound) { if res.HasHTTPStatus(http.StatusNotFound) {
return volumes.Volume{}, errors.Wrapf(errdefs.ErrNotFound, "account %q, file share %q. Original message %s", storageAccount, fileshareName, err.Error()) return volumes.Volume{}, errors.Wrapf(api.ErrNotFound, "account %q, file share %q. Original message %s", storageAccount, fileshareName, err.Error())
} }
return volumes.Volume{}, err return volumes.Volume{}, err
} }

View File

@ -23,12 +23,11 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/docker/compose-cli/api/cloud" "github.com/docker/compose-cli/api/cloud"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/containers" "github.com/docker/compose-cli/api/containers"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/api/resources" "github.com/docker/compose-cli/api/resources"
"github.com/docker/compose-cli/api/secrets" "github.com/docker/compose-cli/api/secrets"
"github.com/docker/compose-cli/api/volumes" "github.com/docker/compose-cli/api/volumes"
"github.com/docker/compose-cli/pkg/api"
) )
var ( var (
@ -66,7 +65,7 @@ func WithBackend(s Service) {
// Service aggregates the service interfaces // Service aggregates the service interfaces
type Service interface { type Service interface {
ContainerService() containers.Service ContainerService() containers.Service
ComposeService() compose.Service ComposeService() api.Service
ResourceService() resources.Service ResourceService() resources.Service
SecretsService() secrets.Service SecretsService() secrets.Service
VolumeService() volumes.Service VolumeService() volumes.Service
@ -103,7 +102,7 @@ func Get(backendType string) (Service, error) {
} }
} }
return nil, errdefs.ErrNotFound return nil, api.ErrNotFound
} }
// GetCloudService returns the backend registered for a particular type, it returns // GetCloudService returns the backend registered for a particular type, it returns

View File

@ -21,14 +21,13 @@ import (
"github.com/docker/compose-cli/api/backend" "github.com/docker/compose-cli/api/backend"
"github.com/docker/compose-cli/api/cloud" "github.com/docker/compose-cli/api/cloud"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/containers" "github.com/docker/compose-cli/api/containers"
apicontext "github.com/docker/compose-cli/api/context" apicontext "github.com/docker/compose-cli/api/context"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/api/resources" "github.com/docker/compose-cli/api/resources"
"github.com/docker/compose-cli/api/secrets" "github.com/docker/compose-cli/api/secrets"
"github.com/docker/compose-cli/api/volumes" "github.com/docker/compose-cli/api/volumes"
"github.com/docker/compose-cli/pkg/api"
) )
// New returns a backend client associated with current context // New returns a backend client associated with current context
@ -43,7 +42,7 @@ func New(ctx context.Context) (*Client, error) {
service := backend.Current() service := backend.Current()
if service == nil { if service == nil {
return nil, errdefs.ErrNotFound return nil, api.ErrNotFound
} }
client := NewClient(cc.Type(), service) client := NewClient(cc.Type(), service)
@ -84,7 +83,7 @@ func (c *Client) ContainerService() containers.Service {
} }
// ComposeService returns the backend service for the current context // ComposeService returns the backend service for the current context
func (c *Client) ComposeService() compose.Service { func (c *Client) ComposeService() api.Service {
if cs := c.bs.ComposeService(); cs != nil { if cs := c.bs.ComposeService(); cs != nil {
return cs return cs
} }

View File

@ -19,107 +19,105 @@ package client
import ( import (
"context" "context"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/errdefs"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/types"
"github.com/docker/compose-cli/pkg/api"
) )
type composeService struct { type composeService struct {
} }
func (c *composeService) Build(ctx context.Context, project *types.Project, options compose.BuildOptions) error { func (c *composeService) Build(ctx context.Context, project *types.Project, options api.BuildOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (c *composeService) Push(ctx context.Context, project *types.Project, options compose.PushOptions) error { func (c *composeService) Push(ctx context.Context, project *types.Project, options api.PushOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (c *composeService) Pull(ctx context.Context, project *types.Project, options compose.PullOptions) error { func (c *composeService) Pull(ctx context.Context, project *types.Project, options api.PullOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (c *composeService) Create(ctx context.Context, project *types.Project, opts compose.CreateOptions) error { func (c *composeService) Create(ctx context.Context, project *types.Project, opts api.CreateOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (c *composeService) Start(ctx context.Context, project *types.Project, options compose.StartOptions) error { func (c *composeService) Start(ctx context.Context, project *types.Project, options api.StartOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (c *composeService) Restart(ctx context.Context, project *types.Project, options compose.RestartOptions) error { func (c *composeService) Restart(ctx context.Context, project *types.Project, options api.RestartOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (c *composeService) Stop(ctx context.Context, project *types.Project, options compose.StopOptions) error { func (c *composeService) Stop(ctx context.Context, project *types.Project, options api.StopOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (c *composeService) Up(context.Context, *types.Project, compose.UpOptions) error { func (c *composeService) Up(context.Context, *types.Project, api.UpOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (c *composeService) Down(context.Context, string, compose.DownOptions) error { func (c *composeService) Down(context.Context, string, api.DownOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (c *composeService) Logs(context.Context, string, compose.LogConsumer, compose.LogOptions) error { func (c *composeService) Logs(context.Context, string, api.LogConsumer, api.LogOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (c *composeService) Ps(context.Context, string, compose.PsOptions) ([]compose.ContainerSummary, error) { func (c *composeService) Ps(context.Context, string, api.PsOptions) ([]api.ContainerSummary, error) {
return nil, errdefs.ErrNotImplemented return nil, api.ErrNotImplemented
} }
func (c *composeService) List(context.Context, compose.ListOptions) ([]compose.Stack, error) { func (c *composeService) List(context.Context, api.ListOptions) ([]api.Stack, error) {
return nil, errdefs.ErrNotImplemented return nil, api.ErrNotImplemented
} }
func (c *composeService) Convert(context.Context, *types.Project, compose.ConvertOptions) ([]byte, error) { func (c *composeService) Convert(context.Context, *types.Project, api.ConvertOptions) ([]byte, error) {
return nil, errdefs.ErrNotImplemented return nil, api.ErrNotImplemented
} }
func (c *composeService) Kill(ctx context.Context, project *types.Project, options compose.KillOptions) error { func (c *composeService) Kill(ctx context.Context, project *types.Project, options api.KillOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (c *composeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { func (c *composeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) {
return 0, errdefs.ErrNotImplemented return 0, api.ErrNotImplemented
} }
func (c *composeService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) error { func (c *composeService) Remove(ctx context.Context, project *types.Project, options api.RemoveOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (c *composeService) Exec(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { func (c *composeService) Exec(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) {
return 0, errdefs.ErrNotImplemented return 0, api.ErrNotImplemented
} }
func (c *composeService) Copy(ctx context.Context, project *types.Project, opts compose.CopyOptions) error { func (c *composeService) Copy(ctx context.Context, project *types.Project, opts api.CopyOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (c *composeService) Pause(ctx context.Context, project string, options compose.PauseOptions) error { func (c *composeService) Pause(ctx context.Context, project string, options api.PauseOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (c *composeService) UnPause(ctx context.Context, project string, options compose.PauseOptions) error { func (c *composeService) UnPause(ctx context.Context, project string, options api.PauseOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (c *composeService) Top(ctx context.Context, projectName string, services []string) ([]compose.ContainerProcSummary, error) { func (c *composeService) Top(ctx context.Context, projectName string, services []string) ([]api.ContainerProcSummary, error) {
return nil, errdefs.ErrNotImplemented return nil, api.ErrNotImplemented
} }
func (c *composeService) Events(ctx context.Context, project string, options compose.EventsOptions) error { func (c *composeService) Events(ctx context.Context, project string, options api.EventsOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (c *composeService) Port(ctx context.Context, project string, service string, port int, options compose.PortOptions) (string, int, error) { func (c *composeService) Port(ctx context.Context, project string, service string, port int, options api.PortOptions) (string, int, error) {
return "", 0, errdefs.ErrNotImplemented return "", 0, api.ErrNotImplemented
} }
func (c *composeService) Images(ctx context.Context, projectName string, options compose.ImagesOptions) ([]compose.ImageSummary, error) { func (c *composeService) Images(ctx context.Context, projectName string, options api.ImagesOptions) ([]api.ImageSummary, error) {
return nil, errdefs.ErrNotImplemented return nil, api.ErrNotImplemented
} }

View File

@ -20,7 +20,7 @@ import (
"context" "context"
"github.com/docker/compose-cli/api/containers" "github.com/docker/compose-cli/api/containers"
"github.com/docker/compose-cli/api/errdefs" "github.com/docker/compose-cli/pkg/api"
) )
type containerService struct { type containerService struct {
@ -28,44 +28,44 @@ type containerService struct {
// List returns all the containers // List returns all the containers
func (c *containerService) List(context.Context, bool) ([]containers.Container, error) { func (c *containerService) List(context.Context, bool) ([]containers.Container, error) {
return nil, errdefs.ErrNotImplemented return nil, api.ErrNotImplemented
} }
// Start starts a stopped container // Start starts a stopped container
func (c *containerService) Start(context.Context, string) error { func (c *containerService) Start(context.Context, string) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
// Stop stops the running container // Stop stops the running container
func (c *containerService) Stop(context.Context, string, *uint32) error { func (c *containerService) Stop(context.Context, string, *uint32) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (c *containerService) Kill(ctx context.Context, containerID string, signal string) error { func (c *containerService) Kill(ctx context.Context, containerID string, signal string) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
// Run creates and starts a container // Run creates and starts a container
func (c *containerService) Run(context.Context, containers.ContainerConfig) error { func (c *containerService) Run(context.Context, containers.ContainerConfig) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
// Exec executes a command inside a running container // Exec executes a command inside a running container
func (c *containerService) Exec(context.Context, string, containers.ExecRequest) error { func (c *containerService) Exec(context.Context, string, containers.ExecRequest) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
// Logs returns all the logs of a container // Logs returns all the logs of a container
func (c *containerService) Logs(context.Context, string, containers.LogsRequest) error { func (c *containerService) Logs(context.Context, string, containers.LogsRequest) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
// Delete removes containers // Delete removes containers
func (c *containerService) Delete(context.Context, string, containers.DeleteRequest) error { func (c *containerService) Delete(context.Context, string, containers.DeleteRequest) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
// Inspect get a specific container // Inspect get a specific container
func (c *containerService) Inspect(context.Context, string) (containers.Container, error) { func (c *containerService) Inspect(context.Context, string) (containers.Container, error) {
return containers.Container{}, errdefs.ErrNotImplemented return containers.Container{}, api.ErrNotImplemented
} }

View File

@ -19,8 +19,8 @@ package client
import ( import (
"context" "context"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/api/resources" "github.com/docker/compose-cli/api/resources"
"github.com/docker/compose-cli/pkg/api"
) )
type resourceService struct { type resourceService struct {
@ -28,5 +28,5 @@ type resourceService struct {
// Prune prune resources // Prune prune resources
func (c *resourceService) Prune(ctx context.Context, request resources.PruneRequest) (resources.PruneResult, error) { func (c *resourceService) Prune(ctx context.Context, request resources.PruneRequest) (resources.PruneResult, error) {
return resources.PruneResult{}, errdefs.ErrNotImplemented return resources.PruneResult{}, api.ErrNotImplemented
} }

View File

@ -19,25 +19,25 @@ package client
import ( import (
"context" "context"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/api/secrets" "github.com/docker/compose-cli/api/secrets"
"github.com/docker/compose-cli/pkg/api"
) )
type secretsService struct { type secretsService struct {
} }
func (s *secretsService) CreateSecret(context.Context, secrets.Secret) (string, error) { func (s *secretsService) CreateSecret(context.Context, secrets.Secret) (string, error) {
return "", errdefs.ErrNotImplemented return "", api.ErrNotImplemented
} }
func (s *secretsService) InspectSecret(context.Context, string) (secrets.Secret, error) { func (s *secretsService) InspectSecret(context.Context, string) (secrets.Secret, error) {
return secrets.Secret{}, errdefs.ErrNotImplemented return secrets.Secret{}, api.ErrNotImplemented
} }
func (s *secretsService) ListSecrets(context.Context) ([]secrets.Secret, error) { func (s *secretsService) ListSecrets(context.Context) ([]secrets.Secret, error) {
return nil, errdefs.ErrNotImplemented return nil, api.ErrNotImplemented
} }
func (s *secretsService) DeleteSecret(context.Context, string, bool) error { func (s *secretsService) DeleteSecret(context.Context, string, bool) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }

View File

@ -19,25 +19,25 @@ package client
import ( import (
"context" "context"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/api/volumes" "github.com/docker/compose-cli/api/volumes"
"github.com/docker/compose-cli/pkg/api"
) )
type volumeService struct { type volumeService struct {
} }
func (c *volumeService) List(ctx context.Context) ([]volumes.Volume, error) { func (c *volumeService) List(ctx context.Context) ([]volumes.Volume, error) {
return nil, errdefs.ErrNotImplemented return nil, api.ErrNotImplemented
} }
func (c *volumeService) Create(ctx context.Context, name string, options interface{}) (volumes.Volume, error) { func (c *volumeService) Create(ctx context.Context, name string, options interface{}) (volumes.Volume, error) {
return volumes.Volume{}, errdefs.ErrNotImplemented return volumes.Volume{}, api.ErrNotImplemented
} }
func (c *volumeService) Delete(ctx context.Context, id string, options interface{}) error { func (c *volumeService) Delete(ctx context.Context, id string, options interface{}) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (c *volumeService) Inspect(ctx context.Context, volumeID string) (volumes.Volume, error) { func (c *volumeService) Inspect(ctx context.Context, volumeID string) (volumes.Volume, error) {
return volumes.Volume{}, errdefs.ErrNotImplemented return volumes.Volume{}, api.ErrNotImplemented
} }

View File

@ -19,7 +19,7 @@ package cloud
import ( import (
"context" "context"
"github.com/docker/compose-cli/api/errdefs" "github.com/docker/compose-cli/pkg/api"
) )
// Service cloud specific services // Service cloud specific services
@ -42,13 +42,13 @@ type notImplementedCloudService struct {
// Logout login to cloud provider // Logout login to cloud provider
func (cs notImplementedCloudService) Logout(ctx context.Context) error { func (cs notImplementedCloudService) Logout(ctx context.Context) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (cs notImplementedCloudService) Login(ctx context.Context, params interface{}) error { func (cs notImplementedCloudService) Login(ctx context.Context, params interface{}) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (cs notImplementedCloudService) CreateContextData(ctx context.Context, params interface{}) (interface{}, string, error) { func (cs notImplementedCloudService) CreateContextData(ctx context.Context, params interface{}) (interface{}, string, error) {
return nil, "", errdefs.ErrNotImplemented return nil, "", api.ErrNotImplemented
} }

View File

@ -24,10 +24,10 @@ import (
"path/filepath" "path/filepath"
"reflect" "reflect"
"github.com/docker/compose-cli/pkg/api"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/docker/compose-cli/api/errdefs"
) )
const ( const (
@ -130,7 +130,7 @@ func (s *store) Get(name string) (*DockerContext, error) {
meta := filepath.Join(s.root, contextsDir, metadataDir, contextDirOf(name), metaFile) meta := filepath.Join(s.root, contextsDir, metadataDir, contextDirOf(name), metaFile)
m, err := read(meta) m, err := read(meta)
if os.IsNotExist(err) { if os.IsNotExist(err) {
return nil, errors.Wrap(errdefs.ErrNotFound, objectName(name)) return nil, errors.Wrap(api.ErrNotFound, objectName(name))
} else if err != nil { } else if err != nil {
return nil, err return nil, err
} }
@ -145,7 +145,7 @@ func (s *store) GetEndpoint(name string, data interface{}) error {
} }
contextType := meta.Type() contextType := meta.Type()
if _, ok := meta.Endpoints[contextType]; !ok { if _, ok := meta.Endpoints[contextType]; !ok {
return errors.Wrapf(errdefs.ErrNotFound, "endpoint of type %q", contextType) return errors.Wrapf(api.ErrNotFound, "endpoint of type %q", contextType)
} }
dstPtrValue := reflect.ValueOf(data) dstPtrValue := reflect.ValueOf(data)
@ -155,7 +155,7 @@ func (s *store) GetEndpoint(name string, data interface{}) error {
valIndirect := reflect.Indirect(val) valIndirect := reflect.Indirect(val)
if dstValue.Type() != valIndirect.Type() { if dstValue.Type() != valIndirect.Type() {
return errdefs.ErrWrongContextType return api.ErrWrongContextType
} }
dstValue.Set(valIndirect) dstValue.Set(valIndirect)
@ -223,7 +223,7 @@ func (s *store) ContextExists(name string) bool {
func (s *store) Create(name string, contextType string, description string, data interface{}) error { func (s *store) Create(name string, contextType string, description string, data interface{}) error {
if s.ContextExists(name) { if s.ContextExists(name) {
return errors.Wrap(errdefs.ErrAlreadyExists, objectName(name)) return errors.Wrap(api.ErrAlreadyExists, objectName(name))
} }
dir := contextDirOf(name) dir := contextDirOf(name)
metaDir := filepath.Join(s.root, contextsDir, metadataDir, dir) metaDir := filepath.Join(s.root, contextsDir, metadataDir, dir)
@ -285,15 +285,15 @@ func (s *store) List() ([]*DockerContext, error) {
func (s *store) Remove(name string) error { func (s *store) Remove(name string) error {
if name == DefaultContextName { if name == DefaultContextName {
return errors.Wrap(errdefs.ErrForbidden, objectName(name)) return errors.Wrap(api.ErrForbidden, objectName(name))
} }
dir := filepath.Join(s.root, contextsDir, metadataDir, contextDirOf(name)) dir := filepath.Join(s.root, contextsDir, metadataDir, contextDirOf(name))
// Check if directory exists because os.RemoveAll returns nil if it doesn't // Check if directory exists because os.RemoveAll returns nil if it doesn't
if _, err := os.Stat(dir); os.IsNotExist(err) { if _, err := os.Stat(dir); os.IsNotExist(err) {
return errors.Wrap(errdefs.ErrNotFound, objectName(name)) return errors.Wrap(api.ErrNotFound, objectName(name))
} }
if err := os.RemoveAll(dir); err != nil { if err := os.RemoveAll(dir); err != nil {
return errors.Wrapf(errdefs.ErrUnknown, "unable to remove %s: %s", objectName(name), err) return errors.Wrapf(api.ErrUnknown, "unable to remove %s: %s", objectName(name), err)
} }
return nil return nil
} }

View File

@ -22,10 +22,10 @@ import (
"os" "os"
"testing" "testing"
"github.com/docker/compose-cli/pkg/api"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
"gotest.tools/v3/assert/cmp" "gotest.tools/v3/assert/cmp"
"github.com/docker/compose-cli/api/errdefs"
) )
func testStore(t *testing.T) Store { func testStore(t *testing.T) Store {
@ -49,7 +49,7 @@ func TestCreate(t *testing.T) {
err = s.Create("test", "test", "descrsiption", ContextMetadata{}) err = s.Create("test", "test", "descrsiption", ContextMetadata{})
assert.Error(t, err, `context "test": already exists`) assert.Error(t, err, `context "test": already exists`)
assert.Assert(t, errdefs.IsAlreadyExistsError(err)) assert.Assert(t, api.IsAlreadyExistsError(err))
} }
func TestGetEndpoint(t *testing.T) { func TestGetEndpoint(t *testing.T) {
@ -74,7 +74,7 @@ func TestGetUnknown(t *testing.T) {
meta, err := s.Get("unknown") meta, err := s.Get("unknown")
assert.Assert(t, cmp.Nil(meta)) assert.Assert(t, cmp.Nil(meta))
assert.Error(t, err, `context "unknown": not found`) assert.Error(t, err, `context "unknown": not found`)
assert.Assert(t, errdefs.IsNotFoundError(err)) assert.Assert(t, api.IsNotFoundError(err))
} }
func TestGet(t *testing.T) { func TestGet(t *testing.T) {
@ -99,7 +99,7 @@ func TestRemoveNotFound(t *testing.T) {
s := testStore(t) s := testStore(t)
err := s.Remove("notfound") err := s.Remove("notfound")
assert.Error(t, err, `context "notfound": not found`) assert.Error(t, err, `context "notfound": not found`)
assert.Assert(t, errdefs.IsNotFoundError(err)) assert.Assert(t, api.IsNotFoundError(err))
} }
func TestRemove(t *testing.T) { func TestRemove(t *testing.T) {

View File

@ -55,7 +55,7 @@ cli:
.PHONY: compose-plugin .PHONY: compose-plugin
compose-plugin: compose-plugin:
GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY_WITH_EXTENSION) . GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY_WITH_EXTENSION) ./cmd
.PHONY: cross .PHONY: cross
cross: cross:
@ -69,13 +69,13 @@ cross:
.PHONY: cross-compose-plugin .PHONY: cross-compose-plugin
cross-compose-plugin: cross-compose-plugin:
GOOS=linux GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-amd64 . GOOS=linux GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-amd64 ./cmd
GOOS=linux GOARCH=arm64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-arm64 . GOOS=linux GOARCH=arm64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-arm64 ./cmd
GOOS=linux GOARM=6 GOARCH=arm $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-armv6 . GOOS=linux GOARM=6 GOARCH=arm $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-armv6 ./cmd
GOOS=linux GOARM=7 GOARCH=arm $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-armv7 . GOOS=linux GOARM=7 GOARCH=arm $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-armv7 ./cmd
GOOS=darwin GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-darwin-amd64 . GOOS=darwin GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-darwin-amd64 ./cmd
GOOS=darwin GOARCH=arm64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-darwin-arm64 . GOOS=darwin GOARCH=arm64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-darwin-arm64 ./cmd
GOOS=windows GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-windows-amd64.exe . GOOS=windows GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-windows-amd64.exe ./cmd
.PHONY: test .PHONY: test
test: test:

View File

@ -25,7 +25,7 @@ import (
"github.com/docker/compose-cli/aci" "github.com/docker/compose-cli/aci"
"github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/client"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/api/errdefs" "github.com/docker/compose-cli/pkg/api"
) )
func init() { func init() {
@ -58,7 +58,7 @@ func createAciCommand() *cobra.Command {
func runCreateAci(ctx context.Context, contextName string, opts aci.ContextParams) error { func runCreateAci(ctx context.Context, contextName string, opts aci.ContextParams) error {
if contextExists(contextName) { if contextExists(contextName) {
return errors.Wrapf(errdefs.ErrAlreadyExists, "context %s", contextName) return errors.Wrapf(api.ErrAlreadyExists, "context %s", contextName)
} }
contextData, description, err := getAciContextData(ctx, opts) contextData, description, err := getAciContextData(ctx, opts)
if err != nil { if err != nil {

View File

@ -28,8 +28,8 @@ import (
"github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/client"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/ecs" "github.com/docker/compose-cli/ecs"
"github.com/docker/compose-cli/pkg/api"
) )
func init() { func init() {
@ -110,7 +110,7 @@ func parseAccessKeysFile(file string, opts *ecs.ContextParams) error {
func runCreateLocalSimulation(ctx context.Context, contextName string, opts ecs.ContextParams) error { func runCreateLocalSimulation(ctx context.Context, contextName string, opts ecs.ContextParams) error {
if contextExists(contextName) { if contextExists(contextName) {
return errors.Wrapf(errdefs.ErrAlreadyExists, "context %q", contextName) return errors.Wrapf(api.ErrAlreadyExists, "context %q", contextName)
} }
cs, err := client.GetCloudService(ctx, store.EcsLocalSimulationContextType) cs, err := client.GetCloudService(ctx, store.EcsLocalSimulationContextType)
if err != nil { if err != nil {
@ -125,7 +125,7 @@ func runCreateLocalSimulation(ctx context.Context, contextName string, opts ecs.
func runCreateEcs(ctx context.Context, contextName string, opts ecs.ContextParams) error { func runCreateEcs(ctx context.Context, contextName string, opts ecs.ContextParams) error {
if contextExists(contextName) { if contextExists(contextName) {
return errors.Wrapf(errdefs.ErrAlreadyExists, "context %q", contextName) return errors.Wrapf(api.ErrAlreadyExists, "context %q", contextName)
} }
contextData, description, err := getEcsContextData(ctx, opts) contextData, description, err := getEcsContextData(ctx, opts)
if err != nil { if err != nil {

View File

@ -19,11 +19,11 @@
package context package context
import ( import (
"github.com/docker/compose-cli/pkg/api"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/kube" "github.com/docker/compose-cli/kube"
) )
@ -56,7 +56,7 @@ func createKubeCommand() *cobra.Command {
func runCreateKube(contextName string, opts kube.ContextParams) error { func runCreateKube(contextName string, opts kube.ContextParams) error {
if contextExists(contextName) { if contextExists(contextName) {
return errors.Wrapf(errdefs.ErrAlreadyExists, "context %q", contextName) return errors.Wrapf(api.ErrAlreadyExists, "context %q", contextName)
} }
contextData, description, err := opts.CreateContextData() contextData, description, err := opts.CreateContextData()

View File

@ -17,11 +17,11 @@
package context package context
import ( import (
"github.com/docker/compose-cli/pkg/api"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/cli/mobycli" "github.com/docker/compose-cli/cli/mobycli"
) )
@ -76,7 +76,7 @@ func runUpdate(cmd *cobra.Command, name string) error {
dockerContext, err := s.Get(name) dockerContext, err := s.Get(name)
if err == nil && dockerContext != nil { if err == nil && dockerContext != nil {
if dockerContext.Type() != store.DefaultContextType { if dockerContext.Type() != store.DefaultContextType {
return errors.Wrapf(errdefs.ErrNotImplemented, "context update for context type %q not supported", dockerContext.Type()) return errors.Wrapf(api.ErrNotImplemented, "context update for context type %q not supported", dockerContext.Type())
} }
} }

View File

@ -25,8 +25,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/client"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/cli/formatter"
"github.com/docker/compose-cli/pkg/api"
) )
type killOpts struct { type killOpts struct {
@ -60,7 +60,7 @@ func runKill(ctx context.Context, args []string, opts killOpts) error {
for _, id := range args { for _, id := range args {
err := c.ContainerService().Kill(ctx, id, opts.signal) err := c.ContainerService().Kill(ctx, id, opts.signal)
if err != nil { if err != nil {
if errdefs.IsNotFoundError(err) { if api.IsNotFoundError(err) {
errs = multierror.Append(errs, fmt.Errorf("container %s not found", id)) errs = multierror.Append(errs, fmt.Errorf("container %s not found", id))
} else { } else {
errs = multierror.Append(errs, err) errs = multierror.Append(errs, err)

View File

@ -24,8 +24,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/client"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/cli/mobycli" "github.com/docker/compose-cli/cli/mobycli"
"github.com/docker/compose-cli/pkg/api"
) )
// Command returns the login command // Command returns the login command
@ -56,7 +56,7 @@ func cloudLogin(cmd *cobra.Command, backendType string, params interface{}) erro
ctx := cmd.Context() ctx := cmd.Context()
cs, err := client.GetCloudService(ctx, backendType) cs, err := client.GetCloudService(ctx, backendType)
if err != nil { if err != nil {
return errors.Wrap(errdefs.ErrLoginFailed, "cannot connect to backend") return errors.Wrap(api.ErrLoginFailed, "cannot connect to backend")
} }
err = cs.Login(ctx, params) err = cs.Login(ctx, params)
if errors.Is(err, context.Canceled) { if errors.Is(err, context.Canceled) {

View File

@ -24,7 +24,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/client"
"github.com/docker/compose-cli/api/errdefs" "github.com/docker/compose-cli/pkg/api"
) )
// AzureLogoutCommand returns the azure logout command // AzureLogoutCommand returns the azure logout command
@ -44,7 +44,7 @@ func cloudLogout(cmd *cobra.Command, backendType string) error {
ctx := cmd.Context() ctx := cmd.Context()
cs, err := client.GetCloudService(ctx, backendType) cs, err := client.GetCloudService(ctx, backendType)
if err != nil { if err != nil {
return errors.Wrap(errdefs.ErrLoginFailed, "cannot connect to backend") return errors.Wrap(api.ErrLoginFailed, "cannot connect to backend")
} }
err = cs.Logout(ctx) err = cs.Logout(ctx)
if errors.Is(err, context.Canceled) { if errors.Is(err, context.Canceled) {

View File

@ -26,8 +26,8 @@ import (
"github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/client"
"github.com/docker/compose-cli/api/containers" "github.com/docker/compose-cli/api/containers"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/cli/formatter"
"github.com/docker/compose-cli/pkg/api"
) )
type rmOpts struct { type rmOpts struct {
@ -63,9 +63,9 @@ func runRm(ctx context.Context, args []string, opts rmOpts) error {
Force: opts.force, Force: opts.force,
}) })
if err != nil { if err != nil {
if errdefs.IsForbiddenError(err) { if api.IsForbiddenError(err) {
errs = multierror.Append(errs, fmt.Errorf("you cannot remove a running container %s. Stop the container before attempting removal or force remove", id)) errs = multierror.Append(errs, fmt.Errorf("you cannot remove a running container %s. Stop the container before attempting removal or force remove", id))
} else if errdefs.IsNotFoundError(err) { } else if api.IsNotFoundError(err) {
errs = multierror.Append(errs, fmt.Errorf("container %s not found", id)) errs = multierror.Append(errs, fmt.Errorf("container %s not found", id))
} else { } else {
errs = multierror.Append(errs, err) errs = multierror.Append(errs, err)

View File

@ -29,8 +29,8 @@ import (
"github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/client"
"github.com/docker/compose-cli/api/containers" "github.com/docker/compose-cli/api/containers"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/api/progress"
"github.com/docker/compose-cli/cli/options/run" "github.com/docker/compose-cli/cli/options/run"
"github.com/docker/compose-cli/pkg/progress"
) )
// Command runs a container // Command runs a container

View File

@ -25,8 +25,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/client"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/cli/formatter"
"github.com/docker/compose-cli/pkg/api"
) )
// StartCommand starts containers // StartCommand starts containers
@ -53,7 +53,7 @@ func runStart(ctx context.Context, args []string) error {
for _, id := range args { for _, id := range args {
err := c.ContainerService().Start(ctx, id) err := c.ContainerService().Start(ctx, id)
if err != nil { if err != nil {
if errdefs.IsNotFoundError(err) { if api.IsNotFoundError(err) {
errs = multierror.Append(errs, fmt.Errorf("container %s not found", id)) errs = multierror.Append(errs, fmt.Errorf("container %s not found", id))
} else { } else {
errs = multierror.Append(errs, err) errs = multierror.Append(errs, err)

View File

@ -25,8 +25,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/client"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/cli/formatter"
"github.com/docker/compose-cli/pkg/api"
) )
type stopOpts struct { type stopOpts struct {
@ -60,7 +60,7 @@ func runStop(ctx context.Context, args []string, opts stopOpts) error {
for _, id := range args { for _, id := range args {
err := c.ContainerService().Stop(ctx, id, &opts.timeout) err := c.ContainerService().Stop(ctx, id, &opts.timeout)
if err != nil { if err != nil {
if errdefs.IsNotFoundError(err) { if api.IsNotFoundError(err) {
errs = multierror.Append(errs, fmt.Errorf("container %s not found", id)) errs = multierror.Append(errs, fmt.Errorf("container %s not found", id))
} else { } else {
errs = multierror.Append(errs, err) errs = multierror.Append(errs, err)

View File

@ -23,10 +23,10 @@ import (
"github.com/docker/compose-cli/aci" "github.com/docker/compose-cli/aci"
"github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/client"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/api/progress"
"github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/cli/formatter"
formatter2 "github.com/docker/compose-cli/cli/formatter" format "github.com/docker/compose-cli/cli/formatter"
"github.com/docker/compose-cli/ecs" "github.com/docker/compose-cli/ecs"
"github.com/docker/compose-cli/pkg/progress"
"github.com/hashicorp/go-multierror" "github.com/hashicorp/go-multierror"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -146,7 +146,7 @@ func inspectVolume() *cobra.Command {
if err != nil { if err != nil {
return err return err
} }
outJSON, err := formatter2.ToStandardJSON(v) outJSON, err := format.ToStandardJSON(v)
if err != nil { if err != nil {
return err return err
} }

View File

@ -22,9 +22,9 @@ import (
"reflect" "reflect"
"strings" "strings"
"github.com/pkg/errors" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/api/errdefs" "github.com/pkg/errors"
) )
// Print prints formatted lists in different formats // Print prints formatted lists in different formats
@ -67,7 +67,7 @@ func Print(toJSON interface{}, format string, outWriter io.Writer, writerFn func
_, _ = fmt.Fprintln(outWriter, outJSON) _, _ = fmt.Fprintln(outWriter, outJSON)
} }
default: default:
return errors.Wrapf(errdefs.ErrParsingFailed, "format value %q could not be parsed", format) return errors.Wrapf(api.ErrParsingFailed, "format value %q could not be parsed", format)
} }
return nil return nil
} }

View File

@ -23,11 +23,11 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
) )
// NewLogConsumer creates a new LogConsumer // NewLogConsumer creates a new LogConsumer
func NewLogConsumer(ctx context.Context, w io.Writer, color bool, prefix bool) compose.LogConsumer { func NewLogConsumer(ctx context.Context, w io.Writer, color bool, prefix bool) api.LogConsumer {
return &logConsumer{ return &logConsumer{
ctx: ctx, ctx: ctx,
presenters: map[string]*presenter{}, presenters: map[string]*presenter{},

View File

@ -35,13 +35,10 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/backend" "github.com/docker/compose-cli/api/backend"
api "github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/config" "github.com/docker/compose-cli/api/config"
apicontext "github.com/docker/compose-cli/api/context" apicontext "github.com/docker/compose-cli/api/context"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/cli/cmd" "github.com/docker/compose-cli/cli/cmd"
"github.com/docker/compose-cli/cli/cmd/compose"
contextcmd "github.com/docker/compose-cli/cli/cmd/context" contextcmd "github.com/docker/compose-cli/cli/cmd/context"
"github.com/docker/compose-cli/cli/cmd/login" "github.com/docker/compose-cli/cli/cmd/login"
"github.com/docker/compose-cli/cli/cmd/logout" "github.com/docker/compose-cli/cli/cmd/logout"
@ -51,7 +48,10 @@ import (
"github.com/docker/compose-cli/cli/metrics" "github.com/docker/compose-cli/cli/metrics"
"github.com/docker/compose-cli/cli/mobycli" "github.com/docker/compose-cli/cli/mobycli"
cliopts "github.com/docker/compose-cli/cli/options" cliopts "github.com/docker/compose-cli/cli/options"
compose2 "github.com/docker/compose-cli/cmd/compose"
"github.com/docker/compose-cli/local" "github.com/docker/compose-cli/local"
"github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/pkg/compose"
// Backend registrations // Backend registrations
_ "github.com/docker/compose-cli/aci" _ "github.com/docker/compose-cli/aci"
@ -226,7 +226,7 @@ func main() {
if ctype != store.DefaultContextType { if ctype != store.DefaultContextType {
// On default context, "compose" is implemented by CLI Plugin // On default context, "compose" is implemented by CLI Plugin
proxy := api.NewServiceProxy().WithService(service.ComposeService()) proxy := api.NewServiceProxy().WithService(service.ComposeService())
command := compose.RootCommand(ctype, proxy) command := compose2.RootCommand(ctype, proxy)
if ctype == store.AciContextType { if ctype == store.AciContextType {
customizeCliForACI(command, proxy) customizeCliForACI(command, proxy)
@ -238,7 +238,7 @@ func main() {
if err = root.ExecuteContext(ctx); err != nil { if err = root.ExecuteContext(ctx); err != nil {
handleError(ctx, err, ctype, currentContext, cc, root) handleError(ctx, err, ctype, currentContext, cc, root)
} }
metrics.Track(ctype, os.Args[1:], metrics.SuccessStatus) metrics.Track(ctype, os.Args[1:], compose.SuccessStatus)
} }
func customizeCliForACI(command *cobra.Command, proxy *api.ServiceProxy) { func customizeCliForACI(command *cobra.Command, proxy *api.ServiceProxy) {
@ -263,7 +263,7 @@ func getBackend(ctype string, configDir string, opts cliopts.GlobalOpts) (backen
return local.GetLocalBackend(configDir, opts) return local.GetLocalBackend(configDir, opts)
} }
service, err := backend.Get(ctype) service, err := backend.Get(ctype)
if errdefs.IsNotFoundError(err) { if api.IsNotFoundError(err) {
return service, nil return service, nil
} }
return service, err return service, err
@ -271,8 +271,8 @@ func getBackend(ctype string, configDir string, opts cliopts.GlobalOpts) (backen
func handleError(ctx context.Context, err error, ctype string, currentContext string, cc *store.DockerContext, root *cobra.Command) { func handleError(ctx context.Context, err error, ctype string, currentContext string, cc *store.DockerContext, root *cobra.Command) {
// if user canceled request, simply exit without any error message // if user canceled request, simply exit without any error message
if errdefs.IsErrCanceled(err) || errors.Is(ctx.Err(), context.Canceled) { if api.IsErrCanceled(err) || errors.Is(ctx.Err(), context.Canceled) {
metrics.Track(ctype, os.Args[1:], metrics.CanceledStatus) metrics.Track(ctype, os.Args[1:], compose.CanceledStatus)
os.Exit(130) os.Exit(130)
} }
if ctype == store.AwsContextType { if ctype == store.AwsContextType {
@ -294,34 +294,34 @@ $ docker context create %s <name>`, cc.Type(), store.EcsContextType), ctype)
func exit(ctx string, err error, ctype string) { func exit(ctx string, err error, ctype string) {
if exit, ok := err.(cli.StatusError); ok { if exit, ok := err.(cli.StatusError); ok {
metrics.Track(ctype, os.Args[1:], metrics.SuccessStatus) metrics.Track(ctype, os.Args[1:], compose.SuccessStatus)
os.Exit(exit.StatusCode) os.Exit(exit.StatusCode)
} }
var composeErr metrics.ComposeError var composeErr compose.Error
metricsStatus := metrics.FailureStatus metricsStatus := compose.FailureStatus
exitCode := 1 exitCode := 1
if errors.As(err, &composeErr) { if errors.As(err, &composeErr) {
metricsStatus = composeErr.GetMetricsFailureCategory().MetricsStatus metricsStatus = composeErr.GetMetricsFailureCategory().MetricsStatus
exitCode = composeErr.GetMetricsFailureCategory().ExitCode exitCode = composeErr.GetMetricsFailureCategory().ExitCode
} }
if strings.HasPrefix(err.Error(), "unknown shorthand flag:") || strings.HasPrefix(err.Error(), "unknown flag:") || strings.HasPrefix(err.Error(), "unknown docker command:") { if strings.HasPrefix(err.Error(), "unknown shorthand flag:") || strings.HasPrefix(err.Error(), "unknown flag:") || strings.HasPrefix(err.Error(), "unknown docker command:") {
metricsStatus = metrics.CommandSyntaxFailure.MetricsStatus metricsStatus = compose.CommandSyntaxFailure.MetricsStatus
exitCode = metrics.CommandSyntaxFailure.ExitCode exitCode = compose.CommandSyntaxFailure.ExitCode
} }
metrics.Track(ctype, os.Args[1:], metricsStatus) metrics.Track(ctype, os.Args[1:], metricsStatus)
if errors.Is(err, errdefs.ErrLoginRequired) { if errors.Is(err, api.ErrLoginRequired) {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
os.Exit(errdefs.ExitCodeLoginRequired) os.Exit(api.ExitCodeLoginRequired)
} }
if compose.Warning != "" { if compose2.Warning != "" {
logrus.Warn(err) logrus.Warn(err)
fmt.Fprintln(os.Stderr, compose.Warning) fmt.Fprintln(os.Stderr, compose2.Warning)
} }
if errors.Is(err, errdefs.ErrNotImplemented) { if errors.Is(err, api.ErrNotImplemented) {
name := metrics.GetCommand(os.Args[1:]) name := metrics.GetCommand(os.Args[1:])
fmt.Fprintf(os.Stderr, "Command %q not available in current context (%s)\n", name, ctx) fmt.Fprintf(os.Stderr, "Command %q not available in current context (%s)\n", name, ctx)
@ -344,7 +344,7 @@ func checkIfUnknownCommandExistInDefaultContext(err error, currentContext string
if mobycli.IsDefaultContextCommand(dockerCommand) { if mobycli.IsDefaultContextCommand(dockerCommand) {
fmt.Fprintf(os.Stderr, "Command %q not available in current context (%s), you can use the \"default\" context to run this command\n", dockerCommand, currentContext) fmt.Fprintf(os.Stderr, "Command %q not available in current context (%s), you can use the \"default\" context to run this command\n", dockerCommand, currentContext)
metrics.Track(contextType, os.Args[1:], metrics.FailureStatus) metrics.Track(contextType, os.Args[1:], compose.FailureStatus)
os.Exit(1) os.Exit(1)
} }
} }

View File

@ -21,7 +21,7 @@ import (
"os/exec" "os/exec"
"strings" "strings"
"github.com/docker/compose-cli/utils" "github.com/docker/compose-cli/pkg/utils"
) )
var managementCommands = []string{"ecs", "scan"} var managementCommands = []string{"ecs", "scan"}

View File

@ -20,7 +20,7 @@ import (
"os" "os"
"strings" "strings"
"github.com/docker/compose-cli/utils" "github.com/docker/compose-cli/pkg/utils"
) )
// Track sends the tracking analytics to Docker Desktop // Track sends the tracking analytics to Docker Desktop

View File

@ -24,13 +24,14 @@ import (
"os/signal" "os/signal"
"regexp" "regexp"
"github.com/spf13/cobra"
apicontext "github.com/docker/compose-cli/api/context" apicontext "github.com/docker/compose-cli/api/context"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/cli/metrics" "github.com/docker/compose-cli/cli/metrics"
"github.com/docker/compose-cli/cli/mobycli/resolvepath" "github.com/docker/compose-cli/cli/mobycli/resolvepath"
"github.com/docker/compose-cli/utils" "github.com/spf13/cobra"
"github.com/docker/compose-cli/pkg/compose"
"github.com/docker/compose-cli/pkg/utils"
) )
var delegatedContextTypes = []string{store.DefaultContextType} var delegatedContextTypes = []string{store.DefaultContextType}
@ -68,10 +69,10 @@ func Exec(root *cobra.Command) {
if err != nil { if err != nil {
if exiterr, ok := err.(*exec.ExitError); ok { if exiterr, ok := err.(*exec.ExitError); ok {
exitCode := exiterr.ExitCode() exitCode := exiterr.ExitCode()
metrics.Track(store.DefaultContextType, os.Args[1:], metrics.ByExitCode(exitCode).MetricsStatus) metrics.Track(store.DefaultContextType, os.Args[1:], compose.ByExitCode(exitCode).MetricsStatus)
os.Exit(exitCode) os.Exit(exitCode)
} }
metrics.Track(store.DefaultContextType, os.Args[1:], metrics.FailureStatus) metrics.Track(store.DefaultContextType, os.Args[1:], compose.FailureStatus)
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
os.Exit(1) os.Exit(1)
} }
@ -79,7 +80,7 @@ func Exec(root *cobra.Command) {
if command == "build" && !metrics.HasQuietFlag(os.Args[1:]) { if command == "build" && !metrics.HasQuietFlag(os.Args[1:]) {
utils.DisplayScanSuggestMsg() utils.DisplayScanSuggestMsg()
} }
metrics.Track(store.DefaultContextType, os.Args[1:], metrics.SuccessStatus) metrics.Track(store.DefaultContextType, os.Args[1:], compose.SuccessStatus)
os.Exit(0) os.Exit(0)
} }

View File

@ -23,6 +23,7 @@ import (
"github.com/docker/compose-cli/cli/metrics" "github.com/docker/compose-cli/cli/metrics"
"github.com/docker/compose-cli/cli/server/proxy" "github.com/docker/compose-cli/cli/server/proxy"
"github.com/docker/compose-cli/pkg/compose"
) )
var ( var (
@ -60,16 +61,16 @@ func metricsServerInterceptor(client metrics.Client) grpc.UnaryServerInterceptor
data, err := handler(ctx, req) data, err := handler(ctx, req)
status := metrics.SuccessStatus status := compose.SuccessStatus
if err != nil { if err != nil {
status = metrics.FailureStatus status = compose.FailureStatus
} }
command := methodMapping[info.FullMethod] command := methodMapping[info.FullMethod]
if command != "" { if command != "" {
client.Send(metrics.Command{ client.Send(metrics.Command{
Command: command, Command: command,
Context: contextType, Context: contextType,
Source: metrics.APISource, Source: compose.APISource,
Status: status, Status: status,
}) })
} }

View File

@ -29,9 +29,7 @@ import (
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
"github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/client"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/containers" "github.com/docker/compose-cli/api/containers"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/api/secrets" "github.com/docker/compose-cli/api/secrets"
"github.com/docker/compose-cli/api/volumes" "github.com/docker/compose-cli/api/volumes"
"github.com/docker/compose-cli/cli/metrics" "github.com/docker/compose-cli/cli/metrics"
@ -40,6 +38,7 @@ import (
streamsv1 "github.com/docker/compose-cli/cli/server/protos/streams/v1" streamsv1 "github.com/docker/compose-cli/cli/server/protos/streams/v1"
volumesv1 "github.com/docker/compose-cli/cli/server/protos/volumes/v1" volumesv1 "github.com/docker/compose-cli/cli/server/protos/volumes/v1"
"github.com/docker/compose-cli/cli/server/proxy" "github.com/docker/compose-cli/cli/server/proxy"
"github.com/docker/compose-cli/pkg/api"
) )
func TestAllMethodsHaveCorrespondingCliCommand(t *testing.T) { func TestAllMethodsHaveCorrespondingCliCommand(t *testing.T) {
@ -77,8 +76,8 @@ func TestTrackSFailures(t *testing.T) {
interceptor := metricsServerInterceptor(mockMetrics) interceptor := metricsServerInterceptor(mockMetrics)
ctx := proxy.WithClient(incomingContext("default"), &newClient) ctx := proxy.WithClient(incomingContext("default"), &newClient)
_, err := interceptor(ctx, nil, containerMethodRoute("Create"), mockHandler(errdefs.ErrLoginRequired)) _, err := interceptor(ctx, nil, containerMethodRoute("Create"), mockHandler(api.ErrLoginRequired))
assert.Assert(t, err == errdefs.ErrLoginRequired) assert.Assert(t, err == api.ErrLoginRequired)
} }
func containerMethodRoute(action string) *grpc.UnaryServerInfo { func containerMethodRoute(action string) *grpc.UnaryServerInfo {
@ -115,7 +114,7 @@ func setupServer() *grpc.Server {
type noopService struct{} type noopService struct{}
func (noopService) ContainerService() containers.Service { return nil } func (noopService) ContainerService() containers.Service { return nil }
func (noopService) ComposeService() compose.Service { return nil } func (noopService) ComposeService() api.Service { return nil }
func (noopService) SecretsService() secrets.Service { return nil } func (noopService) SecretsService() secrets.Service { return nil }
func (noopService) VolumeService() volumes.Service { return nil } func (noopService) VolumeService() volumes.Service { return nil }
func (noopService) ResourceService() resources.Service { return nil } func (noopService) ResourceService() resources.Service { return nil }

View File

@ -24,7 +24,7 @@ import (
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/types"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
) )
type buildOptions struct { type buildOptions struct {
@ -38,7 +38,7 @@ type buildOptions struct {
memory string memory string
} }
func buildCommand(p *projectOptions, backend compose.Service) *cobra.Command { func buildCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := buildOptions{ opts := buildOptions{
projectOptions: p, projectOptions: p,
} }
@ -81,13 +81,13 @@ func buildCommand(p *projectOptions, backend compose.Service) *cobra.Command {
return cmd return cmd
} }
func runBuild(ctx context.Context, backend compose.Service, opts buildOptions, services []string) error { func runBuild(ctx context.Context, backend api.Service, opts buildOptions, services []string) error {
project, err := opts.toProject(services) project, err := opts.toProject(services)
if err != nil { if err != nil {
return err return err
} }
return backend.Build(ctx, project, compose.BuildOptions{ return backend.Build(ctx, project, api.BuildOptions{
Pull: opts.pull, Pull: opts.pull,
Progress: opts.progress, Progress: opts.progress,
Args: types.NewMappingWithEquals(opts.args), Args: types.NewMappingWithEquals(opts.args),

View File

@ -33,11 +33,10 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/cli/formatter"
"github.com/docker/compose-cli/cli/metrics" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/pkg/compose"
) )
//Command defines a compose CLI command as a func with args //Command defines a compose CLI command as a func with args
@ -59,11 +58,11 @@ func Adapt(fn Command) func(cmd *cobra.Command, args []string) error {
}() }()
} }
err := fn(ctx, args) err := fn(ctx, args)
var composeErr metrics.ComposeError var composeErr compose.Error
if errdefs.IsErrCanceled(err) || errors.Is(ctx.Err(), context.Canceled) { if api.IsErrCanceled(err) || errors.Is(ctx.Err(), context.Canceled) {
err = dockercli.StatusError{ err = dockercli.StatusError{
StatusCode: 130, StatusCode: 130,
Status: metrics.CanceledStatus, Status: compose.CanceledStatus,
} }
} }
if errors.As(err, &composeErr) { if errors.As(err, &composeErr) {
@ -120,7 +119,7 @@ func (o *projectOptions) WithServices(fn ProjectServicesFunc) func(cmd *cobra.Co
if s.Labels == nil { if s.Labels == nil {
s.Labels = make(map[string]string) s.Labels = make(map[string]string)
} }
s.Labels[compose.EnvironmentFileLabel] = ef s.Labels[api.EnvironmentFileLabel] = ef
services = append(services, s) services = append(services, s)
} }
} }
@ -156,12 +155,12 @@ func (o *projectOptions) toProjectName() (string, error) {
func (o *projectOptions) toProject(services []string, po ...cli.ProjectOptionsFn) (*types.Project, error) { func (o *projectOptions) toProject(services []string, po ...cli.ProjectOptionsFn) (*types.Project, error) {
options, err := o.toProjectOptions(po...) options, err := o.toProjectOptions(po...)
if err != nil { if err != nil {
return nil, metrics.WrapComposeError(err) return nil, compose.WrapComposeError(err)
} }
project, err := cli.ProjectFromOptions(options) project, err := cli.ProjectFromOptions(options)
if err != nil { if err != nil {
return nil, metrics.WrapComposeError(err) return nil, compose.WrapComposeError(err)
} }
if len(services) > 0 { if len(services) > 0 {
@ -195,7 +194,7 @@ func (o *projectOptions) toProjectOptions(po ...cli.ProjectOptionsFn) (*cli.Proj
} }
// RootCommand returns the compose command with its child commands // RootCommand returns the compose command with its child commands
func RootCommand(contextType string, backend compose.Service) *cobra.Command { func RootCommand(contextType string, backend api.Service) *cobra.Command {
opts := projectOptions{} opts := projectOptions{}
var ansi string var ansi string
var noAnsi bool var noAnsi bool
@ -210,7 +209,7 @@ func RootCommand(contextType string, backend compose.Service) *cobra.Command {
} }
_ = cmd.Help() _ = cmd.Help()
return dockercli.StatusError{ return dockercli.StatusError{
StatusCode: metrics.CommandSyntaxFailure.ExitCode, StatusCode: compose.CommandSyntaxFailure.ExitCode,
Status: fmt.Sprintf("unknown docker command: %q", "compose "+args[0]), Status: fmt.Sprintf("unknown docker command: %q", "compose "+args[0]),
} }
}, },

View File

@ -32,8 +32,8 @@ import (
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/utils" "github.com/docker/compose-cli/pkg/compose"
) )
type convertOptions struct { type convertOptions struct {
@ -51,7 +51,7 @@ type convertOptions struct {
var addFlagsFuncs []func(cmd *cobra.Command, opts *convertOptions) var addFlagsFuncs []func(cmd *cobra.Command, opts *convertOptions)
func convertCommand(p *projectOptions, backend compose.Service) *cobra.Command { func convertCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := convertOptions{ opts := convertOptions{
projectOptions: p, projectOptions: p,
} }
@ -104,7 +104,7 @@ func convertCommand(p *projectOptions, backend compose.Service) *cobra.Command {
return cmd return cmd
} }
func runConvert(ctx context.Context, backend compose.Service, opts convertOptions, services []string) error { func runConvert(ctx context.Context, backend api.Service, opts convertOptions, services []string) error {
var json []byte var json []byte
project, err := opts.toProject(services, cli.WithInterpolation(!opts.noInterpolate)) project, err := opts.toProject(services, cli.WithInterpolation(!opts.noInterpolate))
if err != nil { if err != nil {
@ -124,7 +124,7 @@ func runConvert(ctx context.Context, backend compose.Service, opts convertOption
} }
} }
json, err = backend.Convert(ctx, project, compose.ConvertOptions{ json, err = backend.Convert(ctx, project, api.ConvertOptions{
Format: opts.Format, Format: opts.Format,
Output: opts.Output, Output: opts.Output,
}) })
@ -180,7 +180,7 @@ func runHash(opts convertOptions) error {
return err return err
} }
for _, s := range project.Services { for _, s := range project.Services {
hash, err := utils.ServiceHash(s) hash, err := compose.ServiceHash(s)
if err != nil { if err != nil {
return err return err
} }

View File

@ -23,7 +23,7 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
) )
type copyOptions struct { type copyOptions struct {
@ -37,7 +37,7 @@ type copyOptions struct {
copyUIDGID bool copyUIDGID bool
} }
func copyCommand(p *projectOptions, backend compose.Service) *cobra.Command { func copyCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := copyOptions{ opts := copyOptions{
projectOptions: p, projectOptions: p,
} }
@ -71,13 +71,13 @@ func copyCommand(p *projectOptions, backend compose.Service) *cobra.Command {
return copyCmd return copyCmd
} }
func runCopy(ctx context.Context, backend compose.Service, opts copyOptions) error { func runCopy(ctx context.Context, backend api.Service, opts copyOptions) error {
projects, err := opts.toProject(nil) projects, err := opts.toProject(nil)
if err != nil { if err != nil {
return err return err
} }
return backend.Copy(ctx, projects, compose.CopyOptions{ return backend.Copy(ctx, projects, api.CopyOptions{
Source: opts.source, Source: opts.source,
Destination: opts.destination, Destination: opts.destination,
All: opts.all, All: opts.all,

View File

@ -24,7 +24,7 @@ import (
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/types"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
) )
type createOptions struct { type createOptions struct {
@ -40,7 +40,7 @@ type createOptions struct {
quietPull bool quietPull bool
} }
func createCommand(p *projectOptions, backend compose.Service) *cobra.Command { func createCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := createOptions{} opts := createOptions{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "create [SERVICE...]", Use: "create [SERVICE...]",
@ -55,7 +55,7 @@ func createCommand(p *projectOptions, backend compose.Service) *cobra.Command {
return nil return nil
}), }),
RunE: p.WithProject(func(ctx context.Context, project *types.Project) error { RunE: p.WithProject(func(ctx context.Context, project *types.Project) error {
return backend.Create(ctx, project, compose.CreateOptions{ return backend.Create(ctx, project, api.CreateOptions{
RemoveOrphans: opts.removeOrphans, RemoveOrphans: opts.removeOrphans,
Recreate: opts.recreateStrategy(), Recreate: opts.recreateStrategy(),
RecreateDependencies: opts.dependenciesRecreateStrategy(), RecreateDependencies: opts.dependenciesRecreateStrategy(),
@ -75,22 +75,22 @@ func createCommand(p *projectOptions, backend compose.Service) *cobra.Command {
func (opts createOptions) recreateStrategy() string { func (opts createOptions) recreateStrategy() string {
if opts.noRecreate { if opts.noRecreate {
return compose.RecreateNever return api.RecreateNever
} }
if opts.forceRecreate { if opts.forceRecreate {
return compose.RecreateForce return api.RecreateForce
} }
return compose.RecreateDiverged return api.RecreateDiverged
} }
func (opts createOptions) dependenciesRecreateStrategy() string { func (opts createOptions) dependenciesRecreateStrategy() string {
if opts.noRecreate { if opts.noRecreate {
return compose.RecreateNever return api.RecreateNever
} }
if opts.recreateDeps { if opts.recreateDeps {
return compose.RecreateForce return api.RecreateForce
} }
return compose.RecreateDiverged return api.RecreateDiverged
} }
func (opts createOptions) GetTimeout() *time.Duration { func (opts createOptions) GetTimeout() *time.Duration {

View File

@ -24,7 +24,7 @@ import (
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/types"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
) )
type downOptions struct { type downOptions struct {
@ -36,7 +36,7 @@ type downOptions struct {
images string images string
} }
func downCommand(p *projectOptions, backend compose.Service) *cobra.Command { func downCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := downOptions{ opts := downOptions{
projectOptions: p, projectOptions: p,
} }
@ -66,7 +66,7 @@ func downCommand(p *projectOptions, backend compose.Service) *cobra.Command {
return downCmd return downCmd
} }
func runDown(ctx context.Context, backend compose.Service, opts downOptions) error { func runDown(ctx context.Context, backend api.Service, opts downOptions) error {
name := opts.ProjectName name := opts.ProjectName
var project *types.Project var project *types.Project
if opts.ProjectName == "" { if opts.ProjectName == "" {
@ -83,7 +83,7 @@ func runDown(ctx context.Context, backend compose.Service, opts downOptions) err
timeoutValue := time.Duration(opts.timeout) * time.Second timeoutValue := time.Duration(opts.timeout) * time.Second
timeout = &timeoutValue timeout = &timeoutValue
} }
return backend.Down(ctx, name, compose.DownOptions{ return backend.Down(ctx, name, api.DownOptions{
RemoveOrphans: opts.removeOrphans, RemoveOrphans: opts.removeOrphans,
Project: project, Project: project,
Timeout: timeout, Timeout: timeout,

View File

@ -21,7 +21,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -31,7 +31,7 @@ type eventsOpts struct {
json bool json bool
} }
func eventsCommand(p *projectOptions, backend compose.Service) *cobra.Command { func eventsCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := eventsOpts{ opts := eventsOpts{
composeOptions: &composeOptions{ composeOptions: &composeOptions{
projectOptions: p, projectOptions: p,
@ -49,15 +49,15 @@ func eventsCommand(p *projectOptions, backend compose.Service) *cobra.Command {
return cmd return cmd
} }
func runEvents(ctx context.Context, backend compose.Service, opts eventsOpts, services []string) error { func runEvents(ctx context.Context, backend api.Service, opts eventsOpts, services []string) error {
project, err := opts.toProjectName() project, err := opts.toProjectName()
if err != nil { if err != nil {
return err return err
} }
return backend.Events(ctx, project, compose.EventsOptions{ return backend.Events(ctx, project, api.EventsOptions{
Services: services, Services: services,
Consumer: func(event compose.Event) error { Consumer: func(event api.Event) error {
if opts.json { if opts.json {
marshal, err := json.Marshal(map[string]interface{}{ marshal, err := json.Marshal(map[string]interface{}{
"time": event.Timestamp, "time": event.Timestamp,

View File

@ -25,7 +25,7 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
) )
type execOpts struct { type execOpts struct {
@ -43,7 +43,7 @@ type execOpts struct {
privileged bool privileged bool
} }
func execCommand(p *projectOptions, backend compose.Service) *cobra.Command { func execCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := execOpts{ opts := execOpts{
composeOptions: &composeOptions{ composeOptions: &composeOptions{
projectOptions: p, projectOptions: p,
@ -75,13 +75,13 @@ func execCommand(p *projectOptions, backend compose.Service) *cobra.Command {
return runCmd return runCmd
} }
func runExec(ctx context.Context, backend compose.Service, opts execOpts) error { func runExec(ctx context.Context, backend api.Service, opts execOpts) error {
project, err := opts.toProject(nil) project, err := opts.toProject(nil)
if err != nil { if err != nil {
return err return err
} }
execOpts := compose.RunOptions{ execOpts := api.RunOptions{
Service: opts.service, Service: opts.service,
Command: opts.command, Command: opts.command,
Environment: opts.environment, Environment: opts.environment,

View File

@ -24,14 +24,13 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/go-units"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/cli/formatter"
"github.com/docker/compose-cli/utils" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/docker/pkg/stringid" "github.com/docker/compose-cli/pkg/utils"
"github.com/docker/go-units"
) )
type imageOptions struct { type imageOptions struct {
@ -39,7 +38,7 @@ type imageOptions struct {
Quiet bool Quiet bool
} }
func imagesCommand(p *projectOptions, backend compose.Service) *cobra.Command { func imagesCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := imageOptions{ opts := imageOptions{
projectOptions: p, projectOptions: p,
} }
@ -54,13 +53,13 @@ func imagesCommand(p *projectOptions, backend compose.Service) *cobra.Command {
return imgCmd return imgCmd
} }
func runImages(ctx context.Context, backend compose.Service, opts imageOptions, services []string) error { func runImages(ctx context.Context, backend api.Service, opts imageOptions, services []string) error {
projectName, err := opts.toProjectName() projectName, err := opts.toProjectName()
if err != nil { if err != nil {
return err return err
} }
images, err := backend.Images(ctx, projectName, compose.ImagesOptions{ images, err := backend.Images(ctx, projectName, api.ImagesOptions{
Services: services, Services: services,
}) })
if err != nil { if err != nil {

View File

@ -22,11 +22,11 @@ import (
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/types"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
) )
func killCommand(p *projectOptions, backend compose.Service) *cobra.Command { func killCommand(p *projectOptions, backend api.Service) *cobra.Command {
var opts compose.KillOptions var opts api.KillOptions
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "kill [options] [SERVICE...]", Use: "kill [options] [SERVICE...]",
Short: "Force stop service containers.", Short: "Force stop service containers.",

View File

@ -26,9 +26,9 @@ import (
"github.com/docker/cli/opts" "github.com/docker/cli/opts"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/cli/formatter"
"github.com/docker/compose-cli/pkg/api"
) )
type lsOptions struct { type lsOptions struct {
@ -38,7 +38,7 @@ type lsOptions struct {
Filter opts.FilterOpt Filter opts.FilterOpt
} }
func listCommand(contextType string, backend compose.Service) *cobra.Command { func listCommand(contextType string, backend api.Service) *cobra.Command {
opts := lsOptions{Filter: opts.NewFilterOpt()} opts := lsOptions{Filter: opts.NewFilterOpt()}
lsCmd := &cobra.Command{ lsCmd := &cobra.Command{
Use: "ls", Use: "ls",
@ -61,14 +61,14 @@ var acceptedListFilters = map[string]bool{
"name": true, "name": true,
} }
func runList(ctx context.Context, backend compose.Service, opts lsOptions) error { func runList(ctx context.Context, backend api.Service, opts lsOptions) error {
filters := opts.Filter.Value() filters := opts.Filter.Value()
err := filters.Validate(acceptedListFilters) err := filters.Validate(acceptedListFilters)
if err != nil { if err != nil {
return err return err
} }
stackList, err := backend.List(ctx, compose.ListOptions{All: opts.All}) stackList, err := backend.List(ctx, api.ListOptions{All: opts.All})
if err != nil { if err != nil {
return err return err
} }
@ -80,7 +80,7 @@ func runList(ctx context.Context, backend compose.Service, opts lsOptions) error
} }
if filters.Len() > 0 { if filters.Len() > 0 {
var filtered []compose.Stack var filtered []api.Stack
for _, s := range stackList { for _, s := range stackList {
if filters.Contains("name") && !filters.Match("name", s.Name) { if filters.Contains("name") && !filters.Match("name", s.Name) {
continue continue
@ -103,7 +103,7 @@ type stackView struct {
Status string Status string
} }
func viewFromStackList(stackList []compose.Stack) []stackView { func viewFromStackList(stackList []api.Stack) []stackView {
retList := make([]stackView, len(stackList)) retList := make([]stackView, len(stackList))
for i, s := range stackList { for i, s := range stackList {
retList[i] = stackView{ retList[i] = stackView{

View File

@ -22,9 +22,9 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/cli/formatter"
"github.com/docker/compose-cli/pkg/api"
) )
type logsOptions struct { type logsOptions struct {
@ -39,7 +39,7 @@ type logsOptions struct {
timestamps bool timestamps bool
} }
func logsCommand(p *projectOptions, contextType string, backend compose.Service) *cobra.Command { func logsCommand(p *projectOptions, contextType string, backend api.Service) *cobra.Command {
opts := logsOptions{ opts := logsOptions{
projectOptions: p, projectOptions: p,
} }
@ -64,13 +64,13 @@ func logsCommand(p *projectOptions, contextType string, backend compose.Service)
return logsCmd return logsCmd
} }
func runLogs(ctx context.Context, backend compose.Service, opts logsOptions, services []string) error { func runLogs(ctx context.Context, backend api.Service, opts logsOptions, services []string) error {
projectName, err := opts.toProjectName() projectName, err := opts.toProjectName()
if err != nil { if err != nil {
return err return err
} }
consumer := formatter.NewLogConsumer(ctx, os.Stdout, !opts.noColor, !opts.noPrefix) consumer := formatter.NewLogConsumer(ctx, os.Stdout, !opts.noColor, !opts.noPrefix)
return backend.Logs(ctx, projectName, consumer, compose.LogOptions{ return backend.Logs(ctx, projectName, consumer, api.LogOptions{
Services: services, Services: services,
Follow: opts.follow, Follow: opts.follow,
Tail: opts.tail, Tail: opts.tail,

View File

@ -21,14 +21,14 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
) )
type pauseOptions struct { type pauseOptions struct {
*projectOptions *projectOptions
} }
func pauseCommand(p *projectOptions, backend compose.Service) *cobra.Command { func pauseCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := pauseOptions{ opts := pauseOptions{
projectOptions: p, projectOptions: p,
} }
@ -42,13 +42,13 @@ func pauseCommand(p *projectOptions, backend compose.Service) *cobra.Command {
return cmd return cmd
} }
func runPause(ctx context.Context, backend compose.Service, opts pauseOptions, services []string) error { func runPause(ctx context.Context, backend api.Service, opts pauseOptions, services []string) error {
project, err := opts.toProjectName() project, err := opts.toProjectName()
if err != nil { if err != nil {
return err return err
} }
return backend.Pause(ctx, project, compose.PauseOptions{ return backend.Pause(ctx, project, api.PauseOptions{
Services: services, Services: services,
}) })
} }
@ -57,7 +57,7 @@ type unpauseOptions struct {
*projectOptions *projectOptions
} }
func unpauseCommand(p *projectOptions, backend compose.Service) *cobra.Command { func unpauseCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := unpauseOptions{ opts := unpauseOptions{
projectOptions: p, projectOptions: p,
} }
@ -71,13 +71,13 @@ func unpauseCommand(p *projectOptions, backend compose.Service) *cobra.Command {
return cmd return cmd
} }
func runUnPause(ctx context.Context, backend compose.Service, opts unpauseOptions, services []string) error { func runUnPause(ctx context.Context, backend api.Service, opts unpauseOptions, services []string) error {
project, err := opts.toProjectName() project, err := opts.toProjectName()
if err != nil { if err != nil {
return err return err
} }
return backend.UnPause(ctx, project, compose.PauseOptions{ return backend.UnPause(ctx, project, api.PauseOptions{
Services: services, Services: services,
}) })
} }

View File

@ -23,7 +23,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
) )
type portOptions struct { type portOptions struct {
@ -33,7 +33,7 @@ type portOptions struct {
index int index int
} }
func portCommand(p *projectOptions, backend compose.Service) *cobra.Command { func portCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := portOptions{ opts := portOptions{
projectOptions: p, projectOptions: p,
} }
@ -58,12 +58,12 @@ func portCommand(p *projectOptions, backend compose.Service) *cobra.Command {
return cmd return cmd
} }
func runPort(ctx context.Context, backend compose.Service, opts portOptions, service string) error { func runPort(ctx context.Context, backend api.Service, opts portOptions, service string) error {
projectName, err := opts.toProjectName() projectName, err := opts.toProjectName()
if err != nil { if err != nil {
return err return err
} }
ip, port, err := backend.Port(ctx, projectName, service, opts.port, compose.PortOptions{ ip, port, err := backend.Port(ctx, projectName, service, opts.port, api.PortOptions{
Protocol: opts.protocol, Protocol: opts.protocol,
Index: opts.index, Index: opts.index,
}) })

View File

@ -26,9 +26,9 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/cli/formatter"
"github.com/docker/compose-cli/utils" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/pkg/utils"
) )
type psOptions struct { type psOptions struct {
@ -39,7 +39,7 @@ type psOptions struct {
Services bool Services bool
} }
func psCommand(p *projectOptions, backend compose.Service) *cobra.Command { func psCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := psOptions{ opts := psOptions{
projectOptions: p, projectOptions: p,
} }
@ -57,12 +57,12 @@ func psCommand(p *projectOptions, backend compose.Service) *cobra.Command {
return psCmd return psCmd
} }
func runPs(ctx context.Context, backend compose.Service, services []string, opts psOptions) error { func runPs(ctx context.Context, backend api.Service, services []string, opts psOptions) error {
projectName, err := opts.toProjectName() projectName, err := opts.toProjectName()
if err != nil { if err != nil {
return err return err
} }
containers, err := backend.Ps(ctx, projectName, compose.PsOptions{ containers, err := backend.Ps(ctx, projectName, api.PsOptions{
All: opts.All, All: opts.All,
Services: services, Services: services,
}) })

View File

@ -24,8 +24,8 @@ import (
"github.com/morikuni/aec" "github.com/morikuni/aec"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/utils" "github.com/docker/compose-cli/pkg/utils"
) )
type pullOptions struct { type pullOptions struct {
@ -38,7 +38,7 @@ type pullOptions struct {
ignorePullFailures bool ignorePullFailures bool
} }
func pullCommand(p *projectOptions, backend compose.Service) *cobra.Command { func pullCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := pullOptions{ opts := pullOptions{
projectOptions: p, projectOptions: p,
} }
@ -66,7 +66,7 @@ func pullCommand(p *projectOptions, backend compose.Service) *cobra.Command {
return cmd return cmd
} }
func runPull(ctx context.Context, backend compose.Service, opts pullOptions, services []string) error { func runPull(ctx context.Context, backend api.Service, opts pullOptions, services []string) error {
project, err := opts.toProject(services) project, err := opts.toProject(services)
if err != nil { if err != nil {
return err return err
@ -85,7 +85,7 @@ func runPull(ctx context.Context, backend compose.Service, opts pullOptions, ser
project.Services = enabled project.Services = enabled
} }
return backend.Pull(ctx, project, compose.PullOptions{ return backend.Pull(ctx, project, api.PullOptions{
Quiet: opts.quiet, Quiet: opts.quiet,
IgnoreFailures: opts.ignorePullFailures, IgnoreFailures: opts.ignorePullFailures,
}) })

View File

@ -21,7 +21,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
) )
type pushOptions struct { type pushOptions struct {
@ -31,7 +31,7 @@ type pushOptions struct {
Ignorefailures bool Ignorefailures bool
} }
func pushCommand(p *projectOptions, backend compose.Service) *cobra.Command { func pushCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := pushOptions{ opts := pushOptions{
projectOptions: p, projectOptions: p,
} }
@ -47,13 +47,13 @@ func pushCommand(p *projectOptions, backend compose.Service) *cobra.Command {
return pushCmd return pushCmd
} }
func runPush(ctx context.Context, backend compose.Service, opts pushOptions, services []string) error { func runPush(ctx context.Context, backend api.Service, opts pushOptions, services []string) error {
project, err := opts.toProject(services) project, err := opts.toProject(services)
if err != nil { if err != nil {
return err return err
} }
return backend.Push(ctx, project, compose.PushOptions{ return backend.Push(ctx, project, api.PushOptions{
IgnoreFailures: opts.Ignorefailures, IgnoreFailures: opts.Ignorefailures,
}) })
} }

View File

@ -19,7 +19,7 @@ package compose
import ( import (
"context" "context"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -30,7 +30,7 @@ type removeOptions struct {
volumes bool volumes bool
} }
func removeCommand(p *projectOptions, backend compose.Service) *cobra.Command { func removeCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := removeOptions{ opts := removeOptions{
projectOptions: p, projectOptions: p,
} }
@ -57,19 +57,19 @@ Any data which is not in a volume will be lost.`,
return cmd return cmd
} }
func runRemove(ctx context.Context, backend compose.Service, opts removeOptions, services []string) error { func runRemove(ctx context.Context, backend api.Service, opts removeOptions, services []string) error {
project, err := opts.toProject(services) project, err := opts.toProject(services)
if err != nil { if err != nil {
return err return err
} }
if opts.stop { if opts.stop {
return backend.Stop(ctx, project, compose.StopOptions{ return backend.Stop(ctx, project, api.StopOptions{
Services: services, Services: services,
}) })
} }
return backend.Remove(ctx, project, compose.RemoveOptions{ return backend.Remove(ctx, project, api.RemoveOptions{
Services: services, Services: services,
}) })
} }

View File

@ -22,7 +22,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
) )
type restartOptions struct { type restartOptions struct {
@ -30,7 +30,7 @@ type restartOptions struct {
timeout int timeout int
} }
func restartCommand(p *projectOptions, backend compose.Service) *cobra.Command { func restartCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := restartOptions{ opts := restartOptions{
projectOptions: p, projectOptions: p,
} }
@ -47,14 +47,14 @@ func restartCommand(p *projectOptions, backend compose.Service) *cobra.Command {
return restartCmd return restartCmd
} }
func runRestart(ctx context.Context, backend compose.Service, opts restartOptions, services []string) error { func runRestart(ctx context.Context, backend api.Service, opts restartOptions, services []string) error {
project, err := opts.toProject(services) project, err := opts.toProject(services)
if err != nil { if err != nil {
return err return err
} }
timeout := time.Duration(opts.timeout) * time.Second timeout := time.Duration(opts.timeout) * time.Second
return backend.Restart(ctx, project, compose.RestartOptions{ return backend.Restart(ctx, project, api.RestartOptions{
Timeout: &timeout, Timeout: &timeout,
Services: services, Services: services,
}) })

View File

@ -29,8 +29,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/api/progress" "github.com/docker/compose-cli/pkg/progress"
) )
type runOptions struct { type runOptions struct {
@ -100,7 +100,7 @@ func (opts runOptions) apply(project *types.Project) error {
return nil return nil
} }
func runCommand(p *projectOptions, backend compose.Service) *cobra.Command { func runCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := runOptions{ opts := runOptions{
composeOptions: &composeOptions{ composeOptions: &composeOptions{
projectOptions: p, projectOptions: p,
@ -152,7 +152,7 @@ func notAtTTY() bool {
return !isatty.IsTerminal(os.Stdout.Fd()) return !isatty.IsTerminal(os.Stdout.Fd())
} }
func runRun(ctx context.Context, backend compose.Service, project *types.Project, opts runOptions) error { func runRun(ctx context.Context, backend api.Service, project *types.Project, opts runOptions) error {
err := opts.apply(project) err := opts.apply(project)
if err != nil { if err != nil {
return err return err
@ -183,7 +183,7 @@ func runRun(ctx context.Context, backend compose.Service, project *types.Project
} }
// start container and attach to container streams // start container and attach to container streams
runOpts := compose.RunOptions{ runOpts := api.RunOptions{
Name: opts.name, Name: opts.name,
Service: opts.Service, Service: opts.Service,
Command: opts.Command, Command: opts.Command,
@ -211,7 +211,7 @@ func runRun(ctx context.Context, backend compose.Service, project *types.Project
return err return err
} }
func startDependencies(ctx context.Context, backend compose.Service, project types.Project, requestedServiceName string) error { func startDependencies(ctx context.Context, backend api.Service, project types.Project, requestedServiceName string) error {
dependencies := types.Services{} dependencies := types.Services{}
var requestedService types.ServiceConfig var requestedService types.ServiceConfig
for _, service := range project.Services { for _, service := range project.Services {
@ -224,8 +224,8 @@ func startDependencies(ctx context.Context, backend compose.Service, project typ
project.Services = dependencies project.Services = dependencies
project.DisabledServices = append(project.DisabledServices, requestedService) project.DisabledServices = append(project.DisabledServices, requestedService)
if err := backend.Create(ctx, &project, compose.CreateOptions{}); err != nil { if err := backend.Create(ctx, &project, api.CreateOptions{}); err != nil {
return err return err
} }
return backend.Start(ctx, &project, compose.StartOptions{}) return backend.Start(ctx, &project, api.StartOptions{})
} }

View File

@ -19,7 +19,7 @@ package compose
import ( import (
"context" "context"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -27,7 +27,7 @@ type startOptions struct {
*projectOptions *projectOptions
} }
func startCommand(p *projectOptions, backend compose.Service) *cobra.Command { func startCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := startOptions{ opts := startOptions{
projectOptions: p, projectOptions: p,
} }
@ -41,11 +41,11 @@ func startCommand(p *projectOptions, backend compose.Service) *cobra.Command {
return startCmd return startCmd
} }
func runStart(ctx context.Context, backend compose.Service, opts startOptions, services []string) error { func runStart(ctx context.Context, backend api.Service, opts startOptions, services []string) error {
project, err := opts.toProject(services) project, err := opts.toProject(services)
if err != nil { if err != nil {
return err return err
} }
return backend.Start(ctx, project, compose.StartOptions{}) return backend.Start(ctx, project, api.StartOptions{})
} }

View File

@ -22,7 +22,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
) )
type stopOptions struct { type stopOptions struct {
@ -31,7 +31,7 @@ type stopOptions struct {
timeout int timeout int
} }
func stopCommand(p *projectOptions, backend compose.Service) *cobra.Command { func stopCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := stopOptions{ opts := stopOptions{
projectOptions: p, projectOptions: p,
} }
@ -51,7 +51,7 @@ func stopCommand(p *projectOptions, backend compose.Service) *cobra.Command {
return cmd return cmd
} }
func runStop(ctx context.Context, backend compose.Service, opts stopOptions, services []string) error { func runStop(ctx context.Context, backend api.Service, opts stopOptions, services []string) error {
project, err := opts.toProject(services) project, err := opts.toProject(services)
if err != nil { if err != nil {
return err return err
@ -62,7 +62,7 @@ func runStop(ctx context.Context, backend compose.Service, opts stopOptions, ser
timeoutValue := time.Duration(opts.timeout) * time.Second timeoutValue := time.Duration(opts.timeout) * time.Second
timeout = &timeoutValue timeout = &timeoutValue
} }
return backend.Stop(ctx, project, compose.StopOptions{ return backend.Stop(ctx, project, api.StopOptions{
Timeout: timeout, Timeout: timeout,
Services: services, Services: services,
}) })

View File

@ -27,14 +27,14 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
) )
type topOptions struct { type topOptions struct {
*projectOptions *projectOptions
} }
func topCommand(p *projectOptions, backend compose.Service) *cobra.Command { func topCommand(p *projectOptions, backend api.Service) *cobra.Command {
opts := topOptions{ opts := topOptions{
projectOptions: p, projectOptions: p,
} }
@ -48,7 +48,7 @@ func topCommand(p *projectOptions, backend compose.Service) *cobra.Command {
return topCmd return topCmd
} }
func runTop(ctx context.Context, backend compose.Service, opts topOptions, services []string) error { func runTop(ctx context.Context, backend api.Service, opts topOptions, services []string) error {
projectName, err := opts.toProjectName() projectName, err := opts.toProjectName()
if err != nil { if err != nil {
return err return err

View File

@ -24,10 +24,11 @@ import (
"strings" "strings"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/types"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/cli/formatter"
"github.com/docker/compose-cli/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/cli/formatter"
"github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/pkg/utils"
) )
// composeOptions hold options common to `up` and `run` to run compose project // composeOptions hold options common to `up` and `run` to run compose project
@ -89,7 +90,7 @@ func (opts upOptions) apply(project *types.Project, services []string) error {
return nil return nil
} }
func upCommand(p *projectOptions, backend compose.Service) *cobra.Command { func upCommand(p *projectOptions, backend api.Service) *cobra.Command {
up := upOptions{} up := upOptions{}
create := createOptions{} create := createOptions{}
upCmd := &cobra.Command{ upCmd := &cobra.Command{
@ -144,7 +145,7 @@ func upCommand(p *projectOptions, backend compose.Service) *cobra.Command {
return upCmd return upCmd
} }
func runUp(ctx context.Context, backend compose.Service, createOptions createOptions, upOptions upOptions, project *types.Project, services []string) error { func runUp(ctx context.Context, backend api.Service, createOptions createOptions, upOptions upOptions, project *types.Project, services []string) error {
if len(project.Services) == 0 { if len(project.Services) == 0 {
return fmt.Errorf("no service selected") return fmt.Errorf("no service selected")
} }
@ -156,7 +157,7 @@ func runUp(ctx context.Context, backend compose.Service, createOptions createOpt
return err return err
} }
var consumer compose.LogConsumer var consumer api.LogConsumer
if !upOptions.Detach { if !upOptions.Detach {
consumer = formatter.NewLogConsumer(ctx, os.Stdout, !upOptions.noColor, !upOptions.noPrefix) consumer = formatter.NewLogConsumer(ctx, os.Stdout, !upOptions.noColor, !upOptions.noPrefix)
} }
@ -166,7 +167,7 @@ func runUp(ctx context.Context, backend compose.Service, createOptions createOpt
attachTo = project.ServiceNames() attachTo = project.ServiceNames()
} }
create := compose.CreateOptions{ create := api.CreateOptions{
RemoveOrphans: createOptions.removeOrphans, RemoveOrphans: createOptions.removeOrphans,
Recreate: createOptions.recreateStrategy(), Recreate: createOptions.recreateStrategy(),
RecreateDependencies: createOptions.dependenciesRecreateStrategy(), RecreateDependencies: createOptions.dependenciesRecreateStrategy(),
@ -179,9 +180,9 @@ func runUp(ctx context.Context, backend compose.Service, createOptions createOpt
return backend.Create(ctx, project, create) return backend.Create(ctx, project, create)
} }
return backend.Up(ctx, project, compose.UpOptions{ return backend.Up(ctx, project, api.UpOptions{
Create: create, Create: create,
Start: compose.StartOptions{ Start: api.StartOptions{
Attach: consumer, Attach: consumer,
AttachTo: attachTo, AttachTo: attachTo,
ExitCodeFrom: upOptions.exitCodeFrom, ExitCodeFrom: upOptions.exitCodeFrom,

View File

@ -25,24 +25,23 @@ import (
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/spf13/cobra" "github.com/spf13/cobra"
api "github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/cli/cmd/compose" commands "github.com/docker/compose-cli/cmd/compose"
"github.com/docker/compose-cli/cli/metrics"
"github.com/docker/compose-cli/internal" "github.com/docker/compose-cli/internal"
impl "github.com/docker/compose-cli/local/compose" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/pkg/compose"
) )
func main() { func main() {
plugin.Run(func(dockerCli command.Cli) *cobra.Command { plugin.Run(func(dockerCli command.Cli) *cobra.Command {
lazyInit := api.NewServiceProxy() lazyInit := api.NewServiceProxy()
cmd := compose.RootCommand(store.DefaultContextType, lazyInit) cmd := commands.RootCommand(store.DefaultContextType, lazyInit)
originalPreRun := cmd.PersistentPreRunE originalPreRun := cmd.PersistentPreRunE
cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error { cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
if err := plugin.PersistentPreRunE(cmd, args); err != nil { if err := plugin.PersistentPreRunE(cmd, args); err != nil {
return err return err
} }
lazyInit.WithService(impl.NewComposeService(dockerCli.Client(), dockerCli.ConfigFile())) lazyInit.WithService(compose.NewComposeService(dockerCli.Client(), dockerCli.ConfigFile()))
if originalPreRun != nil { if originalPreRun != nil {
return originalPreRun(cmd, args) return originalPreRun(cmd, args)
} }
@ -50,7 +49,7 @@ func main() {
} }
cmd.SetFlagErrorFunc(func(c *cobra.Command, err error) error { cmd.SetFlagErrorFunc(func(c *cobra.Command, err error) error {
return dockercli.StatusError{ return dockercli.StatusError{
StatusCode: metrics.CommandSyntaxFailure.ExitCode, StatusCode: compose.CommandSyntaxFailure.ExitCode,
Status: err.Error(), Status: err.Error(),
} }
}) })

View File

@ -27,7 +27,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"github.com/docker/compose-cli/cli/cmd/compose" "github.com/docker/compose-cli/cmd/compose"
. "github.com/docker/compose-cli/docs/yaml" . "github.com/docker/compose-cli/docs/yaml"
) )

View File

@ -22,8 +22,8 @@ import (
"github.com/aws/aws-sdk-go/service/cloudformation" "github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go/service/ecs" "github.com/aws/aws-sdk-go/service/ecs"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/secrets" "github.com/docker/compose-cli/api/secrets"
"github.com/docker/compose-cli/pkg/api"
) )
const ( const (
@ -49,7 +49,7 @@ type API interface {
UpdateStack(ctx context.Context, changeset string) error UpdateStack(ctx context.Context, changeset string) error
WaitStackComplete(ctx context.Context, name string, operation int) error WaitStackComplete(ctx context.Context, name string, operation int) error
GetStackID(ctx context.Context, name string) (string, error) GetStackID(ctx context.Context, name string) (string, error)
ListStacks(ctx context.Context) ([]compose.Stack, error) ListStacks(ctx context.Context) ([]api.Stack, error)
GetStackClusterID(ctx context.Context, stack string) (string, error) GetStackClusterID(ctx context.Context, stack string) (string, error)
GetServiceTaskDefinition(ctx context.Context, cluster string, serviceArns []string) (map[string]string, error) GetServiceTaskDefinition(ctx context.Context, cluster string, serviceArns []string) (map[string]string, error)
ListStackServices(ctx context.Context, stack string) ([]string, error) ListStackServices(ctx context.Context, stack string) ([]string, error)
@ -64,9 +64,9 @@ type API interface {
ListSecrets(ctx context.Context) ([]secrets.Secret, error) ListSecrets(ctx context.Context) ([]secrets.Secret, error)
DeleteSecret(ctx context.Context, id string, recover bool) error DeleteSecret(ctx context.Context, id string, recover bool) error
GetLogs(ctx context.Context, name string, consumer func(container string, service string, message string), follow bool) error GetLogs(ctx context.Context, name string, consumer func(container string, service string, message string), follow bool) error
DescribeService(ctx context.Context, cluster string, arn string) (compose.ServiceStatus, error) DescribeService(ctx context.Context, cluster string, arn string) (api.ServiceStatus, error)
DescribeServiceTasks(ctx context.Context, cluster string, project string, service string) ([]compose.ContainerSummary, error) DescribeServiceTasks(ctx context.Context, cluster string, project string, service string) ([]api.ContainerSummary, error)
getURLWithPortMapping(ctx context.Context, targetGroupArns []string) ([]compose.PortPublisher, error) getURLWithPortMapping(ctx context.Context, targetGroupArns []string) ([]api.PortPublisher, error)
ListTasks(ctx context.Context, cluster string, family string) ([]string, error) ListTasks(ctx context.Context, cluster string, family string) ([]string, error)
GetPublicIPs(ctx context.Context, interfaces ...string) (map[string]string, error) GetPublicIPs(ctx context.Context, interfaces ...string) (map[string]string, error)
ResolveLoadBalancer(ctx context.Context, nameOrArn string) (awsResource, string, string, []awsResource, error) ResolveLoadBalancer(ctx context.Context, nameOrArn string) (awsResource, string, string, []awsResource, error)

View File

@ -22,9 +22,6 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/errdefs"
"github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/elbv2" "github.com/aws/aws-sdk-go/service/elbv2"
"github.com/awslabs/goformation/v4/cloudformation" "github.com/awslabs/goformation/v4/cloudformation"
@ -33,6 +30,7 @@ import (
"github.com/awslabs/goformation/v4/cloudformation/efs" "github.com/awslabs/goformation/v4/cloudformation/efs"
"github.com/awslabs/goformation/v4/cloudformation/elasticloadbalancingv2" "github.com/awslabs/goformation/v4/cloudformation/elasticloadbalancingv2"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/types"
"github.com/docker/compose-cli/pkg/api"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -156,7 +154,7 @@ func (b *ecsAPIService) parseClusterExtension(ctx context.Context, project *type
return nil, err return nil, err
} }
if !ok { if !ok {
return nil, errors.Wrapf(errdefs.ErrNotFound, "cluster %q does not exist", cluster) return nil, errors.Wrapf(api.ErrNotFound, "cluster %q does not exist", cluster)
} }
template.Metadata["Cluster"] = cluster.ARN() template.Metadata["Cluster"] = cluster.ARN()
@ -268,7 +266,7 @@ func (b *ecsAPIService) parseExternalNetworks(ctx context.Context, project *type
return nil, err return nil, err
} }
if !exists { if !exists {
return nil, errors.Wrapf(errdefs.ErrNotFound, "security group %q doesn't exist", net.Name) return nil, errors.Wrapf(api.ErrNotFound, "security group %q doesn't exist", net.Name)
} }
securityGroups[name] = net.Name securityGroups[name] = net.Name
} }
@ -289,8 +287,8 @@ func (b *ecsAPIService) parseExternalVolumes(ctx context.Context, project *types
logrus.Debugf("searching for existing filesystem as volume %q", name) logrus.Debugf("searching for existing filesystem as volume %q", name)
tags := map[string]string{ tags := map[string]string{
compose.ProjectLabel: project.Name, api.ProjectLabel: project.Name,
compose.VolumeLabel: name, api.VolumeLabel: name,
} }
previous, err := b.aws.ListFileSystems(ctx, tags) previous, err := b.aws.ListFileSystems(ctx, tags)
if err != nil { if err != nil {
@ -397,11 +395,11 @@ func (b *ecsAPIService) ensureVolumes(r *awsResources, project *types.Project, t
FileSystemPolicy: nil, FileSystemPolicy: nil,
FileSystemTags: []efs.FileSystem_ElasticFileSystemTag{ FileSystemTags: []efs.FileSystem_ElasticFileSystemTag{
{ {
Key: compose.ProjectLabel, Key: api.ProjectLabel,
Value: project.Name, Value: project.Name,
}, },
{ {
Key: compose.VolumeLabel, Key: api.VolumeLabel,
Value: name, Value: name,
}, },
{ {

View File

@ -8,8 +8,8 @@ import (
context "context" context "context"
cloudformation "github.com/aws/aws-sdk-go/service/cloudformation" cloudformation "github.com/aws/aws-sdk-go/service/cloudformation"
ecs "github.com/aws/aws-sdk-go/service/ecs" ecs "github.com/aws/aws-sdk-go/service/ecs"
compose "github.com/docker/compose-cli/api/compose"
secrets "github.com/docker/compose-cli/api/secrets" secrets "github.com/docker/compose-cli/api/secrets"
compose "github.com/docker/compose-cli/pkg/api"
gomock "github.com/golang/mock/gomock" gomock "github.com/golang/mock/gomock"
reflect "reflect" reflect "reflect"
) )

View File

@ -23,14 +23,13 @@ import (
"github.com/docker/compose-cli/api/backend" "github.com/docker/compose-cli/api/backend"
"github.com/docker/compose-cli/api/cloud" "github.com/docker/compose-cli/api/cloud"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/containers" "github.com/docker/compose-cli/api/containers"
apicontext "github.com/docker/compose-cli/api/context" apicontext "github.com/docker/compose-cli/api/context"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/api/resources" "github.com/docker/compose-cli/api/resources"
"github.com/docker/compose-cli/api/secrets" "github.com/docker/compose-cli/api/secrets"
"github.com/docker/compose-cli/api/volumes" "github.com/docker/compose-cli/api/volumes"
"github.com/docker/compose-cli/pkg/api"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/aws/session"
@ -125,7 +124,7 @@ func (b *ecsAPIService) ContainerService() containers.Service {
return nil return nil
} }
func (b *ecsAPIService) ComposeService() compose.Service { func (b *ecsAPIService) ComposeService() api.Service {
return b return b
} }
@ -149,11 +148,11 @@ type ecsCloudService struct {
} }
func (a ecsCloudService) Login(ctx context.Context, params interface{}) error { func (a ecsCloudService) Login(ctx context.Context, params interface{}) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (a ecsCloudService) Logout(ctx context.Context) error { func (a ecsCloudService) Logout(ctx context.Context) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (a ecsCloudService) CreateContextData(ctx context.Context, params interface{}) (interface{}, string, error) { func (a ecsCloudService) CreateContextData(ctx context.Context, params interface{}) (interface{}, string, error) {

View File

@ -23,10 +23,6 @@ import (
"regexp" "regexp"
"strings" "strings"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/config"
"github.com/docker/compose-cli/api/errdefs"
ecsapi "github.com/aws/aws-sdk-go/service/ecs" ecsapi "github.com/aws/aws-sdk-go/service/ecs"
"github.com/aws/aws-sdk-go/service/elbv2" "github.com/aws/aws-sdk-go/service/elbv2"
cloudmapapi "github.com/aws/aws-sdk-go/service/servicediscovery" cloudmapapi "github.com/aws/aws-sdk-go/service/servicediscovery"
@ -42,16 +38,18 @@ import (
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/types"
"github.com/distribution/distribution/v3/reference" "github.com/distribution/distribution/v3/reference"
cliconfig "github.com/docker/cli/cli/config" cliconfig "github.com/docker/cli/cli/config"
"github.com/docker/compose-cli/api/config"
"github.com/docker/compose-cli/pkg/api"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"sigs.k8s.io/kustomize/kyaml/yaml" "sigs.k8s.io/kustomize/kyaml/yaml"
"sigs.k8s.io/kustomize/kyaml/yaml/merge2" "sigs.k8s.io/kustomize/kyaml/yaml/merge2"
) )
func (b *ecsAPIService) Kill(ctx context.Context, project *types.Project, options compose.KillOptions) error { func (b *ecsAPIService) Kill(ctx context.Context, project *types.Project, options api.KillOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (b *ecsAPIService) Convert(ctx context.Context, project *types.Project, options compose.ConvertOptions) ([]byte, error) { func (b *ecsAPIService) Convert(ctx context.Context, project *types.Project, options api.ConvertOptions) ([]byte, error) {
err := b.resolveServiceImagesDigests(ctx, project) err := b.resolveServiceImagesDigests(ctx, project)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -23,7 +23,7 @@ import (
"reflect" "reflect"
"testing" "testing"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
"github.com/aws/aws-sdk-go/service/elbv2" "github.com/aws/aws-sdk-go/service/elbv2"
"github.com/awslabs/goformation/v4/cloudformation" "github.com/awslabs/goformation/v4/cloudformation"
@ -406,8 +406,8 @@ volumes:
provisioned_throughput: 1024 provisioned_throughput: 1024
`, useDefaultVPC, func(m *MockAPIMockRecorder) { `, useDefaultVPC, func(m *MockAPIMockRecorder) {
m.ListFileSystems(gomock.Any(), map[string]string{ m.ListFileSystems(gomock.Any(), map[string]string{
compose.ProjectLabel: t.Name(), api.ProjectLabel: t.Name(),
compose.VolumeLabel: "db-data", api.VolumeLabel: "db-data",
}).Return(nil, nil) }).Return(nil, nil)
}) })
n := volumeResourceName("db-data") n := volumeResourceName("db-data")
@ -452,8 +452,8 @@ volumes:
db-data: {} db-data: {}
`, useDefaultVPC, func(m *MockAPIMockRecorder) { `, useDefaultVPC, func(m *MockAPIMockRecorder) {
m.ListFileSystems(gomock.Any(), map[string]string{ m.ListFileSystems(gomock.Any(), map[string]string{
compose.ProjectLabel: t.Name(), api.ProjectLabel: t.Name(),
compose.VolumeLabel: "db-data", api.VolumeLabel: "db-data",
}).Return([]awsResource{ }).Return([]awsResource{
existingAWSResource{ existingAWSResource{
id: "fs-123abc", id: "fs-123abc",
@ -521,7 +521,7 @@ services:
for i := 0; i < tags.Len(); i++ { for i := 0; i < tags.Len(); i++ {
k := tags.Index(i).FieldByName("Key").String() k := tags.Index(i).FieldByName("Key").String()
v := tags.Index(i).FieldByName("Value").String() v := tags.Index(i).FieldByName("Value").String()
if k == compose.ProjectLabel { if k == api.ProjectLabel {
assert.Equal(t, v, t.Name()) assert.Equal(t, v, t.Name())
} }
} }

View File

@ -24,9 +24,7 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/pkg/prompt"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/utils/prompt"
"github.com/AlecAivazis/survey/v2/terminal" "github.com/AlecAivazis/survey/v2/terminal"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
@ -34,6 +32,8 @@ import (
"github.com/aws/aws-sdk-go/aws/defaults" "github.com/aws/aws-sdk-go/aws/defaults"
"github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
"github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/pkg/api"
"github.com/pkg/errors" "github.com/pkg/errors"
"gopkg.in/ini.v1" "gopkg.in/ini.v1"
) )
@ -92,7 +92,7 @@ func (h contextCreateAWSHelper) createContextData(_ context.Context, opts Contex
return nil, "", err return nil, "", err
} }
if !contains(profilesList, opts.Profile) { if !contains(profilesList, opts.Profile) {
return nil, "", errors.Wrapf(errdefs.ErrNotFound, "profile %q not found", opts.Profile) return nil, "", errors.Wrapf(api.ErrNotFound, "profile %q not found", opts.Profile)
} }
} else { } else {
// interactive // interactive
@ -117,7 +117,7 @@ func (h contextCreateAWSHelper) createContextData(_ context.Context, opts Contex
selected, err := h.user.Select("Create a Docker context using:", options) selected, err := h.user.Select("Create a Docker context using:", options)
if err != nil { if err != nil {
if err == terminal.InterruptErr { if err == terminal.InterruptErr {
return nil, "", errdefs.ErrCanceled return nil, "", api.ErrCanceled
} }
return nil, "", err return nil, "", err
} }
@ -290,7 +290,7 @@ func (h contextCreateAWSHelper) chooseProfile(profiles []string) (string, error)
selected, err := h.user.Select("Select AWS Profile", options) selected, err := h.user.Select("Select AWS Profile", options)
if err != nil { if err != nil {
if err == terminal.InterruptErr { if err == terminal.InterruptErr {
return "", errdefs.ErrCanceled return "", api.ErrCanceled
} }
return "", err return "", err
} }

View File

@ -22,7 +22,7 @@ import (
"testing" "testing"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/utils/prompt" "github.com/docker/compose-cli/pkg/prompt"
"github.com/golang/mock/gomock" "github.com/golang/mock/gomock"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"

View File

@ -21,17 +21,16 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/api/errdefs" "github.com/docker/compose-cli/pkg/progress"
"github.com/docker/compose-cli/api/progress"
) )
func (b *ecsAPIService) Down(ctx context.Context, projectName string, options compose.DownOptions) error { func (b *ecsAPIService) Down(ctx context.Context, projectName string, options api.DownOptions) error {
if options.Volumes { if options.Volumes {
return errors.Wrap(errdefs.ErrNotImplemented, "--volumes option is not supported on ECS") return errors.Wrap(api.ErrNotImplemented, "--volumes option is not supported on ECS")
} }
if options.Images != "" { if options.Images != "" {
return errors.Wrap(errdefs.ErrNotImplemented, "--rmi option is not supported on ECS") return errors.Wrap(api.ErrNotImplemented, "--rmi option is not supported on ECS")
} }
return progress.Run(ctx, func(ctx context.Context) error { return progress.Run(ctx, func(ctx context.Context) error {
return b.down(ctx, projectName) return b.down(ctx, projectName)

View File

@ -21,10 +21,9 @@ import (
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/types"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/api/errdefs"
) )
func (b *ecsAPIService) Exec(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { func (b *ecsAPIService) Exec(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) {
return 0, errdefs.ErrNotImplemented return 0, api.ErrNotImplemented
} }

View File

@ -19,10 +19,9 @@ package ecs
import ( import (
"context" "context"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/api/errdefs"
) )
func (b *ecsAPIService) Images(ctx context.Context, projectName string, options compose.ImagesOptions) ([]compose.ImageSummary, error) { func (b *ecsAPIService) Images(ctx context.Context, projectName string, options api.ImagesOptions) ([]api.ImageSummary, error) {
return nil, errdefs.ErrNotImplemented return nil, api.ErrNotImplemented
} }

View File

@ -20,19 +20,19 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
) )
func (b *ecsAPIService) List(ctx context.Context, opts compose.ListOptions) ([]compose.Stack, error) { func (b *ecsAPIService) List(ctx context.Context, opts api.ListOptions) ([]api.Stack, error) {
stacks, err := b.aws.ListStacks(ctx) stacks, err := b.aws.ListStacks(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, stack := range stacks { for _, stack := range stacks {
if stack.Status == compose.STARTING { if stack.Status == api.STARTING {
if err := b.checkStackState(ctx, stack.Name); err != nil { if err := b.checkStackState(ctx, stack.Name); err != nil {
stack.Status = compose.FAILED stack.Status = api.FAILED
stack.Reason = err.Error() stack.Reason = err.Error()
} }
} }

View File

@ -24,13 +24,13 @@ import (
"github.com/docker/compose-cli/api/backend" "github.com/docker/compose-cli/api/backend"
"github.com/docker/compose-cli/api/cloud" "github.com/docker/compose-cli/api/cloud"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/containers" "github.com/docker/compose-cli/api/containers"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/api/resources" "github.com/docker/compose-cli/api/resources"
"github.com/docker/compose-cli/api/secrets" "github.com/docker/compose-cli/api/secrets"
"github.com/docker/compose-cli/api/volumes" "github.com/docker/compose-cli/api/volumes"
local_compose "github.com/docker/compose-cli/local/compose" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/pkg/compose"
) )
const backendType = store.EcsLocalSimulationContextType const backendType = store.EcsLocalSimulationContextType
@ -41,7 +41,7 @@ func init() {
type ecsLocalSimulation struct { type ecsLocalSimulation struct {
moby *client.Client moby *client.Client
compose compose.Service compose api.Service
} }
func service() (backend.Service, error) { func service() (backend.Service, error) {
@ -52,7 +52,7 @@ func service() (backend.Service, error) {
return &ecsLocalSimulation{ return &ecsLocalSimulation{
moby: apiClient, moby: apiClient,
compose: local_compose.NewComposeService(apiClient, cliconfig.LoadDefaultConfigFile(os.Stderr)), compose: compose.NewComposeService(apiClient, cliconfig.LoadDefaultConfigFile(os.Stderr)),
}, nil }, nil
} }
@ -72,7 +72,7 @@ func (e ecsLocalSimulation) SecretsService() secrets.Service {
return nil return nil
} }
func (e ecsLocalSimulation) ComposeService() compose.Service { func (e ecsLocalSimulation) ComposeService() api.Service {
return e return e
} }

View File

@ -28,23 +28,22 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sanathkr/go-yaml" "github.com/sanathkr/go-yaml"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/api/errdefs"
) )
func (e ecsLocalSimulation) Build(ctx context.Context, project *types.Project, options compose.BuildOptions) error { func (e ecsLocalSimulation) Build(ctx context.Context, project *types.Project, options api.BuildOptions) error {
return e.compose.Build(ctx, project, options) return e.compose.Build(ctx, project, options)
} }
func (e ecsLocalSimulation) Push(ctx context.Context, project *types.Project, options compose.PushOptions) error { func (e ecsLocalSimulation) Push(ctx context.Context, project *types.Project, options api.PushOptions) error {
return e.compose.Push(ctx, project, options) return e.compose.Push(ctx, project, options)
} }
func (e ecsLocalSimulation) Pull(ctx context.Context, project *types.Project, options compose.PullOptions) error { func (e ecsLocalSimulation) Pull(ctx context.Context, project *types.Project, options api.PullOptions) error {
return e.compose.Pull(ctx, project, options) return e.compose.Pull(ctx, project, options)
} }
func (e ecsLocalSimulation) Create(ctx context.Context, project *types.Project, opts compose.CreateOptions) error { func (e ecsLocalSimulation) Create(ctx context.Context, project *types.Project, opts api.CreateOptions) error {
enhanced, err := e.enhanceForLocalSimulation(project) enhanced, err := e.enhanceForLocalSimulation(project)
if err != nil { if err != nil {
return err return err
@ -53,27 +52,27 @@ func (e ecsLocalSimulation) Create(ctx context.Context, project *types.Project,
return e.compose.Create(ctx, enhanced, opts) return e.compose.Create(ctx, enhanced, opts)
} }
func (e ecsLocalSimulation) Start(ctx context.Context, project *types.Project, options compose.StartOptions) error { func (e ecsLocalSimulation) Start(ctx context.Context, project *types.Project, options api.StartOptions) error {
return e.compose.Start(ctx, project, options) return e.compose.Start(ctx, project, options)
} }
func (e ecsLocalSimulation) Restart(ctx context.Context, project *types.Project, options compose.RestartOptions) error { func (e ecsLocalSimulation) Restart(ctx context.Context, project *types.Project, options api.RestartOptions) error {
return e.compose.Restart(ctx, project, options) return e.compose.Restart(ctx, project, options)
} }
func (e ecsLocalSimulation) Stop(ctx context.Context, project *types.Project, options compose.StopOptions) error { func (e ecsLocalSimulation) Stop(ctx context.Context, project *types.Project, options api.StopOptions) error {
return e.compose.Stop(ctx, project, options) return e.compose.Stop(ctx, project, options)
} }
func (e ecsLocalSimulation) Up(ctx context.Context, project *types.Project, options compose.UpOptions) error { func (e ecsLocalSimulation) Up(ctx context.Context, project *types.Project, options api.UpOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (e ecsLocalSimulation) Kill(ctx context.Context, project *types.Project, options compose.KillOptions) error { func (e ecsLocalSimulation) Kill(ctx context.Context, project *types.Project, options api.KillOptions) error {
return e.compose.Kill(ctx, project, options) return e.compose.Kill(ctx, project, options)
} }
func (e ecsLocalSimulation) Convert(ctx context.Context, project *types.Project, options compose.ConvertOptions) ([]byte, error) { func (e ecsLocalSimulation) Convert(ctx context.Context, project *types.Project, options api.ConvertOptions) ([]byte, error) {
enhanced, err := e.enhanceForLocalSimulation(project) enhanced, err := e.enhanceForLocalSimulation(project)
if err != nil { if err != nil {
return nil, err return nil, err
@ -161,57 +160,57 @@ func (e ecsLocalSimulation) enhanceForLocalSimulation(project *types.Project) (*
return project, nil return project, nil
} }
func (e ecsLocalSimulation) Down(ctx context.Context, projectName string, options compose.DownOptions) error { func (e ecsLocalSimulation) Down(ctx context.Context, projectName string, options api.DownOptions) error {
options.RemoveOrphans = true options.RemoveOrphans = true
return e.compose.Down(ctx, projectName, options) return e.compose.Down(ctx, projectName, options)
} }
func (e ecsLocalSimulation) Logs(ctx context.Context, projectName string, consumer compose.LogConsumer, options compose.LogOptions) error { func (e ecsLocalSimulation) Logs(ctx context.Context, projectName string, consumer api.LogConsumer, options api.LogOptions) error {
return e.compose.Logs(ctx, projectName, consumer, options) return e.compose.Logs(ctx, projectName, consumer, options)
} }
func (e ecsLocalSimulation) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) { func (e ecsLocalSimulation) Ps(ctx context.Context, projectName string, options api.PsOptions) ([]api.ContainerSummary, error) {
return e.compose.Ps(ctx, projectName, options) return e.compose.Ps(ctx, projectName, options)
} }
func (e ecsLocalSimulation) List(ctx context.Context, opts compose.ListOptions) ([]compose.Stack, error) { func (e ecsLocalSimulation) List(ctx context.Context, opts api.ListOptions) ([]api.Stack, error) {
return e.compose.List(ctx, opts) return e.compose.List(ctx, opts)
} }
func (e ecsLocalSimulation) RunOneOffContainer(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { func (e ecsLocalSimulation) RunOneOffContainer(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) {
return 0, errors.Wrap(errdefs.ErrNotImplemented, "use docker-compose run") return 0, errors.Wrap(api.ErrNotImplemented, "use docker-compose run")
} }
func (e ecsLocalSimulation) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) error { func (e ecsLocalSimulation) Remove(ctx context.Context, project *types.Project, options api.RemoveOptions) error {
return e.compose.Remove(ctx, project, options) return e.compose.Remove(ctx, project, options)
} }
func (e ecsLocalSimulation) Exec(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { func (e ecsLocalSimulation) Exec(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) {
return 0, errdefs.ErrNotImplemented return 0, api.ErrNotImplemented
} }
func (e ecsLocalSimulation) Copy(ctx context.Context, project *types.Project, opts compose.CopyOptions) error { func (e ecsLocalSimulation) Copy(ctx context.Context, project *types.Project, opts api.CopyOptions) error {
return e.compose.Copy(ctx, project, opts) return e.compose.Copy(ctx, project, opts)
} }
func (e ecsLocalSimulation) Pause(ctx context.Context, project string, options compose.PauseOptions) error { func (e ecsLocalSimulation) Pause(ctx context.Context, project string, options api.PauseOptions) error {
return e.compose.Pause(ctx, project, options) return e.compose.Pause(ctx, project, options)
} }
func (e ecsLocalSimulation) UnPause(ctx context.Context, project string, options compose.PauseOptions) error { func (e ecsLocalSimulation) UnPause(ctx context.Context, project string, options api.PauseOptions) error {
return e.compose.UnPause(ctx, project, options) return e.compose.UnPause(ctx, project, options)
} }
func (e ecsLocalSimulation) Top(ctx context.Context, projectName string, services []string) ([]compose.ContainerProcSummary, error) { func (e ecsLocalSimulation) Top(ctx context.Context, projectName string, services []string) ([]api.ContainerProcSummary, error) {
return e.compose.Top(ctx, projectName, services) return e.compose.Top(ctx, projectName, services)
} }
func (e ecsLocalSimulation) Events(ctx context.Context, project string, options compose.EventsOptions) error { func (e ecsLocalSimulation) Events(ctx context.Context, project string, options api.EventsOptions) error {
return e.compose.Events(ctx, project, options) return e.compose.Events(ctx, project, options)
} }
func (e ecsLocalSimulation) Port(ctx context.Context, project string, service string, port int, options compose.PortOptions) (string, int, error) { func (e ecsLocalSimulation) Port(ctx context.Context, project string, service string, port int, options api.PortOptions) (string, int, error) {
return "", 0, errdefs.ErrNotImplemented return "", 0, api.ErrNotImplemented
} }
func (e ecsLocalSimulation) Images(ctx context.Context, projectName string, options compose.ImagesOptions) ([]compose.ImageSummary, error) { func (e ecsLocalSimulation) Images(ctx context.Context, projectName string, options api.ImagesOptions) ([]api.ImageSummary, error) {
return nil, errdefs.ErrNotImplemented return nil, api.ErrNotImplemented
} }

View File

@ -20,18 +20,18 @@ import (
"context" "context"
"github.com/docker/compose-cli/api/cloud" "github.com/docker/compose-cli/api/cloud"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/ecs" "github.com/docker/compose-cli/ecs"
"github.com/docker/compose-cli/pkg/api"
) )
var _ cloud.Service = ecsLocalSimulation{} var _ cloud.Service = ecsLocalSimulation{}
func (e ecsLocalSimulation) Login(ctx context.Context, params interface{}) error { func (e ecsLocalSimulation) Login(ctx context.Context, params interface{}) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (e ecsLocalSimulation) Logout(ctx context.Context) error { func (e ecsLocalSimulation) Logout(ctx context.Context) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (e ecsLocalSimulation) CreateContextData(ctx context.Context, params interface{}) (contextData interface{}, description string, err error) { func (e ecsLocalSimulation) CreateContextData(ctx context.Context, params interface{}) (contextData interface{}, description string, err error) {

View File

@ -19,11 +19,11 @@ package ecs
import ( import (
"context" "context"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/utils" "github.com/docker/compose-cli/utils"
) )
func (b *ecsAPIService) Logs(ctx context.Context, projectName string, consumer compose.LogConsumer, options compose.LogOptions) error { func (b *ecsAPIService) Logs(ctx context.Context, projectName string, consumer api.LogConsumer, options api.LogOptions) error {
if len(options.Services) > 0 { if len(options.Services) > 0 {
consumer = utils.FilteredLogConsumer(consumer, options.Services) consumer = utils.FilteredLogConsumer(consumer, options.Services)
} }

View File

@ -19,10 +19,10 @@ package ecs
import ( import (
"context" "context"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
) )
func (b *ecsAPIService) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) { func (b *ecsAPIService) Ps(ctx context.Context, projectName string, options api.PsOptions) ([]api.ContainerSummary, error) {
cluster, err := b.aws.GetStackClusterID(ctx, projectName) cluster, err := b.aws.GetStackClusterID(ctx, projectName)
if err != nil { if err != nil {
return nil, err return nil, err
@ -36,7 +36,7 @@ func (b *ecsAPIService) Ps(ctx context.Context, projectName string, options comp
return nil, nil return nil, nil
} }
summary := []compose.ContainerSummary{} summary := []api.ContainerSummary{}
for _, arn := range servicesARN { for _, arn := range servicesARN {
service, err := b.aws.DescribeService(ctx, cluster, arn) service, err := b.aws.DescribeService(ctx, cluster, arn)
if err != nil { if err != nil {

View File

@ -21,14 +21,13 @@ import (
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/types"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/api/errdefs"
) )
func (b *ecsAPIService) RunOneOffContainer(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { func (b *ecsAPIService) RunOneOffContainer(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) {
return 0, errdefs.ErrNotImplemented return 0, api.ErrNotImplemented
} }
func (b *ecsAPIService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) error { func (b *ecsAPIService) Remove(ctx context.Context, project *types.Project, options api.RemoveOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }

View File

@ -24,10 +24,9 @@ import (
"strings" "strings"
"time" "time"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/api/secrets" "github.com/docker/compose-cli/api/secrets"
"github.com/docker/compose-cli/internal" "github.com/docker/compose-cli/internal"
"github.com/docker/compose-cli/pkg/api"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/aws/arn"
@ -126,7 +125,7 @@ func (s sdk) ResolveCluster(ctx context.Context, nameOrArn string) (awsResource,
return nil, err return nil, err
} }
if len(clusters.Clusters) == 0 { if len(clusters.Clusters) == 0 {
return nil, errors.Wrapf(errdefs.ErrNotFound, "cluster %q does not exist", nameOrArn) return nil, errors.Wrapf(api.ErrNotFound, "cluster %q does not exist", nameOrArn)
} }
it := clusters.Clusters[0] it := clusters.Clusters[0]
return existingAWSResource{ return existingAWSResource{
@ -341,7 +340,7 @@ func (s sdk) CreateStack(ctx context.Context, name string, region string, templa
}, },
Tags: []*cloudformation.Tag{ Tags: []*cloudformation.Tag{
{ {
Key: aws.String(compose.ProjectLabel), Key: aws.String(api.ProjectLabel),
Value: aws.String(name), Value: aws.String(name),
}, },
}, },
@ -444,10 +443,10 @@ func (s sdk) GetStackID(ctx context.Context, name string) (string, error) {
return *stacks.Stacks[0].StackId, nil return *stacks.Stacks[0].StackId, nil
} }
func (s sdk) ListStacks(ctx context.Context) ([]compose.Stack, error) { func (s sdk) ListStacks(ctx context.Context) ([]api.Stack, error) {
params := cloudformation.DescribeStacksInput{} params := cloudformation.DescribeStacksInput{}
var token *string var token *string
var stacks []compose.Stack var stacks []api.Stack
for { for {
response, err := s.CF.DescribeStacksWithContext(ctx, &params) response, err := s.CF.DescribeStacksWithContext(ctx, &params)
if err != nil { if err != nil {
@ -455,18 +454,18 @@ func (s sdk) ListStacks(ctx context.Context) ([]compose.Stack, error) {
} }
for _, stack := range response.Stacks { for _, stack := range response.Stacks {
for _, t := range stack.Tags { for _, t := range stack.Tags {
if *t.Key == compose.ProjectLabel { if *t.Key == api.ProjectLabel {
status := compose.RUNNING status := api.RUNNING
switch aws.StringValue(stack.StackStatus) { switch aws.StringValue(stack.StackStatus) {
case "CREATE_IN_PROGRESS": case "CREATE_IN_PROGRESS":
status = compose.STARTING status = api.STARTING
case "DELETE_IN_PROGRESS": case "DELETE_IN_PROGRESS":
status = compose.REMOVING status = api.REMOVING
case "UPDATE_IN_PROGRESS": case "UPDATE_IN_PROGRESS":
status = compose.UPDATING status = api.UPDATING
default: default:
} }
stacks = append(stacks, compose.Stack{ stacks = append(stacks, api.Stack{
ID: aws.StringValue(stack.StackId), ID: aws.StringValue(stack.StackId),
Name: aws.StringValue(stack.StackName), Name: aws.StringValue(stack.StackName),
Status: status, Status: status,
@ -516,7 +515,7 @@ func (s sdk) GetStackClusterID(ctx context.Context, stack string) (string, error
return "", err return "", err
} }
if m.Cluster == "" { if m.Cluster == "" {
return "", errors.Wrap(errdefs.ErrNotFound, "CloudFormation is missing cluster metadata") return "", errors.Wrap(api.ErrNotFound, "CloudFormation is missing cluster metadata")
} }
return m.Cluster, nil return m.Cluster, nil
@ -844,28 +843,28 @@ func (s sdk) GetLogs(ctx context.Context, name string, consumer func(container s
} }
} }
func (s sdk) DescribeService(ctx context.Context, cluster string, arn string) (compose.ServiceStatus, error) { func (s sdk) DescribeService(ctx context.Context, cluster string, arn string) (api.ServiceStatus, error) {
services, err := s.ECS.DescribeServicesWithContext(ctx, &ecs.DescribeServicesInput{ services, err := s.ECS.DescribeServicesWithContext(ctx, &ecs.DescribeServicesInput{
Cluster: aws.String(cluster), Cluster: aws.String(cluster),
Services: []*string{aws.String(arn)}, Services: []*string{aws.String(arn)},
Include: aws.StringSlice([]string{"TAGS"}), Include: aws.StringSlice([]string{"TAGS"}),
}) })
if err != nil { if err != nil {
return compose.ServiceStatus{}, err return api.ServiceStatus{}, err
} }
for _, f := range services.Failures { for _, f := range services.Failures {
return compose.ServiceStatus{}, errors.Wrapf(errdefs.ErrNotFound, "can't get service status %s: %s", aws.StringValue(f.Detail), aws.StringValue(f.Reason)) return api.ServiceStatus{}, errors.Wrapf(api.ErrNotFound, "can't get service status %s: %s", aws.StringValue(f.Detail), aws.StringValue(f.Reason))
} }
service := services.Services[0] service := services.Services[0]
var name string var name string
for _, t := range service.Tags { for _, t := range service.Tags {
if *t.Key == compose.ServiceLabel { if *t.Key == api.ServiceLabel {
name = aws.StringValue(t.Value) name = aws.StringValue(t.Value)
} }
} }
if name == "" { if name == "" {
return compose.ServiceStatus{}, fmt.Errorf("service %s doesn't have a %s tag", *service.ServiceArn, compose.ServiceLabel) return api.ServiceStatus{}, fmt.Errorf("service %s doesn't have a %s tag", *service.ServiceArn, api.ServiceLabel)
} }
targetGroupArns := []string{} targetGroupArns := []string{}
for _, lb := range service.LoadBalancers { for _, lb := range service.LoadBalancers {
@ -875,9 +874,9 @@ func (s sdk) DescribeService(ctx context.Context, cluster string, arn string) (c
// one to get the target groups and another for load balancers // one to get the target groups and another for load balancers
loadBalancers, err := s.getURLWithPortMapping(ctx, targetGroupArns) loadBalancers, err := s.getURLWithPortMapping(ctx, targetGroupArns)
if err != nil { if err != nil {
return compose.ServiceStatus{}, err return api.ServiceStatus{}, err
} }
return compose.ServiceStatus{ return api.ServiceStatus{
ID: aws.StringValue(service.ServiceName), ID: aws.StringValue(service.ServiceName),
Name: name, Name: name,
Replicas: int(aws.Int64Value(service.RunningCount)), Replicas: int(aws.Int64Value(service.RunningCount)),
@ -886,8 +885,8 @@ func (s sdk) DescribeService(ctx context.Context, cluster string, arn string) (c
}, nil }, nil
} }
func (s sdk) DescribeServiceTasks(ctx context.Context, cluster string, project string, service string) ([]compose.ContainerSummary, error) { func (s sdk) DescribeServiceTasks(ctx context.Context, cluster string, project string, service string) ([]api.ContainerSummary, error) {
var summary []compose.ContainerSummary var summary []api.ContainerSummary
familly := fmt.Sprintf("%s-%s", project, service) familly := fmt.Sprintf("%s-%s", project, service)
var token *string var token *string
for { for {
@ -919,9 +918,9 @@ func (s sdk) DescribeServiceTasks(ctx context.Context, cluster string, project s
var service string var service string
for _, tag := range t.Tags { for _, tag := range t.Tags {
switch aws.StringValue(tag.Key) { switch aws.StringValue(tag.Key) {
case compose.ProjectLabel: case api.ProjectLabel:
project = aws.StringValue(tag.Value) project = aws.StringValue(tag.Value)
case compose.ServiceLabel: case api.ServiceLabel:
service = aws.StringValue(tag.Value) service = aws.StringValue(tag.Value)
} }
} }
@ -931,7 +930,7 @@ func (s sdk) DescribeServiceTasks(ctx context.Context, cluster string, project s
return nil, err return nil, err
} }
summary = append(summary, compose.ContainerSummary{ summary = append(summary, api.ContainerSummary{
ID: id.String(), ID: id.String(),
Name: id.Resource, Name: id.Resource,
Project: project, Project: project,
@ -949,7 +948,7 @@ func (s sdk) DescribeServiceTasks(ctx context.Context, cluster string, project s
return summary, nil return summary, nil
} }
func (s sdk) getURLWithPortMapping(ctx context.Context, targetGroupArns []string) ([]compose.PortPublisher, error) { func (s sdk) getURLWithPortMapping(ctx context.Context, targetGroupArns []string) ([]api.PortPublisher, error) {
if len(targetGroupArns) == 0 { if len(targetGroupArns) == 0 {
return nil, nil return nil, nil
} }
@ -983,14 +982,14 @@ func (s sdk) getURLWithPortMapping(ctx context.Context, targetGroupArns []string
} }
return nil return nil
} }
loadBalancers := []compose.PortPublisher{} loadBalancers := []api.PortPublisher{}
for _, tg := range groups.TargetGroups { for _, tg := range groups.TargetGroups {
for _, lbarn := range tg.LoadBalancerArns { for _, lbarn := range tg.LoadBalancerArns {
lb := filterLB(lbarn, lbs.LoadBalancers) lb := filterLB(lbarn, lbs.LoadBalancers)
if lb == nil { if lb == nil {
continue continue
} }
loadBalancers = append(loadBalancers, compose.PortPublisher{ loadBalancers = append(loadBalancers, api.PortPublisher{
URL: fmt.Sprintf("%s:%d", aws.StringValue(lb.DNSName), aws.Int64Value(tg.Port)), URL: fmt.Sprintf("%s:%d", aws.StringValue(lb.DNSName), aws.Int64Value(tg.Port)),
TargetPort: int(aws.Int64Value(tg.Port)), TargetPort: int(aws.Int64Value(tg.Port)),
PublishedPort: int(aws.Int64Value(tg.Port)), PublishedPort: int(aws.Int64Value(tg.Port)),
@ -1063,7 +1062,7 @@ func (s sdk) ResolveLoadBalancer(ctx context.Context, nameOrArn string) (awsReso
return nil, "", "", nil, err return nil, "", "", nil, err
} }
if len(lbs.LoadBalancers) == 0 { if len(lbs.LoadBalancers) == 0 {
return nil, "", "", nil, errors.Wrapf(errdefs.ErrNotFound, "load balancer %q does not exist", nameOrArn) return nil, "", "", nil, errors.Wrapf(api.ErrNotFound, "load balancer %q does not exist", nameOrArn)
} }
it := lbs.LoadBalancers[0] it := lbs.LoadBalancers[0]
var subNets []awsResource var subNets []awsResource
@ -1151,7 +1150,7 @@ func (s sdk) ResolveFileSystem(ctx context.Context, id string) (awsResource, err
return nil, err return nil, err
} }
if len(desc.FileSystems) == 0 { if len(desc.FileSystems) == 0 {
return nil, errors.Wrapf(errdefs.ErrNotFound, "EFS file system %q doesn't exist", id) return nil, errors.Wrapf(api.ErrNotFound, "EFS file system %q doesn't exist", id)
} }
it := desc.FileSystems[0] it := desc.FileSystems[0]
return existingAWSResource{ return existingAWSResource{

View File

@ -20,13 +20,13 @@ import (
"github.com/awslabs/goformation/v4/cloudformation/tags" "github.com/awslabs/goformation/v4/cloudformation/tags"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/types"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
) )
func projectTags(project *types.Project) []tags.Tag { func projectTags(project *types.Project) []tags.Tag {
return []tags.Tag{ return []tags.Tag{
{ {
Key: compose.ProjectLabel, Key: api.ProjectLabel,
Value: project.Name, Value: project.Name,
}, },
} }
@ -35,11 +35,11 @@ func projectTags(project *types.Project) []tags.Tag {
func serviceTags(project *types.Project, service types.ServiceConfig) []tags.Tag { func serviceTags(project *types.Project, service types.ServiceConfig) []tags.Tag {
return []tags.Tag{ return []tags.Tag{
{ {
Key: compose.ProjectLabel, Key: api.ProjectLabel,
Value: project.Name, Value: project.Name,
}, },
{ {
Key: compose.ServiceLabel, Key: api.ServiceLabel,
Value: service.Name, Value: service.Name,
}, },
} }
@ -48,11 +48,11 @@ func serviceTags(project *types.Project, service types.ServiceConfig) []tags.Tag
func networkTags(project *types.Project, net types.NetworkConfig) []tags.Tag { func networkTags(project *types.Project, net types.NetworkConfig) []tags.Tag {
return []tags.Tag{ return []tags.Tag{
{ {
Key: compose.ProjectLabel, Key: api.ProjectLabel,
Value: project.Name, Value: project.Name,
}, },
{ {
Key: compose.NetworkLabel, Key: api.NetworkLabel,
Value: net.Name, Value: net.Name,
}, },
} }

View File

@ -19,10 +19,9 @@ package ecs
import ( import (
"context" "context"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/api/errdefs"
) )
func (b *ecsAPIService) Top(ctx context.Context, projectName string, services []string) ([]compose.ContainerProcSummary, error) { func (b *ecsAPIService) Top(ctx context.Context, projectName string, services []string) ([]api.ContainerProcSummary, error) {
return nil, errdefs.ErrNotImplemented return nil, api.ErrNotImplemented
} }

View File

@ -26,73 +26,72 @@ import (
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/types"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/api/errdefs" "github.com/docker/compose-cli/pkg/progress"
"github.com/docker/compose-cli/api/progress"
) )
func (b *ecsAPIService) Build(ctx context.Context, project *types.Project, options compose.BuildOptions) error { func (b *ecsAPIService) Build(ctx context.Context, project *types.Project, options api.BuildOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (b *ecsAPIService) Push(ctx context.Context, project *types.Project, options compose.PushOptions) error { func (b *ecsAPIService) Push(ctx context.Context, project *types.Project, options api.PushOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (b *ecsAPIService) Pull(ctx context.Context, project *types.Project, options compose.PullOptions) error { func (b *ecsAPIService) Pull(ctx context.Context, project *types.Project, options api.PullOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (b *ecsAPIService) Create(ctx context.Context, project *types.Project, opts compose.CreateOptions) error { func (b *ecsAPIService) Create(ctx context.Context, project *types.Project, opts api.CreateOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (b *ecsAPIService) Start(ctx context.Context, project *types.Project, options compose.StartOptions) error { func (b *ecsAPIService) Start(ctx context.Context, project *types.Project, options api.StartOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (b *ecsAPIService) Restart(ctx context.Context, project *types.Project, options compose.RestartOptions) error { func (b *ecsAPIService) Restart(ctx context.Context, project *types.Project, options api.RestartOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (b *ecsAPIService) Stop(ctx context.Context, project *types.Project, options compose.StopOptions) error { func (b *ecsAPIService) Stop(ctx context.Context, project *types.Project, options api.StopOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (b *ecsAPIService) Pause(ctx context.Context, project string, options compose.PauseOptions) error { func (b *ecsAPIService) Pause(ctx context.Context, project string, options api.PauseOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (b *ecsAPIService) UnPause(ctx context.Context, project string, options compose.PauseOptions) error { func (b *ecsAPIService) UnPause(ctx context.Context, project string, options api.PauseOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (b *ecsAPIService) Events(ctx context.Context, project string, options compose.EventsOptions) error { func (b *ecsAPIService) Events(ctx context.Context, project string, options api.EventsOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (b *ecsAPIService) Port(ctx context.Context, project string, service string, port int, options compose.PortOptions) (string, int, error) { func (b *ecsAPIService) Port(ctx context.Context, project string, service string, port int, options api.PortOptions) (string, int, error) {
return "", 0, errdefs.ErrNotImplemented return "", 0, api.ErrNotImplemented
} }
func (b *ecsAPIService) Copy(ctx context.Context, project *types.Project, options compose.CopyOptions) error { func (b *ecsAPIService) Copy(ctx context.Context, project *types.Project, options api.CopyOptions) error {
return errdefs.ErrNotImplemented return api.ErrNotImplemented
} }
func (b *ecsAPIService) Up(ctx context.Context, project *types.Project, options compose.UpOptions) error { func (b *ecsAPIService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error {
return progress.Run(ctx, func(ctx context.Context) error { return progress.Run(ctx, func(ctx context.Context) error {
return b.up(ctx, project, options) return b.up(ctx, project, options)
}) })
} }
func (b *ecsAPIService) up(ctx context.Context, project *types.Project, options compose.UpOptions) error { func (b *ecsAPIService) up(ctx context.Context, project *types.Project, options api.UpOptions) error {
logrus.Debugf("deploying on AWS with region=%q", b.Region) logrus.Debugf("deploying on AWS with region=%q", b.Region)
err := b.aws.CheckRequirements(ctx, b.Region) err := b.aws.CheckRequirements(ctx, b.Region)
if err != nil { if err != nil {
return err return err
} }
template, err := b.Convert(ctx, project, compose.ConvertOptions{ template, err := b.Convert(ctx, project, api.ConvertOptions{
Format: "yaml", Format: "yaml",
}) })
if err != nil { if err != nil {
@ -138,7 +137,7 @@ func (b *ecsAPIService) up(ctx context.Context, project *types.Project, options
go func() { go func() {
<-signalChan <-signalChan
fmt.Println("user interrupted deployment. Deleting stack...") fmt.Println("user interrupted deployment. Deleting stack...")
b.Down(ctx, project.Name, compose.DownOptions{}) // nolint:errcheck b.Down(ctx, project.Name, api.DownOptions{}) // nolint:errcheck
}() }()
err = b.WaitStackCompletion(ctx, project.Name, operation, previousEvents...) err = b.WaitStackCompletion(ctx, project.Name, operation, previousEvents...)

View File

@ -20,9 +20,8 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/errdefs"
"github.com/docker/compose-cli/api/volumes" "github.com/docker/compose-cli/api/volumes"
"github.com/docker/compose-cli/pkg/api"
"github.com/awslabs/goformation/v4/cloudformation" "github.com/awslabs/goformation/v4/cloudformation"
"github.com/awslabs/goformation/v4/cloudformation/efs" "github.com/awslabs/goformation/v4/cloudformation/efs"
@ -63,11 +62,11 @@ func (b *ecsAPIService) createAccessPoints(project *types.Project, r awsResource
ap := efs.AccessPoint{ ap := efs.AccessPoint{
AccessPointTags: []efs.AccessPoint_AccessPointTag{ AccessPointTags: []efs.AccessPoint_AccessPointTag{
{ {
Key: compose.ProjectLabel, Key: api.ProjectLabel,
Value: project.Name, Value: project.Name,
}, },
{ {
Key: compose.VolumeLabel, Key: api.VolumeLabel,
Value: name, Value: name,
}, },
{ {
@ -147,7 +146,7 @@ func (e ecsVolumeService) Delete(ctx context.Context, volumeID string, options i
func (e ecsVolumeService) Inspect(ctx context.Context, volumeID string) (volumes.Volume, error) { func (e ecsVolumeService) Inspect(ctx context.Context, volumeID string) (volumes.Volume, error) {
ok, err := e.backend.aws.ResolveFileSystem(ctx, volumeID) ok, err := e.backend.aws.ResolveFileSystem(ctx, volumeID)
if ok == nil { if ok == nil {
err = errors.Wrapf(errdefs.ErrNotFound, "filesystem %q does not exists", volumeID) err = errors.Wrapf(api.ErrNotFound, "filesystem %q does not exists", volumeID)
} }
return volumes.Volume{ return volumes.Volume{
ID: volumeID, ID: volumeID,

View File

@ -23,10 +23,10 @@ import (
"strings" "strings"
"time" "time"
"github.com/docker/compose-cli/pkg/progress"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/iancoleman/strcase" "github.com/iancoleman/strcase"
"github.com/docker/compose-cli/api/progress"
) )
func (b *ecsAPIService) WaitStackCompletion(ctx context.Context, name string, operation int, ignored ...string) error { //nolint:gocyclo func (b *ecsAPIService) WaitStackCompletion(ctx context.Context, name string, operation int, ignored ...string) error { //nolint:gocyclo

View File

@ -21,18 +21,18 @@ package kube
import ( import (
"github.com/docker/compose-cli/api/backend" "github.com/docker/compose-cli/api/backend"
"github.com/docker/compose-cli/api/cloud" "github.com/docker/compose-cli/api/cloud"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/containers" "github.com/docker/compose-cli/api/containers"
"github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/api/context/store"
"github.com/docker/compose-cli/api/resources" "github.com/docker/compose-cli/api/resources"
"github.com/docker/compose-cli/api/secrets" "github.com/docker/compose-cli/api/secrets"
"github.com/docker/compose-cli/api/volumes" "github.com/docker/compose-cli/api/volumes"
"github.com/docker/compose-cli/pkg/api"
) )
const backendType = store.KubeContextType const backendType = store.KubeContextType
type kubeAPIService struct { type kubeAPIService struct {
composeService compose.Service composeService api.Service
} }
func init() { func init() {
@ -53,7 +53,7 @@ func (s *kubeAPIService) ContainerService() containers.Service {
return nil return nil
} }
func (s *kubeAPIService) ComposeService() compose.Service { func (s *kubeAPIService) ComposeService() api.Service {
return s.composeService return s.composeService
} }

View File

@ -27,8 +27,9 @@ import (
"strings" "strings"
"time" "time"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
"github.com/docker/compose-cli/utils" "github.com/docker/compose-cli/pkg/utils"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -77,7 +78,7 @@ func NewKubeClient(config genericclioptions.RESTClientGetter) (*KubeClient, erro
// GetPod retrieves a service pod // GetPod retrieves a service pod
func (kc KubeClient) GetPod(ctx context.Context, projectName, serviceName string) (*corev1.Pod, error) { func (kc KubeClient) GetPod(ctx context.Context, projectName, serviceName string) (*corev1.Pod, error) {
pods, err := kc.client.CoreV1().Pods(kc.namespace).List(ctx, metav1.ListOptions{ pods, err := kc.client.CoreV1().Pods(kc.namespace).List(ctx, metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s", compose.ProjectLabel, projectName), LabelSelector: fmt.Sprintf("%s=%s", api.ProjectLabel, projectName),
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@ -87,7 +88,7 @@ func (kc KubeClient) GetPod(ctx context.Context, projectName, serviceName string
} }
var pod corev1.Pod var pod corev1.Pod
for _, p := range pods.Items { for _, p := range pods.Items {
service := p.Labels[compose.ServiceLabel] service := p.Labels[api.ServiceLabel]
if service == serviceName { if service == serviceName {
pod = p pod = p
break break
@ -97,7 +98,7 @@ func (kc KubeClient) GetPod(ctx context.Context, projectName, serviceName string
} }
// Exec executes a command in a container // Exec executes a command in a container
func (kc KubeClient) Exec(ctx context.Context, projectName string, opts compose.RunOptions) error { func (kc KubeClient) Exec(ctx context.Context, projectName string, opts api.RunOptions) error {
pod, err := kc.GetPod(ctx, projectName, opts.Service) pod, err := kc.GetPod(ctx, projectName, opts.Service)
if err != nil || pod == nil { if err != nil || pod == nil {
return err return err
@ -148,24 +149,24 @@ func (kc KubeClient) Exec(ctx context.Context, projectName string, opts compose.
} }
// GetContainers get containers for a given compose project // GetContainers get containers for a given compose project
func (kc KubeClient) GetContainers(ctx context.Context, projectName string, all bool) ([]compose.ContainerSummary, error) { func (kc KubeClient) GetContainers(ctx context.Context, projectName string, all bool) ([]api.ContainerSummary, error) {
fieldSelector := "" fieldSelector := ""
if !all { if !all {
fieldSelector = "status.phase=Running" fieldSelector = "status.phase=Running"
} }
pods, err := kc.client.CoreV1().Pods(kc.namespace).List(ctx, metav1.ListOptions{ pods, err := kc.client.CoreV1().Pods(kc.namespace).List(ctx, metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s", compose.ProjectLabel, projectName), LabelSelector: fmt.Sprintf("%s=%s", api.ProjectLabel, projectName),
FieldSelector: fieldSelector, FieldSelector: fieldSelector,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
} }
services := map[string][]compose.PortPublisher{} services := map[string][]api.PortPublisher{}
result := []compose.ContainerSummary{} result := []api.ContainerSummary{}
for _, pod := range pods.Items { for _, pod := range pods.Items {
summary := podToContainerSummary(pod) summary := podToContainerSummary(pod)
serviceName := pod.GetObjectMeta().GetLabels()[compose.ServiceLabel] serviceName := pod.GetObjectMeta().GetLabels()[api.ServiceLabel]
ports, ok := services[serviceName] ports, ok := services[serviceName]
if !ok { if !ok {
s, err := kc.client.CoreV1().Services(kc.namespace).Get(ctx, serviceName, metav1.GetOptions{}) s, err := kc.client.CoreV1().Services(kc.namespace).Get(ctx, serviceName, metav1.GetOptions{})
@ -176,11 +177,11 @@ func (kc KubeClient) GetContainers(ctx context.Context, projectName string, all
result = append(result, summary) result = append(result, summary)
continue continue
} }
ports = []compose.PortPublisher{} ports = []api.PortPublisher{}
if s != nil { if s != nil {
if s.Spec.Type == corev1.ServiceTypeLoadBalancer { if s.Spec.Type == corev1.ServiceTypeLoadBalancer {
if len(s.Status.LoadBalancer.Ingress) > 0 { if len(s.Status.LoadBalancer.Ingress) > 0 {
port := compose.PortPublisher{URL: s.Status.LoadBalancer.Ingress[0].IP} port := api.PortPublisher{URL: s.Status.LoadBalancer.Ingress[0].IP}
if len(s.Spec.Ports) > 0 { if len(s.Spec.Ports) > 0 {
port.URL = fmt.Sprintf("%s:%d", port.URL, s.Spec.Ports[0].Port) port.URL = fmt.Sprintf("%s:%d", port.URL, s.Spec.Ports[0].Port)
port.TargetPort = s.Spec.Ports[0].TargetPort.IntValue() port.TargetPort = s.Spec.Ports[0].TargetPort.IntValue()
@ -200,9 +201,9 @@ func (kc KubeClient) GetContainers(ctx context.Context, projectName string, all
} }
// GetLogs retrieves pod logs // GetLogs retrieves pod logs
func (kc *KubeClient) GetLogs(ctx context.Context, projectName string, consumer compose.LogConsumer, follow bool) error { func (kc *KubeClient) GetLogs(ctx context.Context, projectName string, consumer api.LogConsumer, follow bool) error {
pods, err := kc.client.CoreV1().Pods(kc.namespace).List(ctx, metav1.ListOptions{ pods, err := kc.client.CoreV1().Pods(kc.namespace).List(ctx, metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s", compose.ProjectLabel, projectName), LabelSelector: fmt.Sprintf("%s=%s", api.ProjectLabel, projectName),
}) })
if err != nil { if err != nil {
return err return err
@ -210,7 +211,7 @@ func (kc *KubeClient) GetLogs(ctx context.Context, projectName string, consumer
eg, ctx := errgroup.WithContext(ctx) eg, ctx := errgroup.WithContext(ctx)
for _, pod := range pods.Items { for _, pod := range pods.Items {
request := kc.client.CoreV1().Pods(kc.namespace).GetLogs(pod.Name, &corev1.PodLogOptions{Follow: follow}) request := kc.client.CoreV1().Pods(kc.namespace).GetLogs(pod.Name, &corev1.PodLogOptions{Follow: follow})
service := pod.Labels[compose.ServiceLabel] service := pod.Labels[api.ServiceLabel]
w := utils.GetWriter(func(line string) { w := utils.GetWriter(func(line string) {
consumer.Log(pod.Name, service, line) consumer.Log(pod.Name, service, line)
}) })
@ -243,7 +244,7 @@ func (kc KubeClient) WaitForPodState(ctx context.Context, opts WaitForStatusOpti
time.Sleep(500 * time.Millisecond) time.Sleep(500 * time.Millisecond)
pods, err := kc.client.CoreV1().Pods(kc.namespace).List(ctx, metav1.ListOptions{ pods, err := kc.client.CoreV1().Pods(kc.namespace).List(ctx, metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s", compose.ProjectLabel, opts.ProjectName), LabelSelector: fmt.Sprintf("%s=%s", api.ProjectLabel, opts.ProjectName),
}) })
if err != nil { if err != nil {
errch <- err errch <- err

View File

@ -26,7 +26,7 @@ import (
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/pkg/api"
) )
func TestPodToContainerSummary(t *testing.T) { func TestPodToContainerSummary(t *testing.T) {
@ -34,8 +34,8 @@ func TestPodToContainerSummary(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "c1-123", Name: "c1-123",
Labels: map[string]string{ Labels: map[string]string{
compose.ProjectLabel: "myproject", api.ProjectLabel: "myproject",
compose.ServiceLabel: "service1", api.ServiceLabel: "service1",
}, },
}, },
Status: v1.PodStatus{ Status: v1.PodStatus{
@ -45,7 +45,7 @@ func TestPodToContainerSummary(t *testing.T) {
container := podToContainerSummary(pod) container := podToContainerSummary(pod)
expected := compose.ContainerSummary{ expected := api.ContainerSummary{
ID: "c1-123", ID: "c1-123",
Name: "c1-123", Name: "c1-123",
Project: "myproject", Project: "myproject",

Some files were not shown because too many files have changed in this diff Show More