From d90495e1cdc4a1279639ec488472762746c7ff6e Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Mon, 14 Jun 2021 16:26:14 +0200 Subject: [PATCH] move compose API into pkg/api Signed-off-by: Nicolas De Loof --- aci/aci.go | 6 +- aci/backend.go | 4 +- aci/compose.go | 113 ++++++++++++------------ aci/containers.go | 14 +-- aci/context.go | 6 +- aci/convert/convert.go | 8 +- aci/convert/convert_test.go | 4 +- aci/convert/volume.go | 16 ++-- aci/e2e/e2e-aci_test.go | 14 ++- aci/login/client.go | 4 +- aci/login/login.go | 34 +++---- aci/volumes.go | 10 +-- api/backend/backend.go | 7 +- api/client/client.go | 7 +- api/client/compose.go | 100 ++++++++++----------- api/client/containers.go | 20 ++--- api/client/resources.go | 4 +- api/client/secrets.go | 10 +-- api/client/volume.go | 10 +-- api/cloud/api.go | 8 +- api/context/store/store.go | 18 ++-- api/context/store/store_test.go | 10 +-- cli/cmd/compose/build.go | 8 +- cli/cmd/compose/compose.go | 9 +- cli/cmd/compose/convert.go | 8 +- cli/cmd/compose/cp.go | 8 +- cli/cmd/compose/create.go | 18 ++-- cli/cmd/compose/down.go | 8 +- cli/cmd/compose/events.go | 10 +-- cli/cmd/compose/exec.go | 8 +- cli/cmd/compose/images.go | 8 +- cli/cmd/compose/kill.go | 6 +- cli/cmd/compose/list.go | 12 +-- cli/cmd/compose/logs.go | 8 +- cli/cmd/compose/pause.go | 14 +-- cli/cmd/compose/port.go | 8 +- cli/cmd/compose/ps.go | 8 +- cli/cmd/compose/pull.go | 8 +- cli/cmd/compose/push.go | 8 +- cli/cmd/compose/remove.go | 10 +-- cli/cmd/compose/restart.go | 8 +- cli/cmd/compose/run.go | 14 +-- cli/cmd/compose/start.go | 8 +- cli/cmd/compose/stop.go | 8 +- cli/cmd/compose/top.go | 6 +- cli/cmd/compose/up.go | 14 +-- cli/cmd/context/create_aci.go | 4 +- cli/cmd/context/create_ecs.go | 6 +- cli/cmd/context/create_kube.go | 4 +- cli/cmd/context/update.go | 4 +- cli/cmd/kill.go | 4 +- cli/cmd/login/login.go | 4 +- cli/cmd/logout/azure.go | 4 +- cli/cmd/rm.go | 6 +- cli/cmd/start.go | 4 +- cli/cmd/stop.go | 4 +- cli/formatter/formatter.go | 6 +- cli/formatter/logs.go | 4 +- cli/main.go | 13 ++- cli/server/metrics_test.go | 9 +- ecs/aws.go | 10 +-- ecs/awsResources.go | 16 ++-- ecs/aws_mock.go | 2 +- ecs/backend.go | 9 +- ecs/cloudformation.go | 12 ++- ecs/cloudformation_test.go | 12 +-- ecs/context.go | 8 +- ecs/down.go | 9 +- ecs/exec.go | 7 +- ecs/images.go | 7 +- ecs/list.go | 8 +- ecs/local/backend.go | 6 +- ecs/local/compose.go | 61 +++++++------ ecs/local/context.go | 6 +- ecs/logs.go | 4 +- ecs/ps.go | 6 +- ecs/run.go | 11 ++- ecs/sdk.go | 59 ++++++------- ecs/tags.go | 12 +-- ecs/top.go | 7 +- ecs/up.go | 59 ++++++------- ecs/volumes.go | 9 +- kube/backend.go | 6 +- kube/client/client.go | 30 +++---- kube/client/client_test.go | 8 +- kube/client/utils.go | 28 +++--- kube/compose.go | 99 ++++++++++----------- kube/context.go | 10 +-- kube/helm/helm.go | 8 +- kube/resources/kube.go | 6 +- local/backend.go | 6 +- local/compose/attach.go | 16 ++-- local/compose/build.go | 6 +- local/compose/compose.go | 10 +-- local/compose/containers.go | 8 +- local/compose/convergence.go | 12 +-- local/compose/cp.go | 16 ++-- local/compose/create.go | 36 ++++---- local/compose/down.go | 18 ++-- local/compose/down_test.go | 32 +++---- local/compose/events.go | 8 +- local/compose/exec.go | 10 +-- local/compose/filters.go | 14 +-- local/compose/images.go | 14 +-- local/compose/kill.go | 6 +- local/compose/kill_test.go | 16 ++-- local/compose/logs.go | 6 +- local/compose/ls.go | 12 +-- local/compose/ls_test.go | 10 +-- local/compose/pause.go | 10 +-- local/compose/port.go | 4 +- local/compose/printer.go | 26 +++--- local/compose/ps.go | 16 ++-- local/compose/ps_test.go | 16 ++-- local/compose/pull.go | 6 +- local/compose/push.go | 6 +- local/compose/remove.go | 6 +- local/compose/restart.go | 6 +- local/compose/run.go | 24 ++--- local/compose/start.go | 18 ++-- local/compose/stop.go | 6 +- local/compose/stop_test.go | 2 +- local/compose/top.go | 8 +- local/compose/up.go | 8 +- local/containers.go | 6 +- main.go | 2 +- {api/compose => pkg/api}/api.go | 2 +- {api/compose => pkg/api}/api_test.go | 2 +- {api/errdefs => pkg/api}/errors.go | 2 +- {api/errdefs => pkg/api}/errors_test.go | 2 +- {api/compose => pkg/api}/labels.go | 2 +- {api/compose => pkg/api}/proxy.go | 52 ++++++----- utils/logs.go | 6 +- 133 files changed, 864 insertions(+), 893 deletions(-) rename {api/compose => pkg/api}/api.go (99%) rename {api/compose => pkg/api}/api_test.go (98%) rename {api/errdefs => pkg/api}/errors.go (99%) rename {api/errdefs => pkg/api}/errors_test.go (98%) rename {api/compose => pkg/api}/labels.go (99%) rename {api/compose => pkg/api}/proxy.go (91%) diff --git a/aci/aci.go b/aci/aci.go index 7478b9789..78e9303f1 100644 --- a/aci/aci.go +++ b/aci/aci.go @@ -39,8 +39,8 @@ import ( "github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/containers" "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/pkg/api" ) 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)) if err != nil { // Not found, autocreate fileshare - if !errdefs.IsNotFoundError(err) { + if !api.IsNotFoundError(err) { return err } aciVolumeOpts := &VolumeCreateOptions{ @@ -198,7 +198,7 @@ func stopACIContainerGroup(ctx context.Context, aciContext store.AciContext, con result, err := containerGroupsClient.Stop(ctx, aciContext.ResourceGroup, containerGroupName) if result.IsHTTPStatus(http.StatusNotFound) { - return errdefs.ErrNotFound + return api.ErrNotFound } return err } diff --git a/aci/backend.go b/aci/backend.go index c18b32c6e..ac782356c 100644 --- a/aci/backend.go +++ b/aci/backend.go @@ -26,11 +26,11 @@ import ( "github.com/docker/compose-cli/aci/convert" "github.com/docker/compose-cli/aci/login" "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/resources" "github.com/docker/compose-cli/api/secrets" "github.com/docker/compose-cli/api/volumes" + "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/api/cloud" apicontext "github.com/docker/compose-cli/api/context" @@ -115,7 +115,7 @@ func (a *aciAPIService) ContainerService() containers.Service { return a.aciContainerService } -func (a *aciAPIService) ComposeService() compose.Service { +func (a *aciAPIService) ComposeService() api.Service { return a.aciComposeService } diff --git a/aci/compose.go b/aci/compose.go index 6fe92db0f..5f3575952 100644 --- a/aci/compose.go +++ b/aci/compose.go @@ -27,10 +27,9 @@ import ( "github.com/docker/compose-cli/aci/convert" "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/errdefs" "github.com/docker/compose-cli/api/progress" + "github.com/docker/compose-cli/pkg/api" "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 { - return errdefs.ErrNotImplemented +func (cs *aciComposeService) Build(ctx context.Context, project *types.Project, options api.BuildOptions) error { + return api.ErrNotImplemented } -func (cs *aciComposeService) Push(ctx context.Context, project *types.Project, options compose.PushOptions) error { - return errdefs.ErrNotImplemented +func (cs *aciComposeService) Push(ctx context.Context, project *types.Project, options api.PushOptions) error { + return api.ErrNotImplemented } -func (cs *aciComposeService) Pull(ctx context.Context, project *types.Project, options compose.PullOptions) error { - return errdefs.ErrNotImplemented +func (cs *aciComposeService) Pull(ctx context.Context, project *types.Project, options api.PullOptions) error { + return api.ErrNotImplemented } -func (cs *aciComposeService) Create(ctx context.Context, project *types.Project, opts compose.CreateOptions) error { - return errdefs.ErrNotImplemented +func (cs *aciComposeService) Create(ctx context.Context, project *types.Project, opts api.CreateOptions) error { + return api.ErrNotImplemented } -func (cs *aciComposeService) Start(ctx context.Context, project *types.Project, options compose.StartOptions) error { - return errdefs.ErrNotImplemented +func (cs *aciComposeService) Start(ctx context.Context, project *types.Project, options api.StartOptions) error { + return api.ErrNotImplemented } -func (cs *aciComposeService) Restart(ctx context.Context, project *types.Project, options compose.RestartOptions) error { - return errdefs.ErrNotImplemented +func (cs *aciComposeService) Restart(ctx context.Context, project *types.Project, options api.RestartOptions) error { + return api.ErrNotImplemented } -func (cs *aciComposeService) Stop(ctx context.Context, project *types.Project, options compose.StopOptions) error { - return errdefs.ErrNotImplemented +func (cs *aciComposeService) Stop(ctx context.Context, project *types.Project, options api.StopOptions) error { + return api.ErrNotImplemented } -func (cs *aciComposeService) Pause(ctx context.Context, project string, options compose.PauseOptions) error { - return errdefs.ErrNotImplemented +func (cs *aciComposeService) Pause(ctx context.Context, project string, options api.PauseOptions) error { + return api.ErrNotImplemented } -func (cs *aciComposeService) UnPause(ctx context.Context, project string, options compose.PauseOptions) error { - return errdefs.ErrNotImplemented +func (cs *aciComposeService) UnPause(ctx context.Context, project string, options api.PauseOptions) error { + return api.ErrNotImplemented } -func (cs *aciComposeService) Copy(ctx context.Context, project *types.Project, options compose.CopyOptions) error { - return errdefs.ErrNotImplemented +func (cs *aciComposeService) Copy(ctx context.Context, project *types.Project, options api.CopyOptions) error { + 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 cs.up(ctx, project) }) @@ -130,12 +129,12 @@ func (cs aciComposeService) warnKeepVolumeOnDown(ctx context.Context, projectNam 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 { - 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 != "" { - 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 { 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 } if cg.IsHTTPStatus(http.StatusNoContent) { - return errdefs.ErrNotFound + return api.ErrNotFound } 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) if err != nil { 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) } - res := []compose.ContainerSummary{} + res := []api.ContainerSummary{} for _, container := range *group.Containers { if isContainerVisible(container, group, false) { continue } - var publishers []compose.PortPublisher + var publishers []api.PortPublisher urls := formatter.PortsToStrings(convert.ToPorts(group.IPAddress, *container.Ports), convert.FQDN(group, cs.ctx.Location)) for i, p := range *container.Ports { - publishers = append(publishers, compose.PortPublisher{ + publishers = append(publishers, api.PortPublisher{ URL: urls[i], TargetPort: 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) - res = append(res, compose.ContainerSummary{ + res = append(res, api.ContainerSummary{ ID: id, Name: id, Project: projectName, @@ -199,26 +198,26 @@ func (cs *aciComposeService) Ps(ctx context.Context, projectName string, options 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) if err != nil { return nil, err } - var stacks []compose.Stack + var stacks []api.Stack for _, group := range containerGroups { if _, found := group.Tags[composeContainerTag]; !found { continue } - state := compose.RUNNING + state := api.RUNNING for _, container := range *group.ContainerGroupProperties.Containers { containerState := convert.GetStatus(container, group) - if containerState != compose.RUNNING { + if containerState != api.RUNNING { state = containerState break } } - stacks = append(stacks, compose.Stack{ + stacks = append(stacks, api.Stack{ ID: *group.ID, Name: *group.Name, Status: state, @@ -227,41 +226,41 @@ func (cs *aciComposeService) List(ctx context.Context, opts compose.ListOptions) return stacks, nil } -func (cs *aciComposeService) Logs(ctx context.Context, projectName string, consumer compose.LogConsumer, options compose.LogOptions) error { - return errdefs.ErrNotImplemented +func (cs *aciComposeService) Logs(ctx context.Context, projectName string, consumer api.LogConsumer, options api.LogOptions) error { + return api.ErrNotImplemented } -func (cs *aciComposeService) Convert(ctx context.Context, project *types.Project, options compose.ConvertOptions) ([]byte, error) { - return nil, errdefs.ErrNotImplemented +func (cs *aciComposeService) Convert(ctx context.Context, project *types.Project, options api.ConvertOptions) ([]byte, error) { + return nil, api.ErrNotImplemented } -func (cs *aciComposeService) Kill(ctx context.Context, project *types.Project, options compose.KillOptions) error { - return errdefs.ErrNotImplemented +func (cs *aciComposeService) Kill(ctx context.Context, project *types.Project, options api.KillOptions) error { + return api.ErrNotImplemented } -func (cs *aciComposeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { - return 0, errdefs.ErrNotImplemented +func (cs *aciComposeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) { + return 0, api.ErrNotImplemented } -func (cs *aciComposeService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) error { - return errdefs.ErrNotImplemented +func (cs *aciComposeService) Remove(ctx context.Context, project *types.Project, options api.RemoveOptions) error { + return api.ErrNotImplemented } -func (cs *aciComposeService) Exec(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { - return 0, errdefs.ErrNotImplemented +func (cs *aciComposeService) Exec(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) { + return 0, api.ErrNotImplemented } -func (cs *aciComposeService) Top(ctx context.Context, projectName string, services []string) ([]compose.ContainerProcSummary, error) { - return nil, errdefs.ErrNotImplemented +func (cs *aciComposeService) Top(ctx context.Context, projectName string, services []string) ([]api.ContainerProcSummary, error) { + return nil, api.ErrNotImplemented } -func (cs *aciComposeService) Events(ctx context.Context, project string, options compose.EventsOptions) error { - return errdefs.ErrNotImplemented +func (cs *aciComposeService) Events(ctx context.Context, project string, options api.EventsOptions) error { + return api.ErrNotImplemented } -func (cs *aciComposeService) Port(ctx context.Context, project string, service string, port int, options compose.PortOptions) (string, int, error) { - return "", 0, errdefs.ErrNotImplemented +func (cs *aciComposeService) Port(ctx context.Context, project string, service string, port int, options api.PortOptions) (string, int, error) { + return "", 0, api.ErrNotImplemented } -func (cs *aciComposeService) Images(ctx context.Context, projectName string, options compose.ImagesOptions) ([]compose.ImageSummary, error) { - return nil, errdefs.ErrNotImplemented +func (cs *aciComposeService) Images(ctx context.Context, projectName string, options api.ImagesOptions) ([]api.ImageSummary, error) { + return nil, api.ErrNotImplemented } diff --git a/aci/containers.go b/aci/containers.go index 0425c5837..60407e2b0 100644 --- a/aci/containers.go +++ b/aci/containers.go @@ -33,7 +33,7 @@ import ( "github.com/docker/compose-cli/aci/login" "github.com/docker/compose-cli/api/containers" "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 { @@ -107,7 +107,7 @@ func (cs *aciContainerService) Start(ctx context.Context, containerID string) er var aerr autorest.DetailedError if ok := errors.As(err, &aerr); ok { if aerr.StatusCode == http.StatusNotFound { - return errdefs.ErrNotFound + return api.ErrNotFound } } 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) if err != nil { if cg.StatusCode == http.StatusNotFound { - return errdefs.ErrNotFound + return api.ErrNotFound } return err } @@ -216,7 +216,7 @@ func (cs *aciContainerService) Delete(ctx context.Context, containerID string, r status := convert.GetStatus(container, cg) 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) // Delete returns `StatusNoContent` if the group is not found if cg.IsHTTPStatus(http.StatusNoContent) { - return errdefs.ErrNotFound + return api.ErrNotFound } if err != nil { return err @@ -244,7 +244,7 @@ func (cs *aciContainerService) Inspect(ctx context.Context, containerID string) return containers.Container{}, err } 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 @@ -257,7 +257,7 @@ func (cs *aciContainerService) Inspect(ctx context.Context, containerID string) } } if !found { - return containers.Container{}, errdefs.ErrNotFound + return containers.Container{}, api.ErrNotFound } return convert.ContainerGroupToContainer(containerID, cg, cc, cs.ctx.Location), nil diff --git a/aci/context.go b/aci/context.go index 2ce1b6c1c..9345cefdf 100644 --- a/aci/context.go +++ b/aci/context.go @@ -28,7 +28,7 @@ import ( "github.com/pkg/errors" "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" ) @@ -41,7 +41,7 @@ type ContextParams struct { } // 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 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) if err != nil { if err == terminal.InterruptErr { - return resources.Group{}, errdefs.ErrCanceled + return resources.Group{}, api.ErrCanceled } return resources.Group{}, err diff --git a/aci/convert/convert.go b/aci/convert/convert.go index 3cb7211b5..d92f6ebfe 100644 --- a/aci/convert/convert.go +++ b/aci/convert/convert.go @@ -31,9 +31,9 @@ import ( "github.com/pkg/errors" "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/context/store" + "github.com/docker/compose-cli/pkg/api" "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 -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 if GetStatus(container, group) != StatusRunning { replicas = 0 } - return compose.ServiceStatus{ + return api.ServiceStatus{ ID: containerID, Name: *container.Name, 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 { return "Node " + *group.InstanceView.State } - return compose.UNKNOWN + return api.UNKNOWN } diff --git a/aci/convert/convert_test.go b/aci/convert/convert_test.go index 7cef8300a..fd6cf028f 100644 --- a/aci/convert/convert_test.go +++ b/aci/convert/convert_test.go @@ -28,9 +28,9 @@ import ( "gotest.tools/v3/assert" 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/context/store" + "github.com/docker/compose-cli/pkg/api" ) var ( @@ -258,7 +258,7 @@ func TestContainerGroupToServiceStatus(t *testing.T) { }, } - var expectedService = compose.ServiceStatus{ + var expectedService = api.ServiceStatus{ ID: "myContainerID", Name: "myContainerID", Ports: []string{"42.42.42.42:80->80/tcp"}, diff --git a/aci/convert/volume.go b/aci/convert/volume.go index 3c3e0dd44..79b6fcb36 100644 --- a/aci/convert/volume.go +++ b/aci/convert/volume.go @@ -22,15 +22,13 @@ import ( "strconv" "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/go-autorest/autorest/to" - "github.com/compose-spec/compose-go/types" - - "github.com/docker/compose-cli/aci/login" - "github.com/docker/compose-cli/api/errdefs" + "github.com/pkg/errors" ) const ( @@ -151,10 +149,10 @@ func (v *volumeInput) parse(name string, candidate string) error { sourceTokens := strings.Split(tokens[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] == "" { - 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.fileshare = sourceTokens[1] @@ -168,11 +166,11 @@ func (v *volumeInput) parse(name string, candidate string) error { v.target = tokens[1] permissions := strings.ToLower(tokens[2]) 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" 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 diff --git a/aci/e2e/e2e-aci_test.go b/aci/e2e/e2e-aci_test.go index e2a46900d..766b67cf2 100644 --- a/aci/e2e/e2e-aci_test.go +++ b/aci/e2e/e2e-aci_test.go @@ -35,25 +35,23 @@ import ( "testing" "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/prometheus/tsdb/fileutil" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/icmd" "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/convert" "github.com/docker/compose-cli/aci/login" "github.com/docker/compose-cli/api/containers" "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/pkg/api" . "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) { res := c.RunDockerOrExitError("context", "create", "aci", "fail-context") 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`, }) }) diff --git a/aci/login/client.go b/aci/login/client.go index 0d6bafd4f..dbc1bd4fd 100644 --- a/aci/login/client.go +++ b/aci/login/client.go @@ -30,8 +30,8 @@ import ( "github.com/Azure/go-autorest/autorest/date" "github.com/pkg/errors" - "github.com/docker/compose-cli/api/errdefs" "github.com/docker/compose-cli/internal" + "github.com/docker/compose-cli/pkg/api" ) // NewContainerGroupsClient get client toi manipulate containerGrouos @@ -88,7 +88,7 @@ func NewFileShareClient(subscriptionID string) (storage.FileSharesClient, error) func NewSubscriptionsClient() (subscription.SubscriptionsClient, error) { authorizer, mgmtURL, err := getClientSetupData() 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) setupClient(&subc.Client, authorizer) diff --git a/aci/login/login.go b/aci/login/login.go index 805b84239..a4dffce1d 100644 --- a/aci/login/login.go +++ b/aci/login/login.go @@ -25,12 +25,12 @@ import ( "os" "time" + "github.com/docker/compose-cli/pkg/api" + "github.com/Azure/go-autorest/autorest/adal" "github.com/Azure/go-autorest/autorest/azure/auth" "github.com/pkg/errors" "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 @@ -98,20 +98,20 @@ func (login *azureLoginService) LoginServicePrincipal(clientID string, clientSec spToken, err := creds.ServicePrincipalToken() 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() 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()) 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} 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 } @@ -134,28 +134,28 @@ func (login *azureLoginService) getTenantAndValidateLogin( ) error { bits, statusCode, err := login.apiHelper.queryAPIWithHeader(ctx, ce.GetTenantQueryURL(), fmt.Sprintf("Bearer %s", accessToken)) 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 { - 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 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) if err != nil { - return errors.Wrap(errdefs.ErrLoginFailed, err.Error()) + return errors.Wrap(api.ErrLoginFailed, err.Error()) } tToken, err := login.refreshToken(refreshToken, tenantID, ce) 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} 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 } @@ -177,7 +177,7 @@ func (login *azureLoginService) Login(ctx context.Context, requestedTenantID str redirectURL := s.Addr() if redirectURL == "" { - return errors.Wrap(errdefs.ErrLoginFailed, "empty redirect URL") + return errors.Wrap(api.ErrLoginFailed, "empty redirect URL") } deviceCodeFlowCh := make(chan deviceCodeFlowResponse, 1) @@ -190,17 +190,17 @@ func (login *azureLoginService) Login(ctx context.Context, requestedTenantID str return ctx.Err() case dcft := <-deviceCodeFlowCh: 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 return login.getTenantAndValidateLogin(ctx, token.AccessToken, token.RefreshToken, requestedTenantID, ce) case q := <-queryCh: 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"] if !hasCode { - return errors.Wrap(errdefs.ErrLoginFailed, "no login code") + return errors.Wrap(api.ErrLoginFailed, "no login code") } data := url.Values{ "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") 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) } diff --git a/aci/volumes.go b/aci/volumes.go index caa2bc0fa..13c9d9a74 100644 --- a/aci/volumes.go +++ b/aci/volumes.go @@ -30,9 +30,9 @@ import ( "github.com/docker/compose-cli/aci/login" "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/pkg/api" ) 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, "") if err == nil { 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) { 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 { result, err := storageAccountsClient.Delete(ctx, cs.aciContext.ResourceGroup, storageAccount) 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 } @@ -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) if result.HasHTTPStatus(http.StatusNoContent) { - return errors.Wrapf(errdefs.ErrNotFound, "fileshare %q", fileshare) + return errors.Wrapf(api.ErrNotFound, "fileshare %q", fileshare) } 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, "") if err != nil { // Just checks if it exists 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 } diff --git a/api/backend/backend.go b/api/backend/backend.go index 94e7d0a0e..c278a3c06 100644 --- a/api/backend/backend.go +++ b/api/backend/backend.go @@ -23,12 +23,11 @@ import ( "github.com/sirupsen/logrus" "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/errdefs" "github.com/docker/compose-cli/api/resources" "github.com/docker/compose-cli/api/secrets" "github.com/docker/compose-cli/api/volumes" + "github.com/docker/compose-cli/pkg/api" ) var ( @@ -66,7 +65,7 @@ func WithBackend(s Service) { // Service aggregates the service interfaces type Service interface { ContainerService() containers.Service - ComposeService() compose.Service + ComposeService() api.Service ResourceService() resources.Service SecretsService() secrets.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 diff --git a/api/client/client.go b/api/client/client.go index faf081c42..67144f34f 100644 --- a/api/client/client.go +++ b/api/client/client.go @@ -21,14 +21,13 @@ import ( "github.com/docker/compose-cli/api/backend" "github.com/docker/compose-cli/api/cloud" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/containers" apicontext "github.com/docker/compose-cli/api/context" "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/secrets" "github.com/docker/compose-cli/api/volumes" + "github.com/docker/compose-cli/pkg/api" ) // New returns a backend client associated with current context @@ -43,7 +42,7 @@ func New(ctx context.Context) (*Client, error) { service := backend.Current() if service == nil { - return nil, errdefs.ErrNotFound + return nil, api.ErrNotFound } client := NewClient(cc.Type(), service) @@ -84,7 +83,7 @@ func (c *Client) ContainerService() containers.Service { } // 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 { return cs } diff --git a/api/client/compose.go b/api/client/compose.go index 84f09d400..1b6f58216 100644 --- a/api/client/compose.go +++ b/api/client/compose.go @@ -19,107 +19,105 @@ package client import ( "context" - "github.com/docker/compose-cli/api/compose" - "github.com/docker/compose-cli/api/errdefs" - "github.com/compose-spec/compose-go/types" + "github.com/docker/compose-cli/pkg/api" ) type composeService struct { } -func (c *composeService) Build(ctx context.Context, project *types.Project, options compose.BuildOptions) error { - return errdefs.ErrNotImplemented +func (c *composeService) Build(ctx context.Context, project *types.Project, options api.BuildOptions) error { + return api.ErrNotImplemented } -func (c *composeService) Push(ctx context.Context, project *types.Project, options compose.PushOptions) error { - return errdefs.ErrNotImplemented +func (c *composeService) Push(ctx context.Context, project *types.Project, options api.PushOptions) error { + return api.ErrNotImplemented } -func (c *composeService) Pull(ctx context.Context, project *types.Project, options compose.PullOptions) error { - return errdefs.ErrNotImplemented +func (c *composeService) Pull(ctx context.Context, project *types.Project, options api.PullOptions) error { + return api.ErrNotImplemented } -func (c *composeService) Create(ctx context.Context, project *types.Project, opts compose.CreateOptions) error { - return errdefs.ErrNotImplemented +func (c *composeService) Create(ctx context.Context, project *types.Project, opts api.CreateOptions) error { + return api.ErrNotImplemented } -func (c *composeService) Start(ctx context.Context, project *types.Project, options compose.StartOptions) error { - return errdefs.ErrNotImplemented +func (c *composeService) Start(ctx context.Context, project *types.Project, options api.StartOptions) error { + return api.ErrNotImplemented } -func (c *composeService) Restart(ctx context.Context, project *types.Project, options compose.RestartOptions) error { - return errdefs.ErrNotImplemented +func (c *composeService) Restart(ctx context.Context, project *types.Project, options api.RestartOptions) error { + return api.ErrNotImplemented } -func (c *composeService) Stop(ctx context.Context, project *types.Project, options compose.StopOptions) error { - return errdefs.ErrNotImplemented +func (c *composeService) Stop(ctx context.Context, project *types.Project, options api.StopOptions) error { + return api.ErrNotImplemented } -func (c *composeService) Up(context.Context, *types.Project, compose.UpOptions) error { - return errdefs.ErrNotImplemented +func (c *composeService) Up(context.Context, *types.Project, api.UpOptions) error { + return api.ErrNotImplemented } -func (c *composeService) Down(context.Context, string, compose.DownOptions) error { - return errdefs.ErrNotImplemented +func (c *composeService) Down(context.Context, string, api.DownOptions) error { + return api.ErrNotImplemented } -func (c *composeService) Logs(context.Context, string, compose.LogConsumer, compose.LogOptions) error { - return errdefs.ErrNotImplemented +func (c *composeService) Logs(context.Context, string, api.LogConsumer, api.LogOptions) error { + return api.ErrNotImplemented } -func (c *composeService) Ps(context.Context, string, compose.PsOptions) ([]compose.ContainerSummary, error) { - return nil, errdefs.ErrNotImplemented +func (c *composeService) Ps(context.Context, string, api.PsOptions) ([]api.ContainerSummary, error) { + return nil, api.ErrNotImplemented } -func (c *composeService) List(context.Context, compose.ListOptions) ([]compose.Stack, error) { - return nil, errdefs.ErrNotImplemented +func (c *composeService) List(context.Context, api.ListOptions) ([]api.Stack, error) { + return nil, api.ErrNotImplemented } -func (c *composeService) Convert(context.Context, *types.Project, compose.ConvertOptions) ([]byte, error) { - return nil, errdefs.ErrNotImplemented +func (c *composeService) Convert(context.Context, *types.Project, api.ConvertOptions) ([]byte, error) { + return nil, api.ErrNotImplemented } -func (c *composeService) Kill(ctx context.Context, project *types.Project, options compose.KillOptions) error { - return errdefs.ErrNotImplemented +func (c *composeService) Kill(ctx context.Context, project *types.Project, options api.KillOptions) error { + return api.ErrNotImplemented } -func (c *composeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { - return 0, errdefs.ErrNotImplemented +func (c *composeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) { + return 0, api.ErrNotImplemented } -func (c *composeService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) error { - return errdefs.ErrNotImplemented +func (c *composeService) Remove(ctx context.Context, project *types.Project, options api.RemoveOptions) error { + return api.ErrNotImplemented } -func (c *composeService) Exec(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { - return 0, errdefs.ErrNotImplemented +func (c *composeService) Exec(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) { + return 0, api.ErrNotImplemented } -func (c *composeService) Copy(ctx context.Context, project *types.Project, opts compose.CopyOptions) error { - return errdefs.ErrNotImplemented +func (c *composeService) Copy(ctx context.Context, project *types.Project, opts api.CopyOptions) error { + return api.ErrNotImplemented } -func (c *composeService) Pause(ctx context.Context, project string, options compose.PauseOptions) error { - return errdefs.ErrNotImplemented +func (c *composeService) Pause(ctx context.Context, project string, options api.PauseOptions) error { + return api.ErrNotImplemented } -func (c *composeService) UnPause(ctx context.Context, project string, options compose.PauseOptions) error { - return errdefs.ErrNotImplemented +func (c *composeService) UnPause(ctx context.Context, project string, options api.PauseOptions) error { + return api.ErrNotImplemented } -func (c *composeService) Top(ctx context.Context, projectName string, services []string) ([]compose.ContainerProcSummary, error) { - return nil, errdefs.ErrNotImplemented +func (c *composeService) Top(ctx context.Context, projectName string, services []string) ([]api.ContainerProcSummary, error) { + return nil, api.ErrNotImplemented } -func (c *composeService) Events(ctx context.Context, project string, options compose.EventsOptions) error { - return errdefs.ErrNotImplemented +func (c *composeService) Events(ctx context.Context, project string, options api.EventsOptions) error { + return api.ErrNotImplemented } -func (c *composeService) Port(ctx context.Context, project string, service string, port int, options compose.PortOptions) (string, int, error) { - return "", 0, errdefs.ErrNotImplemented +func (c *composeService) Port(ctx context.Context, project string, service string, port int, options api.PortOptions) (string, int, error) { + return "", 0, api.ErrNotImplemented } -func (c *composeService) Images(ctx context.Context, projectName string, options compose.ImagesOptions) ([]compose.ImageSummary, error) { - return nil, errdefs.ErrNotImplemented +func (c *composeService) Images(ctx context.Context, projectName string, options api.ImagesOptions) ([]api.ImageSummary, error) { + return nil, api.ErrNotImplemented } diff --git a/api/client/containers.go b/api/client/containers.go index 1b1e665b8..5269c390d 100644 --- a/api/client/containers.go +++ b/api/client/containers.go @@ -20,7 +20,7 @@ import ( "context" "github.com/docker/compose-cli/api/containers" - "github.com/docker/compose-cli/api/errdefs" + "github.com/docker/compose-cli/pkg/api" ) type containerService struct { @@ -28,44 +28,44 @@ type containerService struct { // List returns all the containers func (c *containerService) List(context.Context, bool) ([]containers.Container, error) { - return nil, errdefs.ErrNotImplemented + return nil, api.ErrNotImplemented } // Start starts a stopped container func (c *containerService) Start(context.Context, string) error { - return errdefs.ErrNotImplemented + return api.ErrNotImplemented } // Stop stops the running container 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 { - return errdefs.ErrNotImplemented + return api.ErrNotImplemented } // Run creates and starts a container func (c *containerService) Run(context.Context, containers.ContainerConfig) error { - return errdefs.ErrNotImplemented + return api.ErrNotImplemented } // Exec executes a command inside a running container func (c *containerService) Exec(context.Context, string, containers.ExecRequest) error { - return errdefs.ErrNotImplemented + return api.ErrNotImplemented } // Logs returns all the logs of a container func (c *containerService) Logs(context.Context, string, containers.LogsRequest) error { - return errdefs.ErrNotImplemented + return api.ErrNotImplemented } // Delete removes containers func (c *containerService) Delete(context.Context, string, containers.DeleteRequest) error { - return errdefs.ErrNotImplemented + return api.ErrNotImplemented } // Inspect get a specific container func (c *containerService) Inspect(context.Context, string) (containers.Container, error) { - return containers.Container{}, errdefs.ErrNotImplemented + return containers.Container{}, api.ErrNotImplemented } diff --git a/api/client/resources.go b/api/client/resources.go index 04b74219f..7f23b41bc 100644 --- a/api/client/resources.go +++ b/api/client/resources.go @@ -19,8 +19,8 @@ package client import ( "context" - "github.com/docker/compose-cli/api/errdefs" "github.com/docker/compose-cli/api/resources" + "github.com/docker/compose-cli/pkg/api" ) type resourceService struct { @@ -28,5 +28,5 @@ type resourceService struct { // Prune prune resources func (c *resourceService) Prune(ctx context.Context, request resources.PruneRequest) (resources.PruneResult, error) { - return resources.PruneResult{}, errdefs.ErrNotImplemented + return resources.PruneResult{}, api.ErrNotImplemented } diff --git a/api/client/secrets.go b/api/client/secrets.go index a263e5fde..d2545b834 100644 --- a/api/client/secrets.go +++ b/api/client/secrets.go @@ -19,25 +19,25 @@ package client import ( "context" - "github.com/docker/compose-cli/api/errdefs" "github.com/docker/compose-cli/api/secrets" + "github.com/docker/compose-cli/pkg/api" ) type secretsService struct { } 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) { - return secrets.Secret{}, errdefs.ErrNotImplemented + return secrets.Secret{}, api.ErrNotImplemented } 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 { - return errdefs.ErrNotImplemented + return api.ErrNotImplemented } diff --git a/api/client/volume.go b/api/client/volume.go index aa359754d..62cdc9d74 100644 --- a/api/client/volume.go +++ b/api/client/volume.go @@ -19,25 +19,25 @@ package client import ( "context" - "github.com/docker/compose-cli/api/errdefs" "github.com/docker/compose-cli/api/volumes" + "github.com/docker/compose-cli/pkg/api" ) type volumeService struct { } 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) { - return volumes.Volume{}, errdefs.ErrNotImplemented + return volumes.Volume{}, api.ErrNotImplemented } 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) { - return volumes.Volume{}, errdefs.ErrNotImplemented + return volumes.Volume{}, api.ErrNotImplemented } diff --git a/api/cloud/api.go b/api/cloud/api.go index aa8b7773c..e6ae7ad0f 100644 --- a/api/cloud/api.go +++ b/api/cloud/api.go @@ -19,7 +19,7 @@ package cloud import ( "context" - "github.com/docker/compose-cli/api/errdefs" + "github.com/docker/compose-cli/pkg/api" ) // Service cloud specific services @@ -42,13 +42,13 @@ type notImplementedCloudService struct { // Logout login to cloud provider func (cs notImplementedCloudService) Logout(ctx context.Context) error { - return errdefs.ErrNotImplemented + return api.ErrNotImplemented } 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) { - return nil, "", errdefs.ErrNotImplemented + return nil, "", api.ErrNotImplemented } diff --git a/api/context/store/store.go b/api/context/store/store.go index 146ed21f8..6f3cc80d4 100644 --- a/api/context/store/store.go +++ b/api/context/store/store.go @@ -24,10 +24,10 @@ import ( "path/filepath" "reflect" + "github.com/docker/compose-cli/pkg/api" + "github.com/opencontainers/go-digest" "github.com/pkg/errors" - - "github.com/docker/compose-cli/api/errdefs" ) const ( @@ -130,7 +130,7 @@ func (s *store) Get(name string) (*DockerContext, error) { meta := filepath.Join(s.root, contextsDir, metadataDir, contextDirOf(name), metaFile) m, err := read(meta) if os.IsNotExist(err) { - return nil, errors.Wrap(errdefs.ErrNotFound, objectName(name)) + return nil, errors.Wrap(api.ErrNotFound, objectName(name)) } else if err != nil { return nil, err } @@ -145,7 +145,7 @@ func (s *store) GetEndpoint(name string, data interface{}) error { } contextType := meta.Type() 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) @@ -155,7 +155,7 @@ func (s *store) GetEndpoint(name string, data interface{}) error { valIndirect := reflect.Indirect(val) if dstValue.Type() != valIndirect.Type() { - return errdefs.ErrWrongContextType + return api.ErrWrongContextType } 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 { if s.ContextExists(name) { - return errors.Wrap(errdefs.ErrAlreadyExists, objectName(name)) + return errors.Wrap(api.ErrAlreadyExists, objectName(name)) } dir := contextDirOf(name) 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 { 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)) // Check if directory exists because os.RemoveAll returns nil if it doesn't 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 { - 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 } diff --git a/api/context/store/store_test.go b/api/context/store/store_test.go index bb05b5844..54fc6a25b 100644 --- a/api/context/store/store_test.go +++ b/api/context/store/store_test.go @@ -22,10 +22,10 @@ import ( "os" "testing" + "github.com/docker/compose-cli/pkg/api" + "gotest.tools/v3/assert" "gotest.tools/v3/assert/cmp" - - "github.com/docker/compose-cli/api/errdefs" ) func testStore(t *testing.T) Store { @@ -49,7 +49,7 @@ func TestCreate(t *testing.T) { err = s.Create("test", "test", "descrsiption", ContextMetadata{}) 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) { @@ -74,7 +74,7 @@ func TestGetUnknown(t *testing.T) { meta, err := s.Get("unknown") assert.Assert(t, cmp.Nil(meta)) 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) { @@ -99,7 +99,7 @@ func TestRemoveNotFound(t *testing.T) { s := testStore(t) err := s.Remove("notfound") 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) { diff --git a/cli/cmd/compose/build.go b/cli/cmd/compose/build.go index 773296a3a..bd1a41196 100644 --- a/cli/cmd/compose/build.go +++ b/cli/cmd/compose/build.go @@ -24,7 +24,7 @@ import ( "github.com/compose-spec/compose-go/types" "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" ) type buildOptions struct { @@ -38,7 +38,7 @@ type buildOptions struct { memory string } -func buildCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func buildCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := buildOptions{ projectOptions: p, } @@ -81,13 +81,13 @@ func buildCommand(p *projectOptions, backend compose.Service) *cobra.Command { 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) if err != nil { return err } - return backend.Build(ctx, project, compose.BuildOptions{ + return backend.Build(ctx, project, api.BuildOptions{ Pull: opts.pull, Progress: opts.progress, Args: types.NewMappingWithEquals(opts.args), diff --git a/cli/cmd/compose/compose.go b/cli/cmd/compose/compose.go index 2b724061b..89a392276 100644 --- a/cli/cmd/compose/compose.go +++ b/cli/cmd/compose/compose.go @@ -33,11 +33,10 @@ import ( "github.com/spf13/cobra" "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/errdefs" "github.com/docker/compose-cli/cli/formatter" "github.com/docker/compose-cli/cli/metrics" + "github.com/docker/compose-cli/pkg/api" ) //Command defines a compose CLI command as a func with args @@ -60,7 +59,7 @@ func Adapt(fn Command) func(cmd *cobra.Command, args []string) error { } err := fn(ctx, args) var composeErr metrics.ComposeError - if errdefs.IsErrCanceled(err) || errors.Is(ctx.Err(), context.Canceled) { + if api.IsErrCanceled(err) || errors.Is(ctx.Err(), context.Canceled) { err = dockercli.StatusError{ StatusCode: 130, Status: metrics.CanceledStatus, @@ -120,7 +119,7 @@ func (o *projectOptions) WithServices(fn ProjectServicesFunc) func(cmd *cobra.Co if s.Labels == nil { s.Labels = make(map[string]string) } - s.Labels[compose.EnvironmentFileLabel] = ef + s.Labels[api.EnvironmentFileLabel] = ef services = append(services, s) } } @@ -195,7 +194,7 @@ func (o *projectOptions) toProjectOptions(po ...cli.ProjectOptionsFn) (*cli.Proj } // 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{} var ansi string var noAnsi bool diff --git a/cli/cmd/compose/convert.go b/cli/cmd/compose/convert.go index f5ce4b66e..fb15b2ca8 100644 --- a/cli/cmd/compose/convert.go +++ b/cli/cmd/compose/convert.go @@ -32,7 +32,7 @@ import ( "github.com/opencontainers/go-digest" "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/utils" ) @@ -51,7 +51,7 @@ type convertOptions struct { 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{ projectOptions: p, } @@ -104,7 +104,7 @@ func convertCommand(p *projectOptions, backend compose.Service) *cobra.Command { 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 project, err := opts.toProject(services, cli.WithInterpolation(!opts.noInterpolate)) 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, Output: opts.Output, }) diff --git a/cli/cmd/compose/cp.go b/cli/cmd/compose/cp.go index 81405cbb5..7a84209c9 100644 --- a/cli/cmd/compose/cp.go +++ b/cli/cmd/compose/cp.go @@ -23,7 +23,7 @@ import ( "github.com/docker/cli/cli" "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" ) type copyOptions struct { @@ -37,7 +37,7 @@ type copyOptions struct { copyUIDGID bool } -func copyCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func copyCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := copyOptions{ projectOptions: p, } @@ -71,13 +71,13 @@ func copyCommand(p *projectOptions, backend compose.Service) *cobra.Command { 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) if err != nil { return err } - return backend.Copy(ctx, projects, compose.CopyOptions{ + return backend.Copy(ctx, projects, api.CopyOptions{ Source: opts.source, Destination: opts.destination, All: opts.all, diff --git a/cli/cmd/compose/create.go b/cli/cmd/compose/create.go index 3bf984927..04dd31250 100644 --- a/cli/cmd/compose/create.go +++ b/cli/cmd/compose/create.go @@ -24,7 +24,7 @@ import ( "github.com/compose-spec/compose-go/types" "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" ) type createOptions struct { @@ -40,7 +40,7 @@ type createOptions struct { quietPull bool } -func createCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func createCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := createOptions{} cmd := &cobra.Command{ Use: "create [SERVICE...]", @@ -55,7 +55,7 @@ func createCommand(p *projectOptions, backend compose.Service) *cobra.Command { return nil }), 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, Recreate: opts.recreateStrategy(), RecreateDependencies: opts.dependenciesRecreateStrategy(), @@ -75,22 +75,22 @@ func createCommand(p *projectOptions, backend compose.Service) *cobra.Command { func (opts createOptions) recreateStrategy() string { if opts.noRecreate { - return compose.RecreateNever + return api.RecreateNever } if opts.forceRecreate { - return compose.RecreateForce + return api.RecreateForce } - return compose.RecreateDiverged + return api.RecreateDiverged } func (opts createOptions) dependenciesRecreateStrategy() string { if opts.noRecreate { - return compose.RecreateNever + return api.RecreateNever } if opts.recreateDeps { - return compose.RecreateForce + return api.RecreateForce } - return compose.RecreateDiverged + return api.RecreateDiverged } func (opts createOptions) GetTimeout() *time.Duration { diff --git a/cli/cmd/compose/down.go b/cli/cmd/compose/down.go index c2191c2c1..a4ca24a8b 100644 --- a/cli/cmd/compose/down.go +++ b/cli/cmd/compose/down.go @@ -24,7 +24,7 @@ import ( "github.com/compose-spec/compose-go/types" "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" ) type downOptions struct { @@ -36,7 +36,7 @@ type downOptions struct { images string } -func downCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func downCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := downOptions{ projectOptions: p, } @@ -66,7 +66,7 @@ func downCommand(p *projectOptions, backend compose.Service) *cobra.Command { 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 var project *types.Project 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 timeout = &timeoutValue } - return backend.Down(ctx, name, compose.DownOptions{ + return backend.Down(ctx, name, api.DownOptions{ RemoveOrphans: opts.removeOrphans, Project: project, Timeout: timeout, diff --git a/cli/cmd/compose/events.go b/cli/cmd/compose/events.go index a66486876..dec921e71 100644 --- a/cli/cmd/compose/events.go +++ b/cli/cmd/compose/events.go @@ -21,7 +21,7 @@ import ( "encoding/json" "fmt" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" "github.com/spf13/cobra" ) @@ -31,7 +31,7 @@ type eventsOpts struct { json bool } -func eventsCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func eventsCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := eventsOpts{ composeOptions: &composeOptions{ projectOptions: p, @@ -49,15 +49,15 @@ func eventsCommand(p *projectOptions, backend compose.Service) *cobra.Command { 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() if err != nil { return err } - return backend.Events(ctx, project, compose.EventsOptions{ + return backend.Events(ctx, project, api.EventsOptions{ Services: services, - Consumer: func(event compose.Event) error { + Consumer: func(event api.Event) error { if opts.json { marshal, err := json.Marshal(map[string]interface{}{ "time": event.Timestamp, diff --git a/cli/cmd/compose/exec.go b/cli/cmd/compose/exec.go index c9b47ee2a..7350a9a07 100644 --- a/cli/cmd/compose/exec.go +++ b/cli/cmd/compose/exec.go @@ -25,7 +25,7 @@ import ( "github.com/docker/cli/cli" "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" ) type execOpts struct { @@ -43,7 +43,7 @@ type execOpts struct { privileged bool } -func execCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func execCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := execOpts{ composeOptions: &composeOptions{ projectOptions: p, @@ -75,13 +75,13 @@ func execCommand(p *projectOptions, backend compose.Service) *cobra.Command { 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) if err != nil { return err } - execOpts := compose.RunOptions{ + execOpts := api.RunOptions{ Service: opts.service, Command: opts.command, Environment: opts.environment, diff --git a/cli/cmd/compose/images.go b/cli/cmd/compose/images.go index 39520cbe0..bc57c6803 100644 --- a/cli/cmd/compose/images.go +++ b/cli/cmd/compose/images.go @@ -26,8 +26,8 @@ import ( "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/cli/formatter" + "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/utils" "github.com/docker/docker/pkg/stringid" @@ -39,7 +39,7 @@ type imageOptions struct { Quiet bool } -func imagesCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func imagesCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := imageOptions{ projectOptions: p, } @@ -54,13 +54,13 @@ func imagesCommand(p *projectOptions, backend compose.Service) *cobra.Command { 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() if err != nil { return err } - images, err := backend.Images(ctx, projectName, compose.ImagesOptions{ + images, err := backend.Images(ctx, projectName, api.ImagesOptions{ Services: services, }) if err != nil { diff --git a/cli/cmd/compose/kill.go b/cli/cmd/compose/kill.go index 988c5da53..977cd88ae 100644 --- a/cli/cmd/compose/kill.go +++ b/cli/cmd/compose/kill.go @@ -22,11 +22,11 @@ import ( "github.com/compose-spec/compose-go/types" "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 { - var opts compose.KillOptions +func killCommand(p *projectOptions, backend api.Service) *cobra.Command { + var opts api.KillOptions cmd := &cobra.Command{ Use: "kill [options] [SERVICE...]", Short: "Force stop service containers.", diff --git a/cli/cmd/compose/list.go b/cli/cmd/compose/list.go index bcf8d3641..56ba30dee 100644 --- a/cli/cmd/compose/list.go +++ b/cli/cmd/compose/list.go @@ -26,9 +26,9 @@ import ( "github.com/docker/cli/opts" "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/cli/formatter" + "github.com/docker/compose-cli/pkg/api" ) type lsOptions struct { @@ -38,7 +38,7 @@ type lsOptions struct { 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()} lsCmd := &cobra.Command{ Use: "ls", @@ -61,14 +61,14 @@ var acceptedListFilters = map[string]bool{ "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() err := filters.Validate(acceptedListFilters) if err != nil { 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 { return err } @@ -80,7 +80,7 @@ func runList(ctx context.Context, backend compose.Service, opts lsOptions) error } if filters.Len() > 0 { - var filtered []compose.Stack + var filtered []api.Stack for _, s := range stackList { if filters.Contains("name") && !filters.Match("name", s.Name) { continue @@ -103,7 +103,7 @@ type stackView struct { Status string } -func viewFromStackList(stackList []compose.Stack) []stackView { +func viewFromStackList(stackList []api.Stack) []stackView { retList := make([]stackView, len(stackList)) for i, s := range stackList { retList[i] = stackView{ diff --git a/cli/cmd/compose/logs.go b/cli/cmd/compose/logs.go index f89b13b4e..404ef86b6 100644 --- a/cli/cmd/compose/logs.go +++ b/cli/cmd/compose/logs.go @@ -22,9 +22,9 @@ import ( "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/cli/formatter" + "github.com/docker/compose-cli/pkg/api" ) type logsOptions struct { @@ -37,7 +37,7 @@ type logsOptions struct { 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{ projectOptions: p, } @@ -60,13 +60,13 @@ func logsCommand(p *projectOptions, contextType string, backend compose.Service) 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() if err != nil { return err } 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, Follow: opts.follow, Tail: opts.tail, diff --git a/cli/cmd/compose/pause.go b/cli/cmd/compose/pause.go index 1928e06fa..66ec751e6 100644 --- a/cli/cmd/compose/pause.go +++ b/cli/cmd/compose/pause.go @@ -21,14 +21,14 @@ import ( "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" ) type pauseOptions struct { *projectOptions } -func pauseCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func pauseCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := pauseOptions{ projectOptions: p, } @@ -42,13 +42,13 @@ func pauseCommand(p *projectOptions, backend compose.Service) *cobra.Command { 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() if err != nil { return err } - return backend.Pause(ctx, project, compose.PauseOptions{ + return backend.Pause(ctx, project, api.PauseOptions{ Services: services, }) } @@ -57,7 +57,7 @@ type unpauseOptions struct { *projectOptions } -func unpauseCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func unpauseCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := unpauseOptions{ projectOptions: p, } @@ -71,13 +71,13 @@ func unpauseCommand(p *projectOptions, backend compose.Service) *cobra.Command { 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() if err != nil { return err } - return backend.UnPause(ctx, project, compose.PauseOptions{ + return backend.UnPause(ctx, project, api.PauseOptions{ Services: services, }) } diff --git a/cli/cmd/compose/port.go b/cli/cmd/compose/port.go index 497c353b6..e1556d96d 100644 --- a/cli/cmd/compose/port.go +++ b/cli/cmd/compose/port.go @@ -23,7 +23,7 @@ import ( "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" ) type portOptions struct { @@ -33,7 +33,7 @@ type portOptions struct { index int } -func portCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func portCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := portOptions{ projectOptions: p, } @@ -58,12 +58,12 @@ func portCommand(p *projectOptions, backend compose.Service) *cobra.Command { 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() if err != nil { 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, Index: opts.index, }) diff --git a/cli/cmd/compose/ps.go b/cli/cmd/compose/ps.go index 1379bce21..5660b3fe2 100644 --- a/cli/cmd/compose/ps.go +++ b/cli/cmd/compose/ps.go @@ -26,8 +26,8 @@ import ( "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/cli/formatter" + "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/utils" ) @@ -39,7 +39,7 @@ type psOptions struct { Services bool } -func psCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func psCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := psOptions{ projectOptions: p, } @@ -57,12 +57,12 @@ func psCommand(p *projectOptions, backend compose.Service) *cobra.Command { 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() if err != nil { return err } - containers, err := backend.Ps(ctx, projectName, compose.PsOptions{ + containers, err := backend.Ps(ctx, projectName, api.PsOptions{ All: opts.All, Services: services, }) diff --git a/cli/cmd/compose/pull.go b/cli/cmd/compose/pull.go index 5dce96ba9..b5cc47fdf 100644 --- a/cli/cmd/compose/pull.go +++ b/cli/cmd/compose/pull.go @@ -24,7 +24,7 @@ import ( "github.com/morikuni/aec" "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/utils" ) @@ -38,7 +38,7 @@ type pullOptions struct { ignorePullFailures bool } -func pullCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func pullCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := pullOptions{ projectOptions: p, } @@ -66,7 +66,7 @@ func pullCommand(p *projectOptions, backend compose.Service) *cobra.Command { 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) if err != nil { return err @@ -85,7 +85,7 @@ func runPull(ctx context.Context, backend compose.Service, opts pullOptions, ser project.Services = enabled } - return backend.Pull(ctx, project, compose.PullOptions{ + return backend.Pull(ctx, project, api.PullOptions{ Quiet: opts.quiet, IgnoreFailures: opts.ignorePullFailures, }) diff --git a/cli/cmd/compose/push.go b/cli/cmd/compose/push.go index f7cefd70c..5632bb649 100644 --- a/cli/cmd/compose/push.go +++ b/cli/cmd/compose/push.go @@ -21,7 +21,7 @@ import ( "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" ) type pushOptions struct { @@ -31,7 +31,7 @@ type pushOptions struct { Ignorefailures bool } -func pushCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func pushCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := pushOptions{ projectOptions: p, } @@ -47,13 +47,13 @@ func pushCommand(p *projectOptions, backend compose.Service) *cobra.Command { 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) if err != nil { return err } - return backend.Push(ctx, project, compose.PushOptions{ + return backend.Push(ctx, project, api.PushOptions{ IgnoreFailures: opts.Ignorefailures, }) } diff --git a/cli/cmd/compose/remove.go b/cli/cmd/compose/remove.go index af0c46e91..ed5a9654d 100644 --- a/cli/cmd/compose/remove.go +++ b/cli/cmd/compose/remove.go @@ -19,7 +19,7 @@ package compose import ( "context" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" "github.com/spf13/cobra" ) @@ -30,7 +30,7 @@ type removeOptions struct { volumes bool } -func removeCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func removeCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := removeOptions{ projectOptions: p, } @@ -57,19 +57,19 @@ Any data which is not in a volume will be lost.`, 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) if err != nil { return err } if opts.stop { - return backend.Stop(ctx, project, compose.StopOptions{ + return backend.Stop(ctx, project, api.StopOptions{ Services: services, }) } - return backend.Remove(ctx, project, compose.RemoveOptions{ + return backend.Remove(ctx, project, api.RemoveOptions{ Services: services, }) } diff --git a/cli/cmd/compose/restart.go b/cli/cmd/compose/restart.go index ad10e2261..891c2f0b9 100644 --- a/cli/cmd/compose/restart.go +++ b/cli/cmd/compose/restart.go @@ -22,7 +22,7 @@ import ( "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" ) type restartOptions struct { @@ -30,7 +30,7 @@ type restartOptions struct { timeout int } -func restartCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func restartCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := restartOptions{ projectOptions: p, } @@ -47,14 +47,14 @@ func restartCommand(p *projectOptions, backend compose.Service) *cobra.Command { 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) if err != nil { return err } timeout := time.Duration(opts.timeout) * time.Second - return backend.Restart(ctx, project, compose.RestartOptions{ + return backend.Restart(ctx, project, api.RestartOptions{ Timeout: &timeout, Services: services, }) diff --git a/cli/cmd/compose/run.go b/cli/cmd/compose/run.go index 6504d5c7f..397f64991 100644 --- a/cli/cmd/compose/run.go +++ b/cli/cmd/compose/run.go @@ -29,8 +29,8 @@ import ( "github.com/spf13/cobra" "github.com/docker/cli/cli" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/progress" + "github.com/docker/compose-cli/pkg/api" ) type runOptions struct { @@ -100,7 +100,7 @@ func (opts runOptions) apply(project *types.Project) error { return nil } -func runCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func runCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := runOptions{ composeOptions: &composeOptions{ projectOptions: p, @@ -152,7 +152,7 @@ func notAtTTY() bool { 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) if err != nil { return err @@ -183,7 +183,7 @@ func runRun(ctx context.Context, backend compose.Service, project *types.Project } // start container and attach to container streams - runOpts := compose.RunOptions{ + runOpts := api.RunOptions{ Name: opts.name, Service: opts.Service, Command: opts.Command, @@ -211,7 +211,7 @@ func runRun(ctx context.Context, backend compose.Service, project *types.Project 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{} var requestedService types.ServiceConfig for _, service := range project.Services { @@ -224,8 +224,8 @@ func startDependencies(ctx context.Context, backend compose.Service, project typ project.Services = dependencies 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 backend.Start(ctx, &project, compose.StartOptions{}) + return backend.Start(ctx, &project, api.StartOptions{}) } diff --git a/cli/cmd/compose/start.go b/cli/cmd/compose/start.go index 5ebbb923e..57e48f811 100644 --- a/cli/cmd/compose/start.go +++ b/cli/cmd/compose/start.go @@ -19,7 +19,7 @@ package compose import ( "context" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" "github.com/spf13/cobra" ) @@ -27,7 +27,7 @@ type startOptions struct { *projectOptions } -func startCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func startCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := startOptions{ projectOptions: p, } @@ -41,11 +41,11 @@ func startCommand(p *projectOptions, backend compose.Service) *cobra.Command { 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) if err != nil { return err } - return backend.Start(ctx, project, compose.StartOptions{}) + return backend.Start(ctx, project, api.StartOptions{}) } diff --git a/cli/cmd/compose/stop.go b/cli/cmd/compose/stop.go index 195eafb27..d8a08c2f4 100644 --- a/cli/cmd/compose/stop.go +++ b/cli/cmd/compose/stop.go @@ -22,7 +22,7 @@ import ( "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" ) type stopOptions struct { @@ -31,7 +31,7 @@ type stopOptions struct { timeout int } -func stopCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func stopCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := stopOptions{ projectOptions: p, } @@ -51,7 +51,7 @@ func stopCommand(p *projectOptions, backend compose.Service) *cobra.Command { 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) if err != nil { return err @@ -62,7 +62,7 @@ func runStop(ctx context.Context, backend compose.Service, opts stopOptions, ser timeoutValue := time.Duration(opts.timeout) * time.Second timeout = &timeoutValue } - return backend.Stop(ctx, project, compose.StopOptions{ + return backend.Stop(ctx, project, api.StopOptions{ Timeout: timeout, Services: services, }) diff --git a/cli/cmd/compose/top.go b/cli/cmd/compose/top.go index 1d6518ea6..ab81dd64c 100644 --- a/cli/cmd/compose/top.go +++ b/cli/cmd/compose/top.go @@ -27,14 +27,14 @@ import ( "github.com/spf13/cobra" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" ) type topOptions struct { *projectOptions } -func topCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func topCommand(p *projectOptions, backend api.Service) *cobra.Command { opts := topOptions{ projectOptions: p, } @@ -48,7 +48,7 @@ func topCommand(p *projectOptions, backend compose.Service) *cobra.Command { 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() if err != nil { return err diff --git a/cli/cmd/compose/up.go b/cli/cmd/compose/up.go index f4845b80d..dd0309378 100644 --- a/cli/cmd/compose/up.go +++ b/cli/cmd/compose/up.go @@ -24,8 +24,8 @@ import ( "strings" "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/pkg/api" "github.com/docker/compose-cli/utils" "github.com/spf13/cobra" ) @@ -89,7 +89,7 @@ func (opts upOptions) apply(project *types.Project, services []string) error { return nil } -func upCommand(p *projectOptions, backend compose.Service) *cobra.Command { +func upCommand(p *projectOptions, backend api.Service) *cobra.Command { up := upOptions{} create := createOptions{} upCmd := &cobra.Command{ @@ -144,7 +144,7 @@ func upCommand(p *projectOptions, backend compose.Service) *cobra.Command { 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 { return fmt.Errorf("no service selected") } @@ -156,7 +156,7 @@ func runUp(ctx context.Context, backend compose.Service, createOptions createOpt return err } - var consumer compose.LogConsumer + var consumer api.LogConsumer if !upOptions.Detach { consumer = formatter.NewLogConsumer(ctx, os.Stdout, !upOptions.noColor, !upOptions.noPrefix) } @@ -166,7 +166,7 @@ func runUp(ctx context.Context, backend compose.Service, createOptions createOpt attachTo = project.ServiceNames() } - create := compose.CreateOptions{ + create := api.CreateOptions{ RemoveOrphans: createOptions.removeOrphans, Recreate: createOptions.recreateStrategy(), RecreateDependencies: createOptions.dependenciesRecreateStrategy(), @@ -179,9 +179,9 @@ func runUp(ctx context.Context, backend compose.Service, createOptions createOpt return backend.Create(ctx, project, create) } - return backend.Up(ctx, project, compose.UpOptions{ + return backend.Up(ctx, project, api.UpOptions{ Create: create, - Start: compose.StartOptions{ + Start: api.StartOptions{ Attach: consumer, AttachTo: attachTo, ExitCodeFrom: upOptions.exitCodeFrom, diff --git a/cli/cmd/context/create_aci.go b/cli/cmd/context/create_aci.go index 775fd8103..0a06a24fc 100644 --- a/cli/cmd/context/create_aci.go +++ b/cli/cmd/context/create_aci.go @@ -25,7 +25,7 @@ import ( "github.com/docker/compose-cli/aci" "github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/context/store" - "github.com/docker/compose-cli/api/errdefs" + "github.com/docker/compose-cli/pkg/api" ) func init() { @@ -58,7 +58,7 @@ func createAciCommand() *cobra.Command { func runCreateAci(ctx context.Context, contextName string, opts aci.ContextParams) error { 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) if err != nil { diff --git a/cli/cmd/context/create_ecs.go b/cli/cmd/context/create_ecs.go index 6570020e4..eabf24e41 100644 --- a/cli/cmd/context/create_ecs.go +++ b/cli/cmd/context/create_ecs.go @@ -28,8 +28,8 @@ import ( "github.com/docker/compose-cli/api/client" "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/pkg/api" ) 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 { 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) 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 { 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) if err != nil { diff --git a/cli/cmd/context/create_kube.go b/cli/cmd/context/create_kube.go index 1eb269cd7..d878d695b 100644 --- a/cli/cmd/context/create_kube.go +++ b/cli/cmd/context/create_kube.go @@ -19,11 +19,11 @@ package context import ( + "github.com/docker/compose-cli/pkg/api" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/docker/compose-cli/api/context/store" - "github.com/docker/compose-cli/api/errdefs" "github.com/docker/compose-cli/kube" ) @@ -56,7 +56,7 @@ func createKubeCommand() *cobra.Command { func runCreateKube(contextName string, opts kube.ContextParams) error { if contextExists(contextName) { - return errors.Wrapf(errdefs.ErrAlreadyExists, "context %q", contextName) + return errors.Wrapf(api.ErrAlreadyExists, "context %q", contextName) } contextData, description, err := opts.CreateContextData() diff --git a/cli/cmd/context/update.go b/cli/cmd/context/update.go index 52e3bf7ee..e71bc105c 100644 --- a/cli/cmd/context/update.go +++ b/cli/cmd/context/update.go @@ -17,11 +17,11 @@ package context import ( + "github.com/docker/compose-cli/pkg/api" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/docker/compose-cli/api/context/store" - "github.com/docker/compose-cli/api/errdefs" "github.com/docker/compose-cli/cli/mobycli" ) @@ -76,7 +76,7 @@ func runUpdate(cmd *cobra.Command, name string) error { dockerContext, err := s.Get(name) if err == nil && dockerContext != nil { 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()) } } diff --git a/cli/cmd/kill.go b/cli/cmd/kill.go index 0de597d77..b836da3ae 100644 --- a/cli/cmd/kill.go +++ b/cli/cmd/kill.go @@ -25,8 +25,8 @@ import ( "github.com/spf13/cobra" "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/pkg/api" ) type killOpts struct { @@ -60,7 +60,7 @@ func runKill(ctx context.Context, args []string, opts killOpts) error { for _, id := range args { err := c.ContainerService().Kill(ctx, id, opts.signal) if err != nil { - if errdefs.IsNotFoundError(err) { + if api.IsNotFoundError(err) { errs = multierror.Append(errs, fmt.Errorf("container %s not found", id)) } else { errs = multierror.Append(errs, err) diff --git a/cli/cmd/login/login.go b/cli/cmd/login/login.go index e672e01be..d74504828 100644 --- a/cli/cmd/login/login.go +++ b/cli/cmd/login/login.go @@ -24,8 +24,8 @@ import ( "github.com/spf13/cobra" "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/pkg/api" ) // Command returns the login command @@ -56,7 +56,7 @@ func cloudLogin(cmd *cobra.Command, backendType string, params interface{}) erro ctx := cmd.Context() cs, err := client.GetCloudService(ctx, backendType) 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) if errors.Is(err, context.Canceled) { diff --git a/cli/cmd/logout/azure.go b/cli/cmd/logout/azure.go index 2c209a496..0b998357e 100644 --- a/cli/cmd/logout/azure.go +++ b/cli/cmd/logout/azure.go @@ -24,7 +24,7 @@ import ( "github.com/spf13/cobra" "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 @@ -44,7 +44,7 @@ func cloudLogout(cmd *cobra.Command, backendType string) error { ctx := cmd.Context() cs, err := client.GetCloudService(ctx, backendType) 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) if errors.Is(err, context.Canceled) { diff --git a/cli/cmd/rm.go b/cli/cmd/rm.go index 0f38f8c7d..120d8b577 100644 --- a/cli/cmd/rm.go +++ b/cli/cmd/rm.go @@ -26,8 +26,8 @@ import ( "github.com/docker/compose-cli/api/client" "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/pkg/api" ) type rmOpts struct { @@ -63,9 +63,9 @@ func runRm(ctx context.Context, args []string, opts rmOpts) error { Force: opts.force, }) 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)) - } else if errdefs.IsNotFoundError(err) { + } else if api.IsNotFoundError(err) { errs = multierror.Append(errs, fmt.Errorf("container %s not found", id)) } else { errs = multierror.Append(errs, err) diff --git a/cli/cmd/start.go b/cli/cmd/start.go index 32e231124..76dada2df 100644 --- a/cli/cmd/start.go +++ b/cli/cmd/start.go @@ -25,8 +25,8 @@ import ( "github.com/spf13/cobra" "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/pkg/api" ) // StartCommand starts containers @@ -53,7 +53,7 @@ func runStart(ctx context.Context, args []string) error { for _, id := range args { err := c.ContainerService().Start(ctx, id) if err != nil { - if errdefs.IsNotFoundError(err) { + if api.IsNotFoundError(err) { errs = multierror.Append(errs, fmt.Errorf("container %s not found", id)) } else { errs = multierror.Append(errs, err) diff --git a/cli/cmd/stop.go b/cli/cmd/stop.go index 460a301bf..8f1c66352 100644 --- a/cli/cmd/stop.go +++ b/cli/cmd/stop.go @@ -25,8 +25,8 @@ import ( "github.com/spf13/cobra" "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/pkg/api" ) type stopOpts struct { @@ -60,7 +60,7 @@ func runStop(ctx context.Context, args []string, opts stopOpts) error { for _, id := range args { err := c.ContainerService().Stop(ctx, id, &opts.timeout) if err != nil { - if errdefs.IsNotFoundError(err) { + if api.IsNotFoundError(err) { errs = multierror.Append(errs, fmt.Errorf("container %s not found", id)) } else { errs = multierror.Append(errs, err) diff --git a/cli/formatter/formatter.go b/cli/formatter/formatter.go index b1472024a..c0452781c 100644 --- a/cli/formatter/formatter.go +++ b/cli/formatter/formatter.go @@ -22,9 +22,9 @@ import ( "reflect" "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 @@ -67,7 +67,7 @@ func Print(toJSON interface{}, format string, outWriter io.Writer, writerFn func _, _ = fmt.Fprintln(outWriter, outJSON) } 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 } diff --git a/cli/formatter/logs.go b/cli/formatter/logs.go index 56893f649..18f45cc9e 100644 --- a/cli/formatter/logs.go +++ b/cli/formatter/logs.go @@ -23,11 +23,11 @@ import ( "strconv" "strings" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" ) // 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{ ctx: ctx, presenters: map[string]*presenter{}, diff --git a/cli/main.go b/cli/main.go index 548957816..bdfe1028f 100644 --- a/cli/main.go +++ b/cli/main.go @@ -35,11 +35,9 @@ import ( "github.com/spf13/cobra" "github.com/docker/compose-cli/api/backend" - api "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/config" apicontext "github.com/docker/compose-cli/api/context" "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/compose" contextcmd "github.com/docker/compose-cli/cli/cmd/context" @@ -52,6 +50,7 @@ import ( "github.com/docker/compose-cli/cli/mobycli" cliopts "github.com/docker/compose-cli/cli/options" "github.com/docker/compose-cli/local" + api "github.com/docker/compose-cli/pkg/api" // Backend registrations _ "github.com/docker/compose-cli/aci" @@ -263,7 +262,7 @@ func getBackend(ctype string, configDir string, opts cliopts.GlobalOpts) (backen return local.GetLocalBackend(configDir, opts) } service, err := backend.Get(ctype) - if errdefs.IsNotFoundError(err) { + if api.IsNotFoundError(err) { return service, nil } return service, err @@ -271,7 +270,7 @@ 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) { // 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) os.Exit(130) } @@ -311,9 +310,9 @@ func exit(ctx string, err error, ctype string) { } metrics.Track(ctype, os.Args[1:], metricsStatus) - if errors.Is(err, errdefs.ErrLoginRequired) { + if errors.Is(err, api.ErrLoginRequired) { fmt.Fprintln(os.Stderr, err) - os.Exit(errdefs.ExitCodeLoginRequired) + os.Exit(api.ExitCodeLoginRequired) } if compose.Warning != "" { @@ -321,7 +320,7 @@ func exit(ctx string, err error, ctype string) { fmt.Fprintln(os.Stderr, compose.Warning) } - if errors.Is(err, errdefs.ErrNotImplemented) { + if errors.Is(err, api.ErrNotImplemented) { name := metrics.GetCommand(os.Args[1:]) fmt.Fprintf(os.Stderr, "Command %q not available in current context (%s)\n", name, ctx) diff --git a/cli/server/metrics_test.go b/cli/server/metrics_test.go index ab4327e4f..8c4501e2f 100644 --- a/cli/server/metrics_test.go +++ b/cli/server/metrics_test.go @@ -29,9 +29,7 @@ import ( "gotest.tools/v3/assert" "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/errdefs" "github.com/docker/compose-cli/api/secrets" "github.com/docker/compose-cli/api/volumes" "github.com/docker/compose-cli/cli/metrics" @@ -40,6 +38,7 @@ import ( streamsv1 "github.com/docker/compose-cli/cli/server/protos/streams/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/pkg/api" ) func TestAllMethodsHaveCorrespondingCliCommand(t *testing.T) { @@ -77,8 +76,8 @@ func TestTrackSFailures(t *testing.T) { interceptor := metricsServerInterceptor(mockMetrics) ctx := proxy.WithClient(incomingContext("default"), &newClient) - _, err := interceptor(ctx, nil, containerMethodRoute("Create"), mockHandler(errdefs.ErrLoginRequired)) - assert.Assert(t, err == errdefs.ErrLoginRequired) + _, err := interceptor(ctx, nil, containerMethodRoute("Create"), mockHandler(api.ErrLoginRequired)) + assert.Assert(t, err == api.ErrLoginRequired) } func containerMethodRoute(action string) *grpc.UnaryServerInfo { @@ -115,7 +114,7 @@ func setupServer() *grpc.Server { type noopService struct{} 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) VolumeService() volumes.Service { return nil } func (noopService) ResourceService() resources.Service { return nil } diff --git a/ecs/aws.go b/ecs/aws.go index 1955318dc..45b79ba08 100644 --- a/ecs/aws.go +++ b/ecs/aws.go @@ -22,8 +22,8 @@ import ( "github.com/aws/aws-sdk-go/service/cloudformation" "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/pkg/api" ) const ( @@ -49,7 +49,7 @@ type API interface { UpdateStack(ctx context.Context, changeset string) error WaitStackComplete(ctx context.Context, name string, operation int) 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) GetServiceTaskDefinition(ctx context.Context, cluster string, serviceArns []string) (map[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) 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 - DescribeService(ctx context.Context, cluster string, arn string) (compose.ServiceStatus, error) - DescribeServiceTasks(ctx context.Context, cluster string, project string, service string) ([]compose.ContainerSummary, error) - getURLWithPortMapping(ctx context.Context, targetGroupArns []string) ([]compose.PortPublisher, error) + DescribeService(ctx context.Context, cluster string, arn string) (api.ServiceStatus, error) + DescribeServiceTasks(ctx context.Context, cluster string, project string, service string) ([]api.ContainerSummary, error) + getURLWithPortMapping(ctx context.Context, targetGroupArns []string) ([]api.PortPublisher, error) ListTasks(ctx context.Context, cluster string, family string) ([]string, error) GetPublicIPs(ctx context.Context, interfaces ...string) (map[string]string, error) ResolveLoadBalancer(ctx context.Context, nameOrArn string) (awsResource, string, string, []awsResource, error) diff --git a/ecs/awsResources.go b/ecs/awsResources.go index bdc50592b..dfb0e4c1b 100644 --- a/ecs/awsResources.go +++ b/ecs/awsResources.go @@ -22,9 +22,6 @@ import ( "strconv" "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/service/elbv2" "github.com/awslabs/goformation/v4/cloudformation" @@ -33,6 +30,7 @@ import ( "github.com/awslabs/goformation/v4/cloudformation/efs" "github.com/awslabs/goformation/v4/cloudformation/elasticloadbalancingv2" "github.com/compose-spec/compose-go/types" + "github.com/docker/compose-cli/pkg/api" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -156,7 +154,7 @@ func (b *ecsAPIService) parseClusterExtension(ctx context.Context, project *type return nil, err } 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() @@ -268,7 +266,7 @@ func (b *ecsAPIService) parseExternalNetworks(ctx context.Context, project *type return nil, err } 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 } @@ -289,8 +287,8 @@ func (b *ecsAPIService) parseExternalVolumes(ctx context.Context, project *types logrus.Debugf("searching for existing filesystem as volume %q", name) tags := map[string]string{ - compose.ProjectLabel: project.Name, - compose.VolumeLabel: name, + api.ProjectLabel: project.Name, + api.VolumeLabel: name, } previous, err := b.aws.ListFileSystems(ctx, tags) if err != nil { @@ -397,11 +395,11 @@ func (b *ecsAPIService) ensureVolumes(r *awsResources, project *types.Project, t FileSystemPolicy: nil, FileSystemTags: []efs.FileSystem_ElasticFileSystemTag{ { - Key: compose.ProjectLabel, + Key: api.ProjectLabel, Value: project.Name, }, { - Key: compose.VolumeLabel, + Key: api.VolumeLabel, Value: name, }, { diff --git a/ecs/aws_mock.go b/ecs/aws_mock.go index 03c5e322c..3e16ae51f 100644 --- a/ecs/aws_mock.go +++ b/ecs/aws_mock.go @@ -8,8 +8,8 @@ import ( context "context" cloudformation "github.com/aws/aws-sdk-go/service/cloudformation" 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" + compose "github.com/docker/compose-cli/pkg/api" gomock "github.com/golang/mock/gomock" reflect "reflect" ) diff --git a/ecs/backend.go b/ecs/backend.go index a0663c745..7fd06d0a6 100644 --- a/ecs/backend.go +++ b/ecs/backend.go @@ -23,14 +23,13 @@ import ( "github.com/docker/compose-cli/api/backend" "github.com/docker/compose-cli/api/cloud" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/containers" apicontext "github.com/docker/compose-cli/api/context" "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/secrets" "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/session" @@ -125,7 +124,7 @@ func (b *ecsAPIService) ContainerService() containers.Service { return nil } -func (b *ecsAPIService) ComposeService() compose.Service { +func (b *ecsAPIService) ComposeService() api.Service { return b } @@ -149,11 +148,11 @@ type ecsCloudService struct { } func (a ecsCloudService) Login(ctx context.Context, params interface{}) error { - return errdefs.ErrNotImplemented + return api.ErrNotImplemented } 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) { diff --git a/ecs/cloudformation.go b/ecs/cloudformation.go index 99d1af435..8577fbd0d 100644 --- a/ecs/cloudformation.go +++ b/ecs/cloudformation.go @@ -23,10 +23,6 @@ import ( "regexp" "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" "github.com/aws/aws-sdk-go/service/elbv2" cloudmapapi "github.com/aws/aws-sdk-go/service/servicediscovery" @@ -42,16 +38,18 @@ import ( "github.com/compose-spec/compose-go/types" "github.com/distribution/distribution/v3/reference" 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" "sigs.k8s.io/kustomize/kyaml/yaml" "sigs.k8s.io/kustomize/kyaml/yaml/merge2" ) -func (b *ecsAPIService) Kill(ctx context.Context, project *types.Project, options compose.KillOptions) error { - return errdefs.ErrNotImplemented +func (b *ecsAPIService) Kill(ctx context.Context, project *types.Project, options api.KillOptions) error { + 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) if err != nil { return nil, err diff --git a/ecs/cloudformation_test.go b/ecs/cloudformation_test.go index f00004231..eb70773bb 100644 --- a/ecs/cloudformation_test.go +++ b/ecs/cloudformation_test.go @@ -23,7 +23,7 @@ import ( "reflect" "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/awslabs/goformation/v4/cloudformation" @@ -406,8 +406,8 @@ volumes: provisioned_throughput: 1024 `, useDefaultVPC, func(m *MockAPIMockRecorder) { m.ListFileSystems(gomock.Any(), map[string]string{ - compose.ProjectLabel: t.Name(), - compose.VolumeLabel: "db-data", + api.ProjectLabel: t.Name(), + api.VolumeLabel: "db-data", }).Return(nil, nil) }) n := volumeResourceName("db-data") @@ -452,8 +452,8 @@ volumes: db-data: {} `, useDefaultVPC, func(m *MockAPIMockRecorder) { m.ListFileSystems(gomock.Any(), map[string]string{ - compose.ProjectLabel: t.Name(), - compose.VolumeLabel: "db-data", + api.ProjectLabel: t.Name(), + api.VolumeLabel: "db-data", }).Return([]awsResource{ existingAWSResource{ id: "fs-123abc", @@ -521,7 +521,7 @@ services: for i := 0; i < tags.Len(); i++ { k := tags.Index(i).FieldByName("Key").String() v := tags.Index(i).FieldByName("Value").String() - if k == compose.ProjectLabel { + if k == api.ProjectLabel { assert.Equal(t, v, t.Name()) } } diff --git a/ecs/context.go b/ecs/context.go index e1f43f3ea..1b07a9b93 100644 --- a/ecs/context.go +++ b/ecs/context.go @@ -25,7 +25,7 @@ import ( "strings" "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/AlecAivazis/survey/v2/terminal" @@ -92,7 +92,7 @@ func (h contextCreateAWSHelper) createContextData(_ context.Context, opts Contex return nil, "", err } 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 { // interactive @@ -117,7 +117,7 @@ func (h contextCreateAWSHelper) createContextData(_ context.Context, opts Contex selected, err := h.user.Select("Create a Docker context using:", options) if err != nil { if err == terminal.InterruptErr { - return nil, "", errdefs.ErrCanceled + return nil, "", api.ErrCanceled } return nil, "", err } @@ -290,7 +290,7 @@ func (h contextCreateAWSHelper) chooseProfile(profiles []string) (string, error) selected, err := h.user.Select("Select AWS Profile", options) if err != nil { if err == terminal.InterruptErr { - return "", errdefs.ErrCanceled + return "", api.ErrCanceled } return "", err } diff --git a/ecs/down.go b/ecs/down.go index d7acecdd3..a399cffbf 100644 --- a/ecs/down.go +++ b/ecs/down.go @@ -21,17 +21,16 @@ import ( "github.com/pkg/errors" - "github.com/docker/compose-cli/api/compose" - "github.com/docker/compose-cli/api/errdefs" "github.com/docker/compose-cli/api/progress" + "github.com/docker/compose-cli/pkg/api" ) -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 { - 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 != "" { - 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 b.down(ctx, projectName) diff --git a/ecs/exec.go b/ecs/exec.go index 829ed3ed3..9fc7c479c 100644 --- a/ecs/exec.go +++ b/ecs/exec.go @@ -21,10 +21,9 @@ import ( "github.com/compose-spec/compose-go/types" - "github.com/docker/compose-cli/api/compose" - "github.com/docker/compose-cli/api/errdefs" + "github.com/docker/compose-cli/pkg/api" ) -func (b *ecsAPIService) Exec(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { - return 0, errdefs.ErrNotImplemented +func (b *ecsAPIService) Exec(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) { + return 0, api.ErrNotImplemented } diff --git a/ecs/images.go b/ecs/images.go index 49447dc73..d713047e6 100644 --- a/ecs/images.go +++ b/ecs/images.go @@ -19,10 +19,9 @@ package ecs import ( "context" - "github.com/docker/compose-cli/api/compose" - "github.com/docker/compose-cli/api/errdefs" + "github.com/docker/compose-cli/pkg/api" ) -func (b *ecsAPIService) Images(ctx context.Context, projectName string, options compose.ImagesOptions) ([]compose.ImageSummary, error) { - return nil, errdefs.ErrNotImplemented +func (b *ecsAPIService) Images(ctx context.Context, projectName string, options api.ImagesOptions) ([]api.ImageSummary, error) { + return nil, api.ErrNotImplemented } diff --git a/ecs/list.go b/ecs/list.go index 7af738da1..378ef9721 100644 --- a/ecs/list.go +++ b/ecs/list.go @@ -20,19 +20,19 @@ import ( "context" "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) if err != nil { return nil, err } for _, stack := range stacks { - if stack.Status == compose.STARTING { + if stack.Status == api.STARTING { if err := b.checkStackState(ctx, stack.Name); err != nil { - stack.Status = compose.FAILED + stack.Status = api.FAILED stack.Reason = err.Error() } } diff --git a/ecs/local/backend.go b/ecs/local/backend.go index 0b521ff1e..17767c629 100644 --- a/ecs/local/backend.go +++ b/ecs/local/backend.go @@ -24,13 +24,13 @@ import ( "github.com/docker/compose-cli/api/backend" "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/context/store" "github.com/docker/compose-cli/api/resources" "github.com/docker/compose-cli/api/secrets" "github.com/docker/compose-cli/api/volumes" local_compose "github.com/docker/compose-cli/local/compose" + "github.com/docker/compose-cli/pkg/api" ) const backendType = store.EcsLocalSimulationContextType @@ -41,7 +41,7 @@ func init() { type ecsLocalSimulation struct { moby *client.Client - compose compose.Service + compose api.Service } func service() (backend.Service, error) { @@ -72,7 +72,7 @@ func (e ecsLocalSimulation) SecretsService() secrets.Service { return nil } -func (e ecsLocalSimulation) ComposeService() compose.Service { +func (e ecsLocalSimulation) ComposeService() api.Service { return e } diff --git a/ecs/local/compose.go b/ecs/local/compose.go index 5b506d3d6..8bc21ba0f 100644 --- a/ecs/local/compose.go +++ b/ecs/local/compose.go @@ -28,23 +28,22 @@ import ( "github.com/pkg/errors" "github.com/sanathkr/go-yaml" - "github.com/docker/compose-cli/api/compose" - "github.com/docker/compose-cli/api/errdefs" + "github.com/docker/compose-cli/pkg/api" ) -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) } -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) } -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) } -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) if err != nil { return err @@ -53,27 +52,27 @@ func (e ecsLocalSimulation) Create(ctx context.Context, project *types.Project, 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) } -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) } -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) } -func (e ecsLocalSimulation) Up(ctx context.Context, project *types.Project, options compose.UpOptions) error { - return errdefs.ErrNotImplemented +func (e ecsLocalSimulation) Up(ctx context.Context, project *types.Project, options api.UpOptions) error { + 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) } -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) if err != nil { return nil, err @@ -161,57 +160,57 @@ func (e ecsLocalSimulation) enhanceForLocalSimulation(project *types.Project) (* 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 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) } -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) } -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) } -func (e ecsLocalSimulation) RunOneOffContainer(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { - return 0, errors.Wrap(errdefs.ErrNotImplemented, "use docker-compose run") +func (e ecsLocalSimulation) RunOneOffContainer(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) { + 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) } -func (e ecsLocalSimulation) Exec(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { - return 0, errdefs.ErrNotImplemented +func (e ecsLocalSimulation) Exec(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) { + 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) } -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) } -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) } -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) } -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) } -func (e ecsLocalSimulation) Port(ctx context.Context, project string, service string, port int, options compose.PortOptions) (string, int, error) { - return "", 0, errdefs.ErrNotImplemented +func (e ecsLocalSimulation) Port(ctx context.Context, project string, service string, port int, options api.PortOptions) (string, int, error) { + return "", 0, api.ErrNotImplemented } -func (e ecsLocalSimulation) Images(ctx context.Context, projectName string, options compose.ImagesOptions) ([]compose.ImageSummary, error) { - return nil, errdefs.ErrNotImplemented +func (e ecsLocalSimulation) Images(ctx context.Context, projectName string, options api.ImagesOptions) ([]api.ImageSummary, error) { + return nil, api.ErrNotImplemented } diff --git a/ecs/local/context.go b/ecs/local/context.go index c623a0f92..d6857370e 100644 --- a/ecs/local/context.go +++ b/ecs/local/context.go @@ -20,18 +20,18 @@ import ( "context" "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/pkg/api" ) var _ cloud.Service = ecsLocalSimulation{} func (e ecsLocalSimulation) Login(ctx context.Context, params interface{}) error { - return errdefs.ErrNotImplemented + return api.ErrNotImplemented } 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) { diff --git a/ecs/logs.go b/ecs/logs.go index 59c6df44d..4018a7fb4 100644 --- a/ecs/logs.go +++ b/ecs/logs.go @@ -19,11 +19,11 @@ package ecs import ( "context" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" "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 { consumer = utils.FilteredLogConsumer(consumer, options.Services) } diff --git a/ecs/ps.go b/ecs/ps.go index 4b9572225..8627bb6cb 100644 --- a/ecs/ps.go +++ b/ecs/ps.go @@ -19,10 +19,10 @@ package ecs import ( "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) if err != nil { return nil, err @@ -36,7 +36,7 @@ func (b *ecsAPIService) Ps(ctx context.Context, projectName string, options comp return nil, nil } - summary := []compose.ContainerSummary{} + summary := []api.ContainerSummary{} for _, arn := range servicesARN { service, err := b.aws.DescribeService(ctx, cluster, arn) if err != nil { diff --git a/ecs/run.go b/ecs/run.go index 8bd3a762f..5758fd85d 100644 --- a/ecs/run.go +++ b/ecs/run.go @@ -21,14 +21,13 @@ import ( "github.com/compose-spec/compose-go/types" - "github.com/docker/compose-cli/api/compose" - "github.com/docker/compose-cli/api/errdefs" + "github.com/docker/compose-cli/pkg/api" ) -func (b *ecsAPIService) RunOneOffContainer(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { - return 0, errdefs.ErrNotImplemented +func (b *ecsAPIService) RunOneOffContainer(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) { + return 0, api.ErrNotImplemented } -func (b *ecsAPIService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) error { - return errdefs.ErrNotImplemented +func (b *ecsAPIService) Remove(ctx context.Context, project *types.Project, options api.RemoveOptions) error { + return api.ErrNotImplemented } diff --git a/ecs/sdk.go b/ecs/sdk.go index c9d656eb8..3205718ed 100644 --- a/ecs/sdk.go +++ b/ecs/sdk.go @@ -24,10 +24,9 @@ import ( "strings" "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/internal" + "github.com/docker/compose-cli/pkg/api" "github.com/aws/aws-sdk-go/aws" "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 } 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] return existingAWSResource{ @@ -341,7 +340,7 @@ func (s sdk) CreateStack(ctx context.Context, name string, region string, templa }, Tags: []*cloudformation.Tag{ { - Key: aws.String(compose.ProjectLabel), + Key: aws.String(api.ProjectLabel), 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 } -func (s sdk) ListStacks(ctx context.Context) ([]compose.Stack, error) { +func (s sdk) ListStacks(ctx context.Context) ([]api.Stack, error) { params := cloudformation.DescribeStacksInput{} var token *string - var stacks []compose.Stack + var stacks []api.Stack for { response, err := s.CF.DescribeStacksWithContext(ctx, ¶ms) if err != nil { @@ -455,18 +454,18 @@ func (s sdk) ListStacks(ctx context.Context) ([]compose.Stack, error) { } for _, stack := range response.Stacks { for _, t := range stack.Tags { - if *t.Key == compose.ProjectLabel { - status := compose.RUNNING + if *t.Key == api.ProjectLabel { + status := api.RUNNING switch aws.StringValue(stack.StackStatus) { case "CREATE_IN_PROGRESS": - status = compose.STARTING + status = api.STARTING case "DELETE_IN_PROGRESS": - status = compose.REMOVING + status = api.REMOVING case "UPDATE_IN_PROGRESS": - status = compose.UPDATING + status = api.UPDATING default: } - stacks = append(stacks, compose.Stack{ + stacks = append(stacks, api.Stack{ ID: aws.StringValue(stack.StackId), Name: aws.StringValue(stack.StackName), Status: status, @@ -516,7 +515,7 @@ func (s sdk) GetStackClusterID(ctx context.Context, stack string) (string, error return "", err } 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 @@ -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{ Cluster: aws.String(cluster), Services: []*string{aws.String(arn)}, Include: aws.StringSlice([]string{"TAGS"}), }) if err != nil { - return compose.ServiceStatus{}, err + return api.ServiceStatus{}, err } 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] var name string for _, t := range service.Tags { - if *t.Key == compose.ServiceLabel { + if *t.Key == api.ServiceLabel { name = aws.StringValue(t.Value) } } 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{} 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 loadBalancers, err := s.getURLWithPortMapping(ctx, targetGroupArns) if err != nil { - return compose.ServiceStatus{}, err + return api.ServiceStatus{}, err } - return compose.ServiceStatus{ + return api.ServiceStatus{ ID: aws.StringValue(service.ServiceName), Name: name, Replicas: int(aws.Int64Value(service.RunningCount)), @@ -886,8 +885,8 @@ func (s sdk) DescribeService(ctx context.Context, cluster string, arn string) (c }, nil } -func (s sdk) DescribeServiceTasks(ctx context.Context, cluster string, project string, service string) ([]compose.ContainerSummary, error) { - var summary []compose.ContainerSummary +func (s sdk) DescribeServiceTasks(ctx context.Context, cluster string, project string, service string) ([]api.ContainerSummary, error) { + var summary []api.ContainerSummary familly := fmt.Sprintf("%s-%s", project, service) var token *string for { @@ -919,9 +918,9 @@ func (s sdk) DescribeServiceTasks(ctx context.Context, cluster string, project s var service string for _, tag := range t.Tags { switch aws.StringValue(tag.Key) { - case compose.ProjectLabel: + case api.ProjectLabel: project = aws.StringValue(tag.Value) - case compose.ServiceLabel: + case api.ServiceLabel: service = aws.StringValue(tag.Value) } } @@ -931,7 +930,7 @@ func (s sdk) DescribeServiceTasks(ctx context.Context, cluster string, project s return nil, err } - summary = append(summary, compose.ContainerSummary{ + summary = append(summary, api.ContainerSummary{ ID: id.String(), Name: id.Resource, Project: project, @@ -949,7 +948,7 @@ func (s sdk) DescribeServiceTasks(ctx context.Context, cluster string, project s 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 { return nil, nil } @@ -983,14 +982,14 @@ func (s sdk) getURLWithPortMapping(ctx context.Context, targetGroupArns []string } return nil } - loadBalancers := []compose.PortPublisher{} + loadBalancers := []api.PortPublisher{} for _, tg := range groups.TargetGroups { for _, lbarn := range tg.LoadBalancerArns { lb := filterLB(lbarn, lbs.LoadBalancers) if lb == nil { continue } - loadBalancers = append(loadBalancers, compose.PortPublisher{ + loadBalancers = append(loadBalancers, api.PortPublisher{ URL: fmt.Sprintf("%s:%d", aws.StringValue(lb.DNSName), aws.Int64Value(tg.Port)), TargetPort: 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 } 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] var subNets []awsResource @@ -1151,7 +1150,7 @@ func (s sdk) ResolveFileSystem(ctx context.Context, id string) (awsResource, err return nil, err } 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] return existingAWSResource{ diff --git a/ecs/tags.go b/ecs/tags.go index 882742cf1..15c52960a 100644 --- a/ecs/tags.go +++ b/ecs/tags.go @@ -20,13 +20,13 @@ import ( "github.com/awslabs/goformation/v4/cloudformation/tags" "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 { return []tags.Tag{ { - Key: compose.ProjectLabel, + Key: api.ProjectLabel, Value: project.Name, }, } @@ -35,11 +35,11 @@ func projectTags(project *types.Project) []tags.Tag { func serviceTags(project *types.Project, service types.ServiceConfig) []tags.Tag { return []tags.Tag{ { - Key: compose.ProjectLabel, + Key: api.ProjectLabel, Value: project.Name, }, { - Key: compose.ServiceLabel, + Key: api.ServiceLabel, 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 { return []tags.Tag{ { - Key: compose.ProjectLabel, + Key: api.ProjectLabel, Value: project.Name, }, { - Key: compose.NetworkLabel, + Key: api.NetworkLabel, Value: net.Name, }, } diff --git a/ecs/top.go b/ecs/top.go index 569a7c655..e1a879659 100644 --- a/ecs/top.go +++ b/ecs/top.go @@ -19,10 +19,9 @@ package ecs import ( "context" - "github.com/docker/compose-cli/api/compose" - "github.com/docker/compose-cli/api/errdefs" + "github.com/docker/compose-cli/pkg/api" ) -func (b *ecsAPIService) Top(ctx context.Context, projectName string, services []string) ([]compose.ContainerProcSummary, error) { - return nil, errdefs.ErrNotImplemented +func (b *ecsAPIService) Top(ctx context.Context, projectName string, services []string) ([]api.ContainerProcSummary, error) { + return nil, api.ErrNotImplemented } diff --git a/ecs/up.go b/ecs/up.go index 3829e680d..c73f3d50f 100644 --- a/ecs/up.go +++ b/ecs/up.go @@ -26,73 +26,72 @@ import ( "github.com/compose-spec/compose-go/types" "github.com/sirupsen/logrus" - "github.com/docker/compose-cli/api/compose" - "github.com/docker/compose-cli/api/errdefs" "github.com/docker/compose-cli/api/progress" + "github.com/docker/compose-cli/pkg/api" ) -func (b *ecsAPIService) Build(ctx context.Context, project *types.Project, options compose.BuildOptions) error { - return errdefs.ErrNotImplemented +func (b *ecsAPIService) Build(ctx context.Context, project *types.Project, options api.BuildOptions) error { + return api.ErrNotImplemented } -func (b *ecsAPIService) Push(ctx context.Context, project *types.Project, options compose.PushOptions) error { - return errdefs.ErrNotImplemented +func (b *ecsAPIService) Push(ctx context.Context, project *types.Project, options api.PushOptions) error { + return api.ErrNotImplemented } -func (b *ecsAPIService) Pull(ctx context.Context, project *types.Project, options compose.PullOptions) error { - return errdefs.ErrNotImplemented +func (b *ecsAPIService) Pull(ctx context.Context, project *types.Project, options api.PullOptions) error { + return api.ErrNotImplemented } -func (b *ecsAPIService) Create(ctx context.Context, project *types.Project, opts compose.CreateOptions) error { - return errdefs.ErrNotImplemented +func (b *ecsAPIService) Create(ctx context.Context, project *types.Project, opts api.CreateOptions) error { + return api.ErrNotImplemented } -func (b *ecsAPIService) Start(ctx context.Context, project *types.Project, options compose.StartOptions) error { - return errdefs.ErrNotImplemented +func (b *ecsAPIService) Start(ctx context.Context, project *types.Project, options api.StartOptions) error { + return api.ErrNotImplemented } -func (b *ecsAPIService) Restart(ctx context.Context, project *types.Project, options compose.RestartOptions) error { - return errdefs.ErrNotImplemented +func (b *ecsAPIService) Restart(ctx context.Context, project *types.Project, options api.RestartOptions) error { + return api.ErrNotImplemented } -func (b *ecsAPIService) Stop(ctx context.Context, project *types.Project, options compose.StopOptions) error { - return errdefs.ErrNotImplemented +func (b *ecsAPIService) Stop(ctx context.Context, project *types.Project, options api.StopOptions) error { + return api.ErrNotImplemented } -func (b *ecsAPIService) Pause(ctx context.Context, project string, options compose.PauseOptions) error { - return errdefs.ErrNotImplemented +func (b *ecsAPIService) Pause(ctx context.Context, project string, options api.PauseOptions) error { + return api.ErrNotImplemented } -func (b *ecsAPIService) UnPause(ctx context.Context, project string, options compose.PauseOptions) error { - return errdefs.ErrNotImplemented +func (b *ecsAPIService) UnPause(ctx context.Context, project string, options api.PauseOptions) error { + return api.ErrNotImplemented } -func (b *ecsAPIService) Events(ctx context.Context, project string, options compose.EventsOptions) error { - return errdefs.ErrNotImplemented +func (b *ecsAPIService) Events(ctx context.Context, project string, options api.EventsOptions) error { + return api.ErrNotImplemented } -func (b *ecsAPIService) Port(ctx context.Context, project string, service string, port int, options compose.PortOptions) (string, int, error) { - return "", 0, errdefs.ErrNotImplemented +func (b *ecsAPIService) Port(ctx context.Context, project string, service string, port int, options api.PortOptions) (string, int, error) { + return "", 0, api.ErrNotImplemented } -func (b *ecsAPIService) Copy(ctx context.Context, project *types.Project, options compose.CopyOptions) error { - return errdefs.ErrNotImplemented +func (b *ecsAPIService) Copy(ctx context.Context, project *types.Project, options api.CopyOptions) error { + 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 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) err := b.aws.CheckRequirements(ctx, b.Region) if err != nil { return err } - template, err := b.Convert(ctx, project, compose.ConvertOptions{ + template, err := b.Convert(ctx, project, api.ConvertOptions{ Format: "yaml", }) if err != nil { @@ -138,7 +137,7 @@ func (b *ecsAPIService) up(ctx context.Context, project *types.Project, options go func() { <-signalChan 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...) diff --git a/ecs/volumes.go b/ecs/volumes.go index 90c0acdb7..6d8c53097 100644 --- a/ecs/volumes.go +++ b/ecs/volumes.go @@ -20,9 +20,8 @@ import ( "context" "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/pkg/api" "github.com/awslabs/goformation/v4/cloudformation" "github.com/awslabs/goformation/v4/cloudformation/efs" @@ -63,11 +62,11 @@ func (b *ecsAPIService) createAccessPoints(project *types.Project, r awsResource ap := efs.AccessPoint{ AccessPointTags: []efs.AccessPoint_AccessPointTag{ { - Key: compose.ProjectLabel, + Key: api.ProjectLabel, Value: project.Name, }, { - Key: compose.VolumeLabel, + Key: api.VolumeLabel, 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) { ok, err := e.backend.aws.ResolveFileSystem(ctx, volumeID) 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{ ID: volumeID, diff --git a/kube/backend.go b/kube/backend.go index fa61a7da0..a439c2a3a 100644 --- a/kube/backend.go +++ b/kube/backend.go @@ -21,18 +21,18 @@ package kube import ( "github.com/docker/compose-cli/api/backend" "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/context/store" "github.com/docker/compose-cli/api/resources" "github.com/docker/compose-cli/api/secrets" "github.com/docker/compose-cli/api/volumes" + "github.com/docker/compose-cli/pkg/api" ) const backendType = store.KubeContextType type kubeAPIService struct { - composeService compose.Service + composeService api.Service } func init() { @@ -53,7 +53,7 @@ func (s *kubeAPIService) ContainerService() containers.Service { return nil } -func (s *kubeAPIService) ComposeService() compose.Service { +func (s *kubeAPIService) ComposeService() api.Service { return s.composeService } diff --git a/kube/client/client.go b/kube/client/client.go index f80ee9dd9..f78748ae6 100644 --- a/kube/client/client.go +++ b/kube/client/client.go @@ -27,7 +27,7 @@ import ( "strings" "time" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/utils" "golang.org/x/sync/errgroup" corev1 "k8s.io/api/core/v1" @@ -77,7 +77,7 @@ func NewKubeClient(config genericclioptions.RESTClientGetter) (*KubeClient, erro // GetPod retrieves a service pod 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{ - LabelSelector: fmt.Sprintf("%s=%s", compose.ProjectLabel, projectName), + LabelSelector: fmt.Sprintf("%s=%s", api.ProjectLabel, projectName), }) if err != nil { return nil, err @@ -87,7 +87,7 @@ func (kc KubeClient) GetPod(ctx context.Context, projectName, serviceName string } var pod corev1.Pod for _, p := range pods.Items { - service := p.Labels[compose.ServiceLabel] + service := p.Labels[api.ServiceLabel] if service == serviceName { pod = p break @@ -97,7 +97,7 @@ func (kc KubeClient) GetPod(ctx context.Context, projectName, serviceName string } // 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) if err != nil || pod == nil { return err @@ -148,24 +148,24 @@ func (kc KubeClient) Exec(ctx context.Context, projectName string, opts compose. } // 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 := "" if !all { fieldSelector = "status.phase=Running" } 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, }) if err != nil { return nil, err } - services := map[string][]compose.PortPublisher{} - result := []compose.ContainerSummary{} + services := map[string][]api.PortPublisher{} + result := []api.ContainerSummary{} for _, pod := range pods.Items { summary := podToContainerSummary(pod) - serviceName := pod.GetObjectMeta().GetLabels()[compose.ServiceLabel] + serviceName := pod.GetObjectMeta().GetLabels()[api.ServiceLabel] ports, ok := services[serviceName] if !ok { s, err := kc.client.CoreV1().Services(kc.namespace).Get(ctx, serviceName, metav1.GetOptions{}) @@ -176,11 +176,11 @@ func (kc KubeClient) GetContainers(ctx context.Context, projectName string, all result = append(result, summary) continue } - ports = []compose.PortPublisher{} + ports = []api.PortPublisher{} if s != nil { if s.Spec.Type == corev1.ServiceTypeLoadBalancer { 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 { port.URL = fmt.Sprintf("%s:%d", port.URL, s.Spec.Ports[0].Port) port.TargetPort = s.Spec.Ports[0].TargetPort.IntValue() @@ -200,9 +200,9 @@ func (kc KubeClient) GetContainers(ctx context.Context, projectName string, all } // 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{ - LabelSelector: fmt.Sprintf("%s=%s", compose.ProjectLabel, projectName), + LabelSelector: fmt.Sprintf("%s=%s", api.ProjectLabel, projectName), }) if err != nil { return err @@ -210,7 +210,7 @@ func (kc *KubeClient) GetLogs(ctx context.Context, projectName string, consumer eg, ctx := errgroup.WithContext(ctx) for _, pod := range pods.Items { 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) { consumer.Log(pod.Name, service, line) }) @@ -243,7 +243,7 @@ func (kc KubeClient) WaitForPodState(ctx context.Context, opts WaitForStatusOpti time.Sleep(500 * time.Millisecond) 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 { errch <- err diff --git a/kube/client/client_test.go b/kube/client/client_test.go index 0b86d1bb0..0c91295c7 100644 --- a/kube/client/client_test.go +++ b/kube/client/client_test.go @@ -26,7 +26,7 @@ import ( "gotest.tools/v3/assert" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" ) func TestPodToContainerSummary(t *testing.T) { @@ -34,8 +34,8 @@ func TestPodToContainerSummary(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "c1-123", Labels: map[string]string{ - compose.ProjectLabel: "myproject", - compose.ServiceLabel: "service1", + api.ProjectLabel: "myproject", + api.ServiceLabel: "service1", }, }, Status: v1.PodStatus{ @@ -45,7 +45,7 @@ func TestPodToContainerSummary(t *testing.T) { container := podToContainerSummary(pod) - expected := compose.ContainerSummary{ + expected := api.ContainerSummary{ ID: "c1-123", Name: "c1-123", Project: "myproject", diff --git a/kube/client/utils.go b/kube/client/utils.go index d147d98e7..18eb4bc36 100644 --- a/kube/client/utils.go +++ b/kube/client/utils.go @@ -22,34 +22,34 @@ import ( "fmt" "time" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/utils" corev1 "k8s.io/api/core/v1" ) -func podToContainerSummary(pod corev1.Pod) compose.ContainerSummary { - state := compose.RUNNING +func podToContainerSummary(pod corev1.Pod) api.ContainerSummary { + state := api.RUNNING if pod.DeletionTimestamp != nil { - state = compose.REMOVING + state = api.REMOVING } else { for _, container := range pod.Status.ContainerStatuses { if container.State.Waiting != nil || container.State.Terminated != nil { - state = compose.UPDATING + state = api.UPDATING break } } - if state == compose.RUNNING && pod.Status.Phase != corev1.PodRunning { + if state == api.RUNNING && pod.Status.Phase != corev1.PodRunning { state = string(pod.Status.Phase) } } - return compose.ContainerSummary{ + return api.ContainerSummary{ ID: pod.GetObjectMeta().GetName(), Name: pod.GetObjectMeta().GetName(), - Service: pod.GetObjectMeta().GetLabels()[compose.ServiceLabel], + Service: pod.GetObjectMeta().GetLabels()[api.ServiceLabel], State: state, - Project: pod.GetObjectMeta().GetLabels()[compose.ProjectLabel], + Project: pod.GetObjectMeta().GetLabels()[api.ProjectLabel], } } @@ -57,7 +57,7 @@ func checkPodsState(services []string, pods []corev1.Pod, status string) (bool, servicePods := map[string]string{} stateReached := true for _, pod := range pods { - service := pod.Labels[compose.ServiceLabel] + service := pod.Labels[api.ServiceLabel] if len(services) > 0 && !utils.StringContains(services, service) { continue @@ -71,17 +71,17 @@ func checkPodsState(services []string, pods []corev1.Pod, status string) (bool, } servicePods[service] = pod.Status.Message - if status == compose.REMOVING { + if status == api.REMOVING { continue } if pod.Status.Phase == corev1.PodFailed { return false, servicePods, fmt.Errorf(pod.Status.Reason) } - if status == compose.RUNNING && (pod.Status.Phase != corev1.PodRunning || !containersRunning) { + if status == api.RUNNING && (pod.Status.Phase != corev1.PodRunning || !containersRunning) { stateReached = false } } - if status == compose.REMOVING && len(servicePods) > 0 { + if status == api.REMOVING && len(servicePods) > 0 { stateReached = false } return stateReached, servicePods, nil @@ -100,7 +100,7 @@ type WaitForStatusOptions struct { } // Ports holds published ports data -type Ports []compose.PortPublisher +type Ports []api.PortPublisher // PortMappingOptions holds the port mapping for project services type PortMappingOptions struct { diff --git a/kube/compose.go b/kube/compose.go index b89ac0560..98efeb8e3 100644 --- a/kube/compose.go +++ b/kube/compose.go @@ -26,14 +26,13 @@ import ( "github.com/compose-spec/compose-go/types" "github.com/pkg/errors" - "github.com/docker/compose-cli/api/compose" apicontext "github.com/docker/compose-cli/api/context" "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/kube/client" "github.com/docker/compose-cli/kube/helm" "github.com/docker/compose-cli/kube/resources" + "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/utils" ) @@ -42,8 +41,8 @@ type composeService struct { client *client.KubeClient } -// NewComposeService create a kubernetes implementation of the compose.Service API -func NewComposeService() (compose.Service, error) { +// NewComposeService create a kubernetes implementation of the api.Service API +func NewComposeService() (api.Service, error) { contextStore := store.Instance() currentContext := apicontext.Current() var kubeContext store.KubeContext @@ -71,7 +70,7 @@ func NewComposeService() (compose.Service, error) { } // Up executes the equivalent to a `compose up` -func (s *composeService) Up(ctx context.Context, project *types.Project, options compose.UpOptions) error { +func (s *composeService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error { return progress.Run(ctx, func(ctx context.Context) error { return s.up(ctx, project) }) @@ -119,7 +118,7 @@ func (s *composeService) up(ctx context.Context, project *types.Project) error { return s.client.WaitForPodState(ctx, client.WaitForStatusOptions{ ProjectName: project.Name, Services: project.ServiceNames(), - Status: compose.RUNNING, + Status: api.RUNNING, Log: func(pod string, stateReached bool, message string) { state := progress.Done if !stateReached { @@ -131,19 +130,19 @@ func (s *composeService) up(ctx context.Context, project *types.Project) error { } // Down executes the equivalent to a `compose down` -func (s *composeService) Down(ctx context.Context, projectName string, options compose.DownOptions) error { +func (s *composeService) Down(ctx context.Context, projectName string, options api.DownOptions) error { if options.Volumes { - return errors.Wrap(errdefs.ErrNotImplemented, "--volumes option is not supported on Kubernetes") + return errors.Wrap(api.ErrNotImplemented, "--volumes option is not supported on Kubernetes") } if options.Images != "" { - return errors.Wrap(errdefs.ErrNotImplemented, "--rmi option is not supported on Kubernetes") + return errors.Wrap(api.ErrNotImplemented, "--rmi option is not supported on Kubernetes") } return progress.Run(ctx, func(ctx context.Context) error { return s.down(ctx, projectName, options) }) } -func (s *composeService) down(ctx context.Context, projectName string, options compose.DownOptions) error { +func (s *composeService) down(ctx context.Context, projectName string, options api.DownOptions) error { w := progress.ContextWriter(ctx) eventName := fmt.Sprintf("Remove %s", projectName) w.Event(progress.CreatingEvent(eventName)) @@ -168,7 +167,7 @@ func (s *composeService) down(ctx context.Context, projectName string, options c err = s.client.WaitForPodState(ctx, client.WaitForStatusOptions{ ProjectName: projectName, Services: nil, - Status: compose.REMOVING, + Status: api.REMOVING, Timeout: options.Timeout, Log: func(pod string, stateReached bool, message string) { state := progress.Done @@ -192,52 +191,52 @@ func (s *composeService) down(ctx context.Context, projectName string, options c } // List executes the equivalent to a `docker stack ls` -func (s *composeService) List(ctx context.Context, opts compose.ListOptions) ([]compose.Stack, error) { +func (s *composeService) List(ctx context.Context, opts api.ListOptions) ([]api.Stack, error) { return s.sdk.ListReleases() } // Build executes the equivalent to a `compose build` -func (s *composeService) Build(ctx context.Context, project *types.Project, options compose.BuildOptions) error { - return errdefs.ErrNotImplemented +func (s *composeService) Build(ctx context.Context, project *types.Project, options api.BuildOptions) error { + return api.ErrNotImplemented } // Push executes the equivalent ot a `compose push` -func (s *composeService) Push(ctx context.Context, project *types.Project, options compose.PushOptions) error { - return errdefs.ErrNotImplemented +func (s *composeService) Push(ctx context.Context, project *types.Project, options api.PushOptions) error { + return api.ErrNotImplemented } // Pull executes the equivalent of a `compose pull` -func (s *composeService) Pull(ctx context.Context, project *types.Project, options compose.PullOptions) error { - return errdefs.ErrNotImplemented +func (s *composeService) Pull(ctx context.Context, project *types.Project, options api.PullOptions) error { + return api.ErrNotImplemented } // Create executes the equivalent to a `compose create` -func (s *composeService) Create(ctx context.Context, project *types.Project, opts compose.CreateOptions) error { - return errdefs.ErrNotImplemented +func (s *composeService) Create(ctx context.Context, project *types.Project, opts api.CreateOptions) error { + return api.ErrNotImplemented } // Start executes the equivalent to a `compose start` -func (s *composeService) Start(ctx context.Context, project *types.Project, options compose.StartOptions) error { - return errdefs.ErrNotImplemented +func (s *composeService) Start(ctx context.Context, project *types.Project, options api.StartOptions) error { + return api.ErrNotImplemented } // Restart executes the equivalent to a `compose restart` -func (s *composeService) Restart(ctx context.Context, project *types.Project, options compose.RestartOptions) error { - return errdefs.ErrNotImplemented +func (s *composeService) Restart(ctx context.Context, project *types.Project, options api.RestartOptions) error { + return api.ErrNotImplemented } // Stop executes the equivalent to a `compose stop` -func (s *composeService) Stop(ctx context.Context, project *types.Project, options compose.StopOptions) error { - return errdefs.ErrNotImplemented +func (s *composeService) Stop(ctx context.Context, project *types.Project, options api.StopOptions) error { + return api.ErrNotImplemented } // Copy copies a file/folder between a service container and the local filesystem -func (s *composeService) Copy(ctx context.Context, project *types.Project, options compose.CopyOptions) error { - return errdefs.ErrNotImplemented +func (s *composeService) Copy(ctx context.Context, project *types.Project, options api.CopyOptions) error { + return api.ErrNotImplemented } // Logs executes the equivalent to a `compose logs` -func (s *composeService) Logs(ctx context.Context, projectName string, consumer compose.LogConsumer, options compose.LogOptions) error { +func (s *composeService) Logs(ctx context.Context, projectName string, consumer api.LogConsumer, options api.LogOptions) error { if len(options.Services) > 0 { consumer = utils.FilteredLogConsumer(consumer, options.Services) } @@ -245,12 +244,12 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer } // Ps executes the equivalent to a `compose ps` -func (s *composeService) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) { +func (s *composeService) Ps(ctx context.Context, projectName string, options api.PsOptions) ([]api.ContainerSummary, error) { return s.client.GetContainers(ctx, projectName, options.All) } // Convert translate compose model into backend's native format -func (s *composeService) Convert(ctx context.Context, project *types.Project, options compose.ConvertOptions) ([]byte, error) { +func (s *composeService) Convert(ctx context.Context, project *types.Project, options api.ConvertOptions) ([]byte, error) { chart, err := helm.GetChartInMemory(project) if err != nil { @@ -272,44 +271,44 @@ func (s *composeService) Convert(ctx context.Context, project *types.Project, op return buff, nil } -func (s *composeService) Kill(ctx context.Context, project *types.Project, options compose.KillOptions) error { - return errdefs.ErrNotImplemented +func (s *composeService) Kill(ctx context.Context, project *types.Project, options api.KillOptions) error { + return api.ErrNotImplemented } // RunOneOffContainer creates a service oneoff container and starts its dependencies -func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { - return 0, errdefs.ErrNotImplemented +func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) { + return 0, api.ErrNotImplemented } -func (s *composeService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) error { - return errdefs.ErrNotImplemented +func (s *composeService) Remove(ctx context.Context, project *types.Project, options api.RemoveOptions) error { + return api.ErrNotImplemented } // Exec executes a command in a running service container -func (s *composeService) Exec(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { +func (s *composeService) Exec(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) { return 0, s.client.Exec(ctx, project.Name, opts) } -func (s *composeService) Pause(ctx context.Context, project string, options compose.PauseOptions) error { - return errdefs.ErrNotImplemented +func (s *composeService) Pause(ctx context.Context, project string, options api.PauseOptions) error { + return api.ErrNotImplemented } -func (s *composeService) UnPause(ctx context.Context, project string, options compose.PauseOptions) error { - return errdefs.ErrNotImplemented +func (s *composeService) UnPause(ctx context.Context, project string, options api.PauseOptions) error { + return api.ErrNotImplemented } -func (s *composeService) Top(ctx context.Context, projectName string, services []string) ([]compose.ContainerProcSummary, error) { - return nil, errdefs.ErrNotImplemented +func (s *composeService) Top(ctx context.Context, projectName string, services []string) ([]api.ContainerProcSummary, error) { + return nil, api.ErrNotImplemented } -func (s *composeService) Events(ctx context.Context, project string, options compose.EventsOptions) error { - return errdefs.ErrNotImplemented +func (s *composeService) Events(ctx context.Context, project string, options api.EventsOptions) error { + return api.ErrNotImplemented } -func (s *composeService) Port(ctx context.Context, project string, service string, port int, options compose.PortOptions) (string, int, error) { - return "", 0, errdefs.ErrNotImplemented +func (s *composeService) Port(ctx context.Context, project string, service string, port int, options api.PortOptions) (string, int, error) { + return "", 0, api.ErrNotImplemented } -func (s *composeService) Images(ctx context.Context, projectName string, options compose.ImagesOptions) ([]compose.ImageSummary, error) { - return nil, errdefs.ErrNotImplemented +func (s *composeService) Images(ctx context.Context, projectName string, options api.ImagesOptions) ([]api.ImageSummary, error) { + return nil, api.ErrNotImplemented } diff --git a/kube/context.go b/kube/context.go index f28d4a3e5..0c80cf288 100644 --- a/kube/context.go +++ b/kube/context.go @@ -22,11 +22,11 @@ import ( "fmt" "github.com/AlecAivazis/survey/v2/terminal" - "github.com/docker/compose-cli/api/context/store" - "github.com/docker/compose-cli/api/errdefs" - "github.com/docker/compose-cli/utils/prompt" + "github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/kube/resources" + "github.com/docker/compose-cli/pkg/api" + "github.com/docker/compose-cli/utils/prompt" ) // ContextParams options for creating a Kubernetes context @@ -55,7 +55,7 @@ func (cp ContextParams) CreateContextData() (interface{}, string, error) { selected, err := user.Select("Select kubeconfig context", contexts) if err != nil { if err == terminal.InterruptErr { - return errdefs.ErrCanceled + return api.ErrCanceled } return err } @@ -93,7 +93,7 @@ func (cp ContextParams) CreateContextData() (interface{}, string, error) { selected, err := user.Select("Create a Docker context using:", options) if err != nil { if err == terminal.InterruptErr { - return nil, "", errdefs.ErrCanceled + return nil, "", api.ErrCanceled } return nil, "", err } diff --git a/kube/helm/helm.go b/kube/helm/helm.go index fd04f7879..846102606 100644 --- a/kube/helm/helm.go +++ b/kube/helm/helm.go @@ -21,7 +21,7 @@ package helm import ( "errors" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chart" env "helm.sh/helm/v3/pkg/cli" @@ -123,15 +123,15 @@ func (hc *Actions) Get(name string) (*release.Release, error) { } // ListReleases lists chart releases -func (hc *Actions) ListReleases() ([]compose.Stack, error) { +func (hc *Actions) ListReleases() ([]api.Stack, error) { actList := action.NewList(hc.Config) releases, err := actList.Run() if err != nil { return nil, err } - result := []compose.Stack{} + result := []api.Stack{} for _, rel := range releases { - result = append(result, compose.Stack{ + result = append(result, api.Stack{ ID: rel.Name, Name: rel.Name, Status: string(rel.Info.Status), diff --git a/kube/resources/kube.go b/kube/resources/kube.go index 0763cb28a..0149f1fc2 100644 --- a/kube/resources/kube.go +++ b/kube/resources/kube.go @@ -25,7 +25,7 @@ import ( "time" "github.com/compose-spec/compose-go/types" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" apps "k8s.io/api/apps/v1" core "k8s.io/api/core/v1" resource "k8s.io/apimachinery/pkg/api/resource" @@ -151,8 +151,8 @@ func mapToDeployment(project *types.Project, service types.ServiceConfig) (*apps func selectorLabels(projectName string, serviceName string) map[string]string { return map[string]string{ - compose.ProjectLabel: projectName, - compose.ServiceLabel: serviceName, + api.ProjectLabel: projectName, + api.ServiceLabel: serviceName, } } diff --git a/local/backend.go b/local/backend.go index 95ab2f573..0e8b21e0a 100644 --- a/local/backend.go +++ b/local/backend.go @@ -25,19 +25,19 @@ import ( "github.com/docker/docker/client" "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/resources" "github.com/docker/compose-cli/api/secrets" "github.com/docker/compose-cli/api/volumes" cliopts "github.com/docker/compose-cli/cli/options" local_compose "github.com/docker/compose-cli/local/compose" + "github.com/docker/compose-cli/pkg/api" ) type local struct { containerService *containerService volumeService *volumeService - composeService compose.Service + composeService api.Service } // NewService build a backend for "local" context, using Docker API client @@ -79,7 +79,7 @@ func (s *local) ContainerService() containers.Service { return s.containerService } -func (s *local) ComposeService() compose.Service { +func (s *local) ComposeService() api.Service { return s.composeService } diff --git a/local/compose/attach.go b/local/compose/attach.go index 266d14418..9245e2474 100644 --- a/local/compose/attach.go +++ b/local/compose/attach.go @@ -22,8 +22,8 @@ import ( "io" "strings" - "github.com/docker/compose-cli/api/compose" convert "github.com/docker/compose-cli/local/moby" + "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/utils" "github.com/compose-spec/compose-go/types" @@ -32,7 +32,7 @@ import ( "github.com/docker/docker/pkg/stdcopy" ) -func (s *composeService) attach(ctx context.Context, project *types.Project, listener compose.ContainerEventListener, selectedServices []string) (Containers, error) { +func (s *composeService) attach(ctx context.Context, project *types.Project, listener api.ContainerEventListener, selectedServices []string) (Containers, error) { containers, err := s.getContainers(ctx, project.Name, oneOffExclude, true, selectedServices...) if err != nil { return nil, err @@ -56,23 +56,23 @@ func (s *composeService) attach(ctx context.Context, project *types.Project, lis return containers, err } -func (s *composeService) attachContainer(ctx context.Context, container moby.Container, listener compose.ContainerEventListener, project *types.Project) error { - serviceName := container.Labels[compose.ServiceLabel] +func (s *composeService) attachContainer(ctx context.Context, container moby.Container, listener api.ContainerEventListener, project *types.Project) error { + serviceName := container.Labels[api.ServiceLabel] containerName := getContainerNameWithoutProject(container) service, err := project.GetService(serviceName) if err != nil { return err } - listener(compose.ContainerEvent{ - Type: compose.ContainerEventAttach, + listener(api.ContainerEvent{ + Type: api.ContainerEventAttach, Container: containerName, Service: serviceName, }) w := utils.GetWriter(func(line string) { - listener(compose.ContainerEvent{ - Type: compose.ContainerEventLog, + listener(api.ContainerEvent{ + Type: api.ContainerEventLog, Container: containerName, Service: serviceName, Line: line, diff --git a/local/compose/build.go b/local/compose/build.go index c9b32290e..bc196cd08 100644 --- a/local/compose/build.go +++ b/local/compose/build.go @@ -34,19 +34,19 @@ import ( "github.com/moby/buildkit/session/auth/authprovider" specs "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/docker/compose-cli/api/compose" composeprogress "github.com/docker/compose-cli/api/progress" "github.com/docker/compose-cli/cli/metrics" + "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/utils" ) -func (s *composeService) Build(ctx context.Context, project *types.Project, options compose.BuildOptions) error { +func (s *composeService) Build(ctx context.Context, project *types.Project, options api.BuildOptions) error { return composeprogress.Run(ctx, func(ctx context.Context) error { return s.build(ctx, project, options) }) } -func (s *composeService) build(ctx context.Context, project *types.Project, options compose.BuildOptions) error { +func (s *composeService) build(ctx context.Context, project *types.Project, options api.BuildOptions) error { opts := map[string]build.Options{} imagesToBuild := []string{} diff --git a/local/compose/compose.go b/local/compose/compose.go index ec71399e4..f26af89c8 100644 --- a/local/compose/compose.go +++ b/local/compose/compose.go @@ -22,7 +22,7 @@ import ( "fmt" "strings" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" "github.com/compose-spec/compose-go/types" "github.com/docker/cli/cli/config/configfile" @@ -32,7 +32,7 @@ import ( ) // NewComposeService create a local implementation of the compose.Service API -func NewComposeService(apiClient client.APIClient, configFile *configfile.ConfigFile) compose.Service { +func NewComposeService(apiClient client.APIClient, configFile *configfile.ConfigFile) api.Service { return &composeService{ apiClient: apiClient, configFile: configFile, @@ -56,15 +56,15 @@ func getCanonicalContainerName(c moby.Container) string { func getContainerNameWithoutProject(c moby.Container) string { name := getCanonicalContainerName(c) - project := c.Labels[compose.ProjectLabel] - prefix := fmt.Sprintf("%s_%s_", project, c.Labels[compose.ServiceLabel]) + project := c.Labels[api.ProjectLabel] + prefix := fmt.Sprintf("%s_%s_", project, c.Labels[api.ServiceLabel]) if strings.HasPrefix(name, prefix) { return name[len(project)+1:] } return name } -func (s *composeService) Convert(ctx context.Context, project *types.Project, options compose.ConvertOptions) ([]byte, error) { +func (s *composeService) Convert(ctx context.Context, project *types.Project, options api.ConvertOptions) ([]byte, error) { switch options.Format { case "json": return json.MarshalIndent(project, "", " ") diff --git a/local/compose/containers.go b/local/compose/containers.go index b49f689ef..fa539f540 100644 --- a/local/compose/containers.go +++ b/local/compose/containers.go @@ -23,7 +23,7 @@ import ( moby "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/utils" ) @@ -69,20 +69,20 @@ type containerPredicate func(c moby.Container) bool func isService(services ...string) containerPredicate { return func(c moby.Container) bool { - service := c.Labels[compose.ServiceLabel] + service := c.Labels[api.ServiceLabel] return utils.StringContains(services, service) } } func isNotService(services ...string) containerPredicate { return func(c moby.Container) bool { - service := c.Labels[compose.ServiceLabel] + service := c.Labels[api.ServiceLabel] return !utils.StringContains(services, service) } } func isNotOneOff(c moby.Container) bool { - v, ok := c.Labels[compose.OneoffLabel] + v, ok := c.Labels[api.OneoffLabel] return !ok || v == "False" } diff --git a/local/compose/convergence.go b/local/compose/convergence.go index a6779b2c7..9e1e514b1 100644 --- a/local/compose/convergence.go +++ b/local/compose/convergence.go @@ -31,9 +31,9 @@ import ( "github.com/sirupsen/logrus" "golang.org/x/sync/errgroup" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/progress" status "github.com/docker/compose-cli/local/moby" + "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/utils" ) @@ -95,7 +95,7 @@ func (s *composeService) ensureService(ctx context.Context, project *types.Proje return err } - if recreate == compose.RecreateNever { + if recreate == api.RecreateNever { return nil } @@ -108,8 +108,8 @@ func (s *composeService) ensureService(ctx context.Context, project *types.Proje container := container name := getContainerProgressName(container) - diverged := container.Labels[compose.ConfigHashLabel] != expected - if diverged || recreate == compose.RecreateForce || service.Extensions[extLifecycle] == forceRecreate { + diverged := container.Labels[api.ConfigHashLabel] != expected + if diverged || recreate == api.RecreateForce || service.Extensions[extLifecycle] == forceRecreate { eg.Go(func() error { return s.recreateContainer(ctx, project, service, container, inherit, timeout) }) @@ -190,7 +190,7 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr func nextContainerNumber(containers []moby.Container) (int, error) { max := 0 for _, c := range containers { - n, err := strconv.Atoi(c.Labels[compose.ContainerNumberLabel]) + n, err := strconv.Atoi(c.Labels[api.ContainerNumberLabel]) if err != nil { return 0, err } @@ -245,7 +245,7 @@ func (s *composeService) recreateContainer(ctx context.Context, project *types.P if err != nil { return err } - number, err := strconv.Atoi(container.Labels[compose.ContainerNumberLabel]) + number, err := strconv.Atoi(container.Labels[api.ContainerNumberLabel]) if err != nil { return err } diff --git a/local/compose/cp.go b/local/compose/cp.go index 1d5dc39a0..a7324ecd5 100644 --- a/local/compose/cp.go +++ b/local/compose/cp.go @@ -28,8 +28,8 @@ import ( "github.com/compose-spec/compose-go/types" "github.com/docker/cli/cli/command" - "github.com/docker/compose-cli/api/compose" - apitypes "github.com/docker/docker/api/types" + "github.com/docker/compose-cli/pkg/api" + moby "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/system" @@ -44,7 +44,7 @@ const ( acrossServices = fromService | toService ) -func (s *composeService) Copy(ctx context.Context, project *types.Project, opts compose.CopyOptions) error { +func (s *composeService) Copy(ctx context.Context, project *types.Project, opts api.CopyOptions) error { srcService, srcPath := splitCpArg(opts.Source) destService, dstPath := splitCpArg(opts.Destination) @@ -69,9 +69,9 @@ func (s *composeService) Copy(ctx context.Context, project *types.Project, opts serviceFilter(serviceName), ) if !opts.All { - f.Add("label", fmt.Sprintf("%s=%d", compose.ContainerNumberLabel, opts.Index)) + f.Add("label", fmt.Sprintf("%s=%d", api.ContainerNumberLabel, opts.Index)) } - containers, err := s.apiClient.ContainerList(ctx, apitypes.ContainerListOptions{Filters: f}) + containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{Filters: f}) if err != nil { return err } @@ -101,7 +101,7 @@ func (s *composeService) Copy(ctx context.Context, project *types.Project, opts return g.Wait() } -func (s *composeService) copyToContainer(ctx context.Context, containerID string, srcPath string, dstPath string, opts compose.CopyOptions) error { +func (s *composeService) copyToContainer(ctx context.Context, containerID string, srcPath string, dstPath string, opts api.CopyOptions) error { var err error if srcPath != "-" { // Get an absolute source path. @@ -189,14 +189,14 @@ func (s *composeService) copyToContainer(ctx context.Context, containerID string content = preparedArchive } - options := apitypes.CopyToContainerOptions{ + options := moby.CopyToContainerOptions{ AllowOverwriteDirWithFile: false, CopyUIDGID: opts.CopyUIDGID, } return s.apiClient.CopyToContainer(ctx, containerID, resolvedDstPath, content, options) } -func (s *composeService) copyFromContainer(ctx context.Context, containerID, srcPath, dstPath string, opts compose.CopyOptions) error { +func (s *composeService) copyFromContainer(ctx context.Context, containerID, srcPath, dstPath string, opts api.CopyOptions) error { var err error if dstPath != "-" { // Get an absolute destination path. diff --git a/local/compose/create.go b/local/compose/create.go index 5cb0dba1c..5cb8ef625 100644 --- a/local/compose/create.go +++ b/local/compose/create.go @@ -38,20 +38,20 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/progress" "github.com/docker/compose-cli/internal" convert "github.com/docker/compose-cli/local/moby" + "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/utils" ) -func (s *composeService) Create(ctx context.Context, project *types.Project, options compose.CreateOptions) error { +func (s *composeService) Create(ctx context.Context, project *types.Project, options api.CreateOptions) error { return progress.Run(ctx, func(ctx context.Context) error { return s.create(ctx, project, options) }) } -func (s *composeService) create(ctx context.Context, project *types.Project, options compose.CreateOptions) error { +func (s *composeService) create(ctx context.Context, project *types.Project, options api.CreateOptions) error { if len(options.Services) == 0 { options.Services = project.ServiceNames() } @@ -140,9 +140,9 @@ func prepareVolumes(p *types.Project) error { func prepareNetworks(project *types.Project) { for k, network := range project.Networks { - network.Labels = network.Labels.Add(compose.NetworkLabel, k) - network.Labels = network.Labels.Add(compose.ProjectLabel, project.Name) - network.Labels = network.Labels.Add(compose.VersionLabel, internal.Version) + network.Labels = network.Labels.Add(api.NetworkLabel, k) + network.Labels = network.Labels.Add(api.ProjectLabel, project.Name) + network.Labels = network.Labels.Add(api.VersionLabel, internal.Version) project.Networks[k] = network } } @@ -183,9 +183,9 @@ func (s *composeService) ensureNetworks(ctx context.Context, networks types.Netw func (s *composeService) ensureProjectVolumes(ctx context.Context, project *types.Project) error { for k, volume := range project.Volumes { - volume.Labels = volume.Labels.Add(compose.VolumeLabel, k) - volume.Labels = volume.Labels.Add(compose.ProjectLabel, project.Name) - volume.Labels = volume.Labels.Add(compose.VersionLabel, internal.Version) + volume.Labels = volume.Labels.Add(api.VolumeLabel, k) + volume.Labels = volume.Labels.Add(api.ProjectLabel, project.Name) + volume.Labels = volume.Labels.Add(api.VersionLabel, internal.Version) err := s.ensureVolume(ctx, volume) if err != nil { return err @@ -215,16 +215,16 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project, labels[k] = v } - labels[compose.ProjectLabel] = p.Name - labels[compose.ServiceLabel] = service.Name - labels[compose.VersionLabel] = internal.Version - if _, ok := service.Labels[compose.OneoffLabel]; !ok { - labels[compose.OneoffLabel] = "False" + labels[api.ProjectLabel] = p.Name + labels[api.ServiceLabel] = service.Name + labels[api.VersionLabel] = internal.Version + if _, ok := service.Labels[api.OneoffLabel]; !ok { + labels[api.OneoffLabel] = "False" } - labels[compose.ConfigHashLabel] = hash - labels[compose.WorkingDirLabel] = p.WorkingDir - labels[compose.ConfigFilesLabel] = strings.Join(p.ComposeFiles, ",") - labels[compose.ContainerNumberLabel] = strconv.Itoa(number) + labels[api.ConfigHashLabel] = hash + labels[api.WorkingDirLabel] = p.WorkingDir + labels[api.ConfigFilesLabel] = strings.Join(p.ComposeFiles, ",") + labels[api.ContainerNumberLabel] = strconv.Itoa(number) var ( runCmd strslice.StrSlice diff --git a/local/compose/down.go b/local/compose/down.go index c3873883f..bd4fcc435 100644 --- a/local/compose/down.go +++ b/local/compose/down.go @@ -29,19 +29,19 @@ import ( "github.com/docker/docker/errdefs" "golang.org/x/sync/errgroup" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/progress" + "github.com/docker/compose-cli/pkg/api" ) type downOp func() error -func (s *composeService) Down(ctx context.Context, projectName string, options compose.DownOptions) error { +func (s *composeService) Down(ctx context.Context, projectName string, options api.DownOptions) error { return progress.Run(ctx, func(ctx context.Context) error { return s.down(ctx, projectName, options) }) } -func (s *composeService) down(ctx context.Context, projectName string, options compose.DownOptions) error { +func (s *composeService) down(ctx context.Context, projectName string, options api.DownOptions) error { w := progress.ContextWriter(ctx) resourceToRemove := false @@ -124,7 +124,7 @@ func (s *composeService) ensureVolumesDown(ctx context.Context, projectName stri return ops, nil } -func (s *composeService) ensureImagesDown(ctx context.Context, projectName string, options compose.DownOptions, w progress.Writer) []downOp { +func (s *composeService) ensureImagesDown(ctx context.Context, projectName string, options api.DownOptions, w progress.Writer) []downOp { var ops []downOp for image := range s.getServiceImages(options, projectName) { image := image @@ -151,7 +151,7 @@ func (s *composeService) ensureNetwoksDown(ctx context.Context, projectName stri return ops, nil } -func (s *composeService) getServiceImages(options compose.DownOptions, projectName string) map[string]struct{} { +func (s *composeService) getServiceImages(options api.DownOptions, projectName string) map[string]struct{} { images := map[string]struct{}{} for _, service := range options.Project.Services { image := service.Image @@ -262,7 +262,7 @@ func (s *composeService) projectFromContainerLabels(containers Containers, proje if options.ConfigPaths[0] == "-" { for _, container := range containers { fakeProject.Services = append(fakeProject.Services, types.ServiceConfig{ - Name: container.Labels[compose.ServiceLabel], + Name: container.Labels[api.ServiceLabel], }) } return fakeProject, nil @@ -276,8 +276,8 @@ func (s *composeService) projectFromContainerLabels(containers Containers, proje } func loadProjectOptionsFromLabels(c moby.Container) (*cli.ProjectOptions, error) { - return cli.NewProjectOptions(strings.Split(c.Labels[compose.ConfigFilesLabel], ","), + return cli.NewProjectOptions(strings.Split(c.Labels[api.ConfigFilesLabel], ","), cli.WithOsEnv, - cli.WithWorkingDirectory(c.Labels[compose.WorkingDirLabel]), - cli.WithName(c.Labels[compose.ProjectLabel])) + cli.WithWorkingDirectory(c.Labels[api.WorkingDirLabel]), + cli.WithName(c.Labels[api.ProjectLabel])) } diff --git a/local/compose/down_test.go b/local/compose/down_test.go index 26e5baf80..0361631bb 100644 --- a/local/compose/down_test.go +++ b/local/compose/down_test.go @@ -20,10 +20,10 @@ import ( "context" "testing" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/local/mocks" + compose "github.com/docker/compose-cli/pkg/api" - apitypes "github.com/docker/docker/api/types" + moby "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/volume" "github.com/golang/mock/gomock" @@ -37,17 +37,17 @@ func TestDown(t *testing.T) { tested.apiClient = api api.EXPECT().ContainerList(gomock.Any(), projectFilterListOpt()).Return( - []apitypes.Container{testContainer("service1", "123"), testContainer("service2", "456"), testContainer("service2", "789"), testContainer("service_orphan", "321")}, nil) + []moby.Container{testContainer("service1", "123"), testContainer("service2", "456"), testContainer("service2", "789"), testContainer("service_orphan", "321")}, nil) api.EXPECT().ContainerStop(gomock.Any(), "123", nil).Return(nil) api.EXPECT().ContainerStop(gomock.Any(), "456", nil).Return(nil) api.EXPECT().ContainerStop(gomock.Any(), "789", nil).Return(nil) - api.EXPECT().ContainerRemove(gomock.Any(), "123", apitypes.ContainerRemoveOptions{Force: true}).Return(nil) - api.EXPECT().ContainerRemove(gomock.Any(), "456", apitypes.ContainerRemoveOptions{Force: true}).Return(nil) - api.EXPECT().ContainerRemove(gomock.Any(), "789", apitypes.ContainerRemoveOptions{Force: true}).Return(nil) + api.EXPECT().ContainerRemove(gomock.Any(), "123", moby.ContainerRemoveOptions{Force: true}).Return(nil) + api.EXPECT().ContainerRemove(gomock.Any(), "456", moby.ContainerRemoveOptions{Force: true}).Return(nil) + api.EXPECT().ContainerRemove(gomock.Any(), "789", moby.ContainerRemoveOptions{Force: true}).Return(nil) - api.EXPECT().NetworkList(gomock.Any(), apitypes.NetworkListOptions{Filters: filters.NewArgs(projectFilter(testProject))}).Return([]apitypes.NetworkResource{{ID: "myProject_default"}}, nil) + api.EXPECT().NetworkList(gomock.Any(), moby.NetworkListOptions{Filters: filters.NewArgs(projectFilter(testProject))}).Return([]moby.NetworkResource{{ID: "myProject_default"}}, nil) api.EXPECT().NetworkRemove(gomock.Any(), "myProject_default").Return(nil) @@ -62,17 +62,17 @@ func TestDownRemoveOrphans(t *testing.T) { tested.apiClient = api api.EXPECT().ContainerList(gomock.Any(), projectFilterListOpt()).Return( - []apitypes.Container{testContainer("service1", "123"), testContainer("service2", "789"), testContainer("service_orphan", "321")}, nil) + []moby.Container{testContainer("service1", "123"), testContainer("service2", "789"), testContainer("service_orphan", "321")}, nil) api.EXPECT().ContainerStop(gomock.Any(), "123", nil).Return(nil) api.EXPECT().ContainerStop(gomock.Any(), "789", nil).Return(nil) api.EXPECT().ContainerStop(gomock.Any(), "321", nil).Return(nil) - api.EXPECT().ContainerRemove(gomock.Any(), "123", apitypes.ContainerRemoveOptions{Force: true}).Return(nil) - api.EXPECT().ContainerRemove(gomock.Any(), "789", apitypes.ContainerRemoveOptions{Force: true}).Return(nil) - api.EXPECT().ContainerRemove(gomock.Any(), "321", apitypes.ContainerRemoveOptions{Force: true}).Return(nil) + api.EXPECT().ContainerRemove(gomock.Any(), "123", moby.ContainerRemoveOptions{Force: true}).Return(nil) + api.EXPECT().ContainerRemove(gomock.Any(), "789", moby.ContainerRemoveOptions{Force: true}).Return(nil) + api.EXPECT().ContainerRemove(gomock.Any(), "321", moby.ContainerRemoveOptions{Force: true}).Return(nil) - api.EXPECT().NetworkList(gomock.Any(), apitypes.NetworkListOptions{Filters: filters.NewArgs(projectFilter(testProject))}).Return([]apitypes.NetworkResource{{ID: "myProject_default"}}, nil) + api.EXPECT().NetworkList(gomock.Any(), moby.NetworkListOptions{Filters: filters.NewArgs(projectFilter(testProject))}).Return([]moby.NetworkResource{{ID: "myProject_default"}}, nil) api.EXPECT().NetworkRemove(gomock.Any(), "myProject_default").Return(nil) @@ -87,14 +87,14 @@ func TestDownRemoveVolumes(t *testing.T) { tested.apiClient = api api.EXPECT().ContainerList(gomock.Any(), projectFilterListOpt()).Return( - []apitypes.Container{testContainer("service1", "123")}, nil) + []moby.Container{testContainer("service1", "123")}, nil) api.EXPECT().ContainerStop(gomock.Any(), "123", nil).Return(nil) - api.EXPECT().ContainerRemove(gomock.Any(), "123", apitypes.ContainerRemoveOptions{Force: true, RemoveVolumes: true}).Return(nil) + api.EXPECT().ContainerRemove(gomock.Any(), "123", moby.ContainerRemoveOptions{Force: true, RemoveVolumes: true}).Return(nil) - api.EXPECT().NetworkList(gomock.Any(), apitypes.NetworkListOptions{Filters: filters.NewArgs(projectFilter(testProject))}).Return(nil, nil) + api.EXPECT().NetworkList(gomock.Any(), moby.NetworkListOptions{Filters: filters.NewArgs(projectFilter(testProject))}).Return(nil, nil) - api.EXPECT().VolumeList(gomock.Any(), filters.NewArgs(projectFilter(testProject))).Return(volume.VolumeListOKBody{Volumes: []*apitypes.Volume{{Name: "myProject_volume"}}}, nil) + api.EXPECT().VolumeList(gomock.Any(), filters.NewArgs(projectFilter(testProject))).Return(volume.VolumeListOKBody{Volumes: []*moby.Volume{{Name: "myProject_volume"}}}, nil) api.EXPECT().VolumeRemove(gomock.Any(), "myProject_volume", true).Return(nil) err := tested.Down(context.Background(), testProject, compose.DownOptions{Volumes: true}) diff --git a/local/compose/events.go b/local/compose/events.go index 4b03c13ed..1da8b3e2d 100644 --- a/local/compose/events.go +++ b/local/compose/events.go @@ -21,14 +21,14 @@ import ( "strings" "time" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/utils" moby "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" ) -func (s *composeService) Events(ctx context.Context, project string, options compose.EventsOptions) error { +func (s *composeService) Events(ctx context.Context, project string, options api.EventsOptions) error { events, errors := s.apiClient.Events(ctx, moby.EventsOptions{ Filters: filters.NewArgs(projectFilter(project)), }) @@ -40,7 +40,7 @@ func (s *composeService) Events(ctx context.Context, project string, options com continue } - service := event.Actor.Attributes[compose.ServiceLabel] + service := event.Actor.Attributes[api.ServiceLabel] if len(options.Services) > 0 && !utils.StringContains(options.Services, service) { continue } @@ -57,7 +57,7 @@ func (s *composeService) Events(ctx context.Context, project string, options com if event.TimeNano != 0 { timestamp = time.Unix(0, event.TimeNano) } - err := options.Consumer(compose.Event{ + err := options.Consumer(api.Event{ Timestamp: timestamp, Service: service, Container: event.ID, diff --git a/local/compose/exec.go b/local/compose/exec.go index 98236cbe0..0e45aebe0 100644 --- a/local/compose/exec.go +++ b/local/compose/exec.go @@ -26,10 +26,10 @@ import ( "github.com/docker/docker/api/types/filters" "github.com/docker/docker/pkg/stdcopy" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" ) -func (s *composeService) Exec(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { +func (s *composeService) Exec(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) { service, err := project.GetService(opts.Service) if err != nil { return 0, err @@ -88,7 +88,7 @@ func (s *composeService) Exec(ctx context.Context, project *types.Project, opts } // inspired by https://github.com/docker/cli/blob/master/cli/command/container/exec.go#L116 -func (s *composeService) interactiveExec(ctx context.Context, opts compose.RunOptions, resp moby.HijackedResponse) error { +func (s *composeService) interactiveExec(ctx context.Context, opts api.RunOptions, resp moby.HijackedResponse) error { outputDone := make(chan error) inputDone := make(chan error) @@ -122,7 +122,7 @@ func (s *composeService) interactiveExec(ctx context.Context, opts compose.RunOp } } -func (s *composeService) getExecTarget(ctx context.Context, project *types.Project, service types.ServiceConfig, opts compose.RunOptions) (moby.Container, error) { +func (s *composeService) getExecTarget(ctx context.Context, project *types.Project, service types.ServiceConfig, opts api.RunOptions) (moby.Container, error) { containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{ Filters: filters.NewArgs( projectFilter(project.Name), @@ -140,7 +140,7 @@ func (s *composeService) getExecTarget(ctx context.Context, project *types.Proje return container, nil } -func (s *composeService) getExecEnvironment(project *types.Project, service types.ServiceConfig, opts compose.RunOptions) []string { +func (s *composeService) getExecEnvironment(project *types.Project, service types.ServiceConfig, opts api.RunOptions) []string { var env []string for k, v := range service.Environment.OverrideBy(types.NewMappingWithEquals(opts.Environment)). Resolve(func(s string) (string, bool) { diff --git a/local/compose/filters.go b/local/compose/filters.go index e64f69e67..178daa10a 100644 --- a/local/compose/filters.go +++ b/local/compose/filters.go @@ -19,20 +19,20 @@ package compose import ( "fmt" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" "github.com/docker/docker/api/types/filters" ) func projectFilter(projectName string) filters.KeyValuePair { - return filters.Arg("label", fmt.Sprintf("%s=%s", compose.ProjectLabel, projectName)) + return filters.Arg("label", fmt.Sprintf("%s=%s", api.ProjectLabel, projectName)) } func serviceFilter(serviceName string) filters.KeyValuePair { - return filters.Arg("label", fmt.Sprintf("%s=%s", compose.ServiceLabel, serviceName)) + return filters.Arg("label", fmt.Sprintf("%s=%s", api.ServiceLabel, serviceName)) } func slugFilter(slug string) filters.KeyValuePair { - return filters.Arg("label", fmt.Sprintf("%s=%s", compose.SlugLabel, slug)) + return filters.Arg("label", fmt.Sprintf("%s=%s", api.SlugLabel, slug)) } func oneOffFilter(b bool) filters.KeyValuePair { @@ -40,13 +40,13 @@ func oneOffFilter(b bool) filters.KeyValuePair { if b { v = "True" } - return filters.Arg("label", fmt.Sprintf("%s=%s", compose.OneoffLabel, v)) + return filters.Arg("label", fmt.Sprintf("%s=%s", api.OneoffLabel, v)) } func containerNumberFilter(index int) filters.KeyValuePair { - return filters.Arg("label", fmt.Sprintf("%s=%d", compose.ContainerNumberLabel, index)) + return filters.Arg("label", fmt.Sprintf("%s=%d", api.ContainerNumberLabel, index)) } func hasProjectLabelFilter() filters.KeyValuePair { - return filters.Arg("label", compose.ProjectLabel) + return filters.Arg("label", api.ProjectLabel) } diff --git a/local/compose/images.go b/local/compose/images.go index 311f6791a..844711e22 100644 --- a/local/compose/images.go +++ b/local/compose/images.go @@ -27,11 +27,11 @@ import ( "github.com/docker/docker/errdefs" "golang.org/x/sync/errgroup" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/utils" ) -func (s *composeService) Images(ctx context.Context, projectName string, options compose.ImagesOptions) ([]compose.ImageSummary, error) { +func (s *composeService) Images(ctx context.Context, projectName string, options api.ImagesOptions) ([]api.ImageSummary, error) { allContainers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{ Filters: filters.NewArgs(projectFilter(projectName)), }) @@ -42,7 +42,7 @@ func (s *composeService) Images(ctx context.Context, projectName string, options if len(options.Services) > 0 { // filter service containers for _, c := range allContainers { - if utils.StringContains(options.Services, c.Labels[compose.ServiceLabel]) { + if utils.StringContains(options.Services, c.Labels[api.ServiceLabel]) { containers = append(containers, c) } @@ -62,7 +62,7 @@ func (s *composeService) Images(ctx context.Context, projectName string, options if err != nil { return nil, err } - summary := make([]compose.ImageSummary, len(containers)) + summary := make([]api.ImageSummary, len(containers)) for i, container := range containers { img, ok := images[container.ImageID] if !ok { @@ -75,8 +75,8 @@ func (s *composeService) Images(ctx context.Context, projectName string, options return summary, nil } -func (s *composeService) getImages(ctx context.Context, images []string) (map[string]compose.ImageSummary, error) { - summary := map[string]compose.ImageSummary{} +func (s *composeService) getImages(ctx context.Context, images []string) (map[string]api.ImageSummary, error) { + summary := map[string]api.ImageSummary{} l := sync.Mutex{} eg, ctx := errgroup.WithContext(ctx) for _, img := range images { @@ -100,7 +100,7 @@ func (s *composeService) getImages(ctx context.Context, images []string) (map[st } } l.Lock() - summary[img] = compose.ImageSummary{ + summary[img] = api.ImageSummary{ ID: inspect.ID, Repository: repository, Tag: tag, diff --git a/local/compose/kill.go b/local/compose/kill.go index 4b951a5a4..e9a1f87fc 100644 --- a/local/compose/kill.go +++ b/local/compose/kill.go @@ -23,17 +23,17 @@ import ( moby "github.com/docker/docker/api/types" "golang.org/x/sync/errgroup" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/progress" + "github.com/docker/compose-cli/pkg/api" ) -func (s *composeService) Kill(ctx context.Context, project *types.Project, options compose.KillOptions) error { +func (s *composeService) Kill(ctx context.Context, project *types.Project, options api.KillOptions) error { return progress.Run(ctx, func(ctx context.Context) error { return s.kill(ctx, project, options) }) } -func (s *composeService) kill(ctx context.Context, project *types.Project, options compose.KillOptions) error { +func (s *composeService) kill(ctx context.Context, project *types.Project, options api.KillOptions) error { w := progress.ContextWriter(ctx) var containers Containers diff --git a/local/compose/kill_test.go b/local/compose/kill_test.go index 69bb01e8e..101ea64bc 100644 --- a/local/compose/kill_test.go +++ b/local/compose/kill_test.go @@ -26,10 +26,10 @@ import ( "gotest.tools/v3/assert" "github.com/compose-spec/compose-go/types" - apitypes "github.com/docker/docker/api/types" + moby "github.com/docker/docker/api/types" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/local/mocks" + compose "github.com/docker/compose-cli/pkg/api" ) const testProject = "testProject" @@ -46,7 +46,7 @@ func TestKillAll(t *testing.T) { ctx := context.Background() api.EXPECT().ContainerList(ctx, projectFilterListOpt()).Return( - []apitypes.Container{testContainer("service1", "123"), testContainer("service1", "456"), testContainer("service2", "789")}, nil) + []moby.Container{testContainer("service1", "123"), testContainer("service1", "456"), testContainer("service2", "789")}, nil) api.EXPECT().ContainerKill(anyCancellableContext(), "123", "").Return(nil) api.EXPECT().ContainerKill(anyCancellableContext(), "456", "").Return(nil) api.EXPECT().ContainerKill(anyCancellableContext(), "789", "").Return(nil) @@ -64,7 +64,7 @@ func TestKillSignal(t *testing.T) { project := types.Project{Name: testProject, Services: []types.ServiceConfig{testService("service1")}} ctx := context.Background() - api.EXPECT().ContainerList(ctx, projectFilterListOpt()).Return([]apitypes.Container{testContainer("service1", "123")}, nil) + api.EXPECT().ContainerList(ctx, projectFilterListOpt()).Return([]moby.Container{testContainer("service1", "123")}, nil) api.EXPECT().ContainerKill(anyCancellableContext(), "123", "SIGTERM").Return(nil) err := tested.kill(ctx, &project, compose.KillOptions{Signal: "SIGTERM"}) @@ -75,8 +75,8 @@ func testService(name string) types.ServiceConfig { return types.ServiceConfig{Name: name} } -func testContainer(service string, id string) apitypes.Container { - return apitypes.Container{ +func testContainer(service string, id string) moby.Container { + return moby.Container{ ID: id, Names: []string{id}, Labels: containerLabels(service), @@ -99,8 +99,8 @@ func anyCancellableContext() gomock.Matcher { return gomock.AssignableToTypeOf(ctxWithCancel) } -func projectFilterListOpt() apitypes.ContainerListOptions { - return apitypes.ContainerListOptions{ +func projectFilterListOpt() moby.ContainerListOptions { + return moby.ContainerListOptions{ Filters: filters.NewArgs(projectFilter(testProject)), All: true, } diff --git a/local/compose/logs.go b/local/compose/logs.go index 3d0323fc5..166026a52 100644 --- a/local/compose/logs.go +++ b/local/compose/logs.go @@ -20,7 +20,7 @@ import ( "context" "io" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/utils" "github.com/docker/docker/api/types" @@ -28,7 +28,7 @@ import ( "golang.org/x/sync/errgroup" ) -func (s *composeService) Logs(ctx context.Context, projectName string, consumer compose.LogConsumer, options compose.LogOptions) error { +func (s *composeService) Logs(ctx context.Context, projectName string, consumer api.LogConsumer, options api.LogOptions) error { list, err := s.getContainers(ctx, projectName, oneOffExclude, true, options.Services...) if err != nil { @@ -37,7 +37,7 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer eg, ctx := errgroup.WithContext(ctx) for _, c := range list { c := c - service := c.Labels[compose.ServiceLabel] + service := c.Labels[api.ServiceLabel] container, err := s.apiClient.ContainerInspect(ctx, c.ID) if err != nil { return err diff --git a/local/compose/ls.go b/local/compose/ls.go index 62d49b262..a57a10918 100644 --- a/local/compose/ls.go +++ b/local/compose/ls.go @@ -21,13 +21,13 @@ import ( "fmt" "sort" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" moby "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" ) -func (s *composeService) List(ctx context.Context, opts compose.ListOptions) ([]compose.Stack, error) { +func (s *composeService) List(ctx context.Context, opts api.ListOptions) ([]api.Stack, error) { list, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{ Filters: filters.NewArgs(hasProjectLabelFilter()), All: opts.All, @@ -39,14 +39,14 @@ func (s *composeService) List(ctx context.Context, opts compose.ListOptions) ([] return containersToStacks(list) } -func containersToStacks(containers []moby.Container) ([]compose.Stack, error) { - containersByLabel, keys, err := groupContainerByLabel(containers, compose.ProjectLabel) +func containersToStacks(containers []moby.Container) ([]api.Stack, error) { + containersByLabel, keys, err := groupContainerByLabel(containers, api.ProjectLabel) if err != nil { return nil, err } - var projects []compose.Stack + var projects []api.Stack for _, project := range keys { - projects = append(projects, compose.Stack{ + projects = append(projects, api.Stack{ ID: project, Name: project, Status: combinedStatus(containerToState(containersByLabel[project])), diff --git a/local/compose/ls_test.go b/local/compose/ls_test.go index c6a465a04..c964fc744 100644 --- a/local/compose/ls_test.go +++ b/local/compose/ls_test.go @@ -19,7 +19,7 @@ package compose import ( "testing" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" moby "github.com/docker/docker/api/types" "gotest.tools/v3/assert" @@ -30,22 +30,22 @@ func TestContainersToStacks(t *testing.T) { { ID: "service1", State: "running", - Labels: map[string]string{compose.ProjectLabel: "project1"}, + Labels: map[string]string{api.ProjectLabel: "project1"}, }, { ID: "service2", State: "running", - Labels: map[string]string{compose.ProjectLabel: "project1"}, + Labels: map[string]string{api.ProjectLabel: "project1"}, }, { ID: "service3", State: "running", - Labels: map[string]string{compose.ProjectLabel: "project2"}, + Labels: map[string]string{api.ProjectLabel: "project2"}, }, } stacks, err := containersToStacks(containers) assert.NilError(t, err) - assert.DeepEqual(t, stacks, []compose.Stack{ + assert.DeepEqual(t, stacks, []api.Stack{ { ID: "project1", Name: "project1", diff --git a/local/compose/pause.go b/local/compose/pause.go index 7642f1bdf..ea77e7603 100644 --- a/local/compose/pause.go +++ b/local/compose/pause.go @@ -22,17 +22,17 @@ import ( moby "github.com/docker/docker/api/types" "golang.org/x/sync/errgroup" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/progress" + "github.com/docker/compose-cli/pkg/api" ) -func (s *composeService) Pause(ctx context.Context, project string, options compose.PauseOptions) error { +func (s *composeService) Pause(ctx context.Context, project string, options api.PauseOptions) error { return progress.Run(ctx, func(ctx context.Context) error { return s.pause(ctx, project, options) }) } -func (s *composeService) pause(ctx context.Context, project string, options compose.PauseOptions) error { +func (s *composeService) pause(ctx context.Context, project string, options api.PauseOptions) error { containers, err := s.getContainers(ctx, project, oneOffExclude, true, options.Services...) if err != nil { return err @@ -54,13 +54,13 @@ func (s *composeService) pause(ctx context.Context, project string, options comp return eg.Wait() } -func (s *composeService) UnPause(ctx context.Context, project string, options compose.PauseOptions) error { +func (s *composeService) UnPause(ctx context.Context, project string, options api.PauseOptions) error { return progress.Run(ctx, func(ctx context.Context) error { return s.unPause(ctx, project, options) }) } -func (s *composeService) unPause(ctx context.Context, project string, options compose.PauseOptions) error { +func (s *composeService) unPause(ctx context.Context, project string, options api.PauseOptions) error { containers, err := s.getContainers(ctx, project, oneOffExclude, true, options.Services...) if err != nil { return err diff --git a/local/compose/port.go b/local/compose/port.go index 012075211..c9f4c069e 100644 --- a/local/compose/port.go +++ b/local/compose/port.go @@ -20,13 +20,13 @@ import ( "context" "fmt" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" moby "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" ) -func (s *composeService) Port(ctx context.Context, project string, service string, port int, options compose.PortOptions) (string, int, error) { +func (s *composeService) Port(ctx context.Context, project string, service string, port int, options api.PortOptions) (string, int, error) { list, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{ Filters: filters.NewArgs( projectFilter(project), diff --git a/local/compose/printer.go b/local/compose/printer.go index 42bee46ec..0ba41496a 100644 --- a/local/compose/printer.go +++ b/local/compose/printer.go @@ -19,21 +19,21 @@ package compose import ( "fmt" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" "github.com/sirupsen/logrus" ) // logPrinter watch application containers an collect their logs type logPrinter interface { - HandleEvent(event compose.ContainerEvent) + HandleEvent(event api.ContainerEvent) Run(cascadeStop bool, exitCodeFrom string, stopFn func() error) (int, error) Cancel() } // newLogPrinter builds a LogPrinter passing containers logs to LogConsumer -func newLogPrinter(consumer compose.LogConsumer) logPrinter { - queue := make(chan compose.ContainerEvent) +func newLogPrinter(consumer api.LogConsumer) logPrinter { + queue := make(chan api.ContainerEvent) printer := printer{ consumer: consumer, queue: queue, @@ -42,17 +42,17 @@ func newLogPrinter(consumer compose.LogConsumer) logPrinter { } func (p *printer) Cancel() { - p.queue <- compose.ContainerEvent{ - Type: compose.UserCancel, + p.queue <- api.ContainerEvent{ + Type: api.UserCancel, } } type printer struct { - queue chan compose.ContainerEvent - consumer compose.LogConsumer + queue chan api.ContainerEvent + consumer api.LogConsumer } -func (p *printer) HandleEvent(event compose.ContainerEvent) { +func (p *printer) HandleEvent(event api.ContainerEvent) { p.queue <- event } @@ -66,15 +66,15 @@ func (p *printer) Run(cascadeStop bool, exitCodeFrom string, stopFn func() error event := <-p.queue container := event.Container switch event.Type { - case compose.UserCancel: + case api.UserCancel: aborting = true - case compose.ContainerEventAttach: + case api.ContainerEventAttach: if _, ok := containers[container]; ok { continue } containers[container] = struct{}{} p.consumer.Register(container) - case compose.ContainerEventExit: + case api.ContainerEventExit: if !event.Restarting { delete(containers, container) } @@ -102,7 +102,7 @@ func (p *printer) Run(cascadeStop bool, exitCodeFrom string, stopFn func() error // Last container terminated, done return exitCode, nil } - case compose.ContainerEventLog: + case api.ContainerEventLog: if !aborting { p.consumer.Log(container, event.Service, event.Line) } diff --git a/local/compose/ps.go b/local/compose/ps.go index a226db127..1f8c590cd 100644 --- a/local/compose/ps.go +++ b/local/compose/ps.go @@ -21,11 +21,11 @@ import ( "fmt" "sort" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" "golang.org/x/sync/errgroup" ) -func (s *composeService) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) { +func (s *composeService) Ps(ctx context.Context, projectName string, options api.PsOptions) ([]api.ContainerSummary, error) { oneOff := oneOffExclude if options.All { oneOff = oneOffInclude @@ -35,13 +35,13 @@ func (s *composeService) Ps(ctx context.Context, projectName string, options com return nil, err } - summary := make([]compose.ContainerSummary, len(containers)) + summary := make([]api.ContainerSummary, len(containers)) eg, ctx := errgroup.WithContext(ctx) for i, c := range containers { container := c i := i eg.Go(func() error { - var publishers []compose.PortPublisher + var publishers []api.PortPublisher sort.Slice(container.Ports, func(i, j int) bool { return container.Ports[i].PrivatePort < container.Ports[j].PrivatePort }) @@ -50,7 +50,7 @@ func (s *composeService) Ps(ctx context.Context, projectName string, options com if p.PublicPort != 0 { url = fmt.Sprintf("%s:%d", p.IP, p.PublicPort) } - publishers = append(publishers, compose.PortPublisher{ + publishers = append(publishers, api.PortPublisher{ URL: url, TargetPort: int(p.PrivatePort), PublishedPort: int(p.PublicPort), @@ -78,11 +78,11 @@ func (s *composeService) Ps(ctx context.Context, projectName string, options com } } - summary[i] = compose.ContainerSummary{ + summary[i] = api.ContainerSummary{ ID: container.ID, Name: getCanonicalContainerName(container), - Project: container.Labels[compose.ProjectLabel], - Service: container.Labels[compose.ServiceLabel], + Project: container.Labels[api.ProjectLabel], + Service: container.Labels[api.ServiceLabel], State: container.State, Health: health, ExitCode: exitCode, diff --git a/local/compose/ps_test.go b/local/compose/ps_test.go index c21de7b57..6e05abbbe 100644 --- a/local/compose/ps_test.go +++ b/local/compose/ps_test.go @@ -23,11 +23,11 @@ import ( "github.com/golang/mock/gomock" "gotest.tools/v3/assert" - apitypes "github.com/docker/docker/api/types" + moby "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/local/mocks" + compose "github.com/docker/compose-cli/pkg/api" ) func TestPs(t *testing.T) { @@ -39,12 +39,12 @@ func TestPs(t *testing.T) { ctx := context.Background() args := filters.NewArgs(projectFilter(testProject)) args.Add("label", "com.docker.compose.oneoff=False") - listOpts := apitypes.ContainerListOptions{Filters: args, All: true} + listOpts := moby.ContainerListOptions{Filters: args, All: true} c1, inspect1 := containerDetails("service1", "123", "running", "healthy", 0) c2, inspect2 := containerDetails("service1", "456", "running", "", 0) - c2.Ports = []apitypes.Port{{PublicPort: 80, PrivatePort: 90, IP: "localhost"}} + c2.Ports = []moby.Port{{PublicPort: 80, PrivatePort: 90, IP: "localhost"}} c3, inspect3 := containerDetails("service2", "789", "exited", "", 130) - api.EXPECT().ContainerList(ctx, listOpts).Return([]apitypes.Container{c1, c2, c3}, nil) + api.EXPECT().ContainerList(ctx, listOpts).Return([]moby.Container{c1, c2, c3}, nil) api.EXPECT().ContainerInspect(anyCancellableContext(), "123").Return(inspect1, nil) api.EXPECT().ContainerInspect(anyCancellableContext(), "456").Return(inspect2, nil) api.EXPECT().ContainerInspect(anyCancellableContext(), "789").Return(inspect3, nil) @@ -60,13 +60,13 @@ func TestPs(t *testing.T) { assert.DeepEqual(t, containers, expected) } -func containerDetails(service string, id string, status string, health string, exitCode int) (apitypes.Container, apitypes.ContainerJSON) { - container := apitypes.Container{ +func containerDetails(service string, id string, status string, health string, exitCode int) (moby.Container, moby.ContainerJSON) { + container := moby.Container{ ID: id, Names: []string{"/" + id}, Labels: containerLabels(service), State: status, } - inspect := apitypes.ContainerJSON{ContainerJSONBase: &apitypes.ContainerJSONBase{State: &apitypes.ContainerState{Status: status, Health: &apitypes.Health{Status: health}, ExitCode: exitCode}}} + inspect := moby.ContainerJSON{ContainerJSONBase: &moby.ContainerJSONBase{State: &moby.ContainerState{Status: status, Health: &moby.Health{Status: health}, ExitCode: exitCode}}} return container, inspect } diff --git a/local/compose/pull.go b/local/compose/pull.go index cc8d16e5b..2651b5620 100644 --- a/local/compose/pull.go +++ b/local/compose/pull.go @@ -32,12 +32,12 @@ import ( "github.com/docker/docker/registry" "golang.org/x/sync/errgroup" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/progress" "github.com/docker/compose-cli/cli/metrics" + "github.com/docker/compose-cli/pkg/api" ) -func (s *composeService) Pull(ctx context.Context, project *types.Project, opts compose.PullOptions) error { +func (s *composeService) Pull(ctx context.Context, project *types.Project, opts api.PullOptions) error { if opts.Quiet { return s.pull(ctx, project, opts) } @@ -46,7 +46,7 @@ func (s *composeService) Pull(ctx context.Context, project *types.Project, opts }) } -func (s *composeService) pull(ctx context.Context, project *types.Project, opts compose.PullOptions) error { +func (s *composeService) pull(ctx context.Context, project *types.Project, opts api.PullOptions) error { info, err := s.apiClient.Info(ctx) if err != nil { return err diff --git a/local/compose/push.go b/local/compose/push.go index a50b4a6ca..1e5b51da4 100644 --- a/local/compose/push.go +++ b/local/compose/push.go @@ -33,18 +33,18 @@ import ( "github.com/pkg/errors" "golang.org/x/sync/errgroup" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/config" "github.com/docker/compose-cli/api/progress" + "github.com/docker/compose-cli/pkg/api" ) -func (s *composeService) Push(ctx context.Context, project *types.Project, options compose.PushOptions) error { +func (s *composeService) Push(ctx context.Context, project *types.Project, options api.PushOptions) error { return progress.Run(ctx, func(ctx context.Context) error { return s.push(ctx, project, options) }) } -func (s *composeService) push(ctx context.Context, project *types.Project, options compose.PushOptions) error { +func (s *composeService) push(ctx context.Context, project *types.Project, options api.PushOptions) error { configFile, err := cliconfig.Load(config.Dir()) if err != nil { return err diff --git a/local/compose/remove.go b/local/compose/remove.go index dba81c69e..302559878 100644 --- a/local/compose/remove.go +++ b/local/compose/remove.go @@ -21,9 +21,9 @@ import ( "fmt" "strings" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/progress" status "github.com/docker/compose-cli/local/moby" + "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/utils/prompt" "github.com/compose-spec/compose-go/types" @@ -31,7 +31,7 @@ import ( "golang.org/x/sync/errgroup" ) -func (s *composeService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) error { +func (s *composeService) Remove(ctx context.Context, project *types.Project, options api.RemoveOptions) error { services := options.Services if len(services) == 0 { services = project.ServiceNames() @@ -72,7 +72,7 @@ func (s *composeService) Remove(ctx context.Context, project *types.Project, opt }) } -func (s *composeService) remove(ctx context.Context, containers Containers, options compose.RemoveOptions) error { +func (s *composeService) remove(ctx context.Context, containers Containers, options api.RemoveOptions) error { w := progress.ContextWriter(ctx) eg, ctx := errgroup.WithContext(ctx) for _, c := range containers { diff --git a/local/compose/restart.go b/local/compose/restart.go index 16eb7943a..d760506c4 100644 --- a/local/compose/restart.go +++ b/local/compose/restart.go @@ -19,20 +19,20 @@ package compose import ( "context" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/progress" + "github.com/docker/compose-cli/pkg/api" "github.com/docker/compose-cli/utils" "github.com/compose-spec/compose-go/types" ) -func (s *composeService) Restart(ctx context.Context, project *types.Project, options compose.RestartOptions) error { +func (s *composeService) Restart(ctx context.Context, project *types.Project, options api.RestartOptions) error { return progress.Run(ctx, func(ctx context.Context) error { return s.restart(ctx, project, options) }) } -func (s *composeService) restart(ctx context.Context, project *types.Project, options compose.RestartOptions) error { +func (s *composeService) restart(ctx context.Context, project *types.Project, options api.RestartOptions) error { ctx, err := s.getUpdatedContainersStateContext(ctx, project.Name) if err != nil { return err diff --git a/local/compose/run.go b/local/compose/run.go index 81a0c22e2..7ecde9e58 100644 --- a/local/compose/run.go +++ b/local/compose/run.go @@ -20,16 +20,16 @@ import ( "context" "fmt" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" "github.com/compose-spec/compose-go/types" - apitypes "github.com/docker/docker/api/types" + moby "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/filters" - moby "github.com/docker/docker/pkg/stringid" + "github.com/docker/docker/pkg/stringid" ) -func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) { +func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) { observedState, err := s.getContainers(ctx, project.Name, oneOffInclude, true) if err != nil { return 0, err @@ -44,14 +44,14 @@ func (s *composeService) RunOneOffContainer(ctx context.Context, project *types. applyRunOptions(project, &service, opts) - slug := moby.GenerateRandomID() + slug := stringid.GenerateRandomID() if service.ContainerName == "" { - service.ContainerName = fmt.Sprintf("%s_%s_run_%s", project.Name, service.Name, moby.TruncateID(slug)) + service.ContainerName = fmt.Sprintf("%s_%s_run_%s", project.Name, service.Name, stringid.TruncateID(slug)) } service.Scale = 1 service.StdinOpen = true - service.Labels = service.Labels.Add(compose.SlugLabel, slug) - service.Labels = service.Labels.Add(compose.OneoffLabel, "True") + service.Labels = service.Labels.Add(api.SlugLabel, slug) + service.Labels = service.Labels.Add(api.OneoffLabel, "True") if err := s.ensureImagesExists(ctx, project, observedState, false); err != nil { // all dependencies already checked, but might miss service img return 0, err @@ -65,7 +65,7 @@ func (s *composeService) RunOneOffContainer(ctx context.Context, project *types. containerID := service.ContainerName if opts.Detach { - err := s.apiClient.ContainerStart(ctx, containerID, apitypes.ContainerStartOptions{}) + err := s.apiClient.ContainerStart(ctx, containerID, moby.ContainerStartOptions{}) if err != nil { return 0, err } @@ -73,7 +73,7 @@ func (s *composeService) RunOneOffContainer(ctx context.Context, project *types. return 0, nil } - containers, err := s.apiClient.ContainerList(ctx, apitypes.ContainerListOptions{ + containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{ Filters: filters.NewArgs(slugFilter(slug)), All: true, }) @@ -89,7 +89,7 @@ func (s *composeService) RunOneOffContainer(ctx context.Context, project *types. statusC, errC := s.apiClient.ContainerWait(context.Background(), oneoffContainer.ID, container.WaitConditionNextExit) - err = s.apiClient.ContainerStart(ctx, containerID, apitypes.ContainerStartOptions{}) + err = s.apiClient.ContainerStart(ctx, containerID, moby.ContainerStartOptions{}) if err != nil { return 0, err } @@ -105,7 +105,7 @@ func (s *composeService) RunOneOffContainer(ctx context.Context, project *types. } -func applyRunOptions(project *types.Project, service *types.ServiceConfig, opts compose.RunOptions) { +func applyRunOptions(project *types.Project, service *types.ServiceConfig, opts api.RunOptions) { service.Tty = opts.Tty service.ContainerName = opts.Name diff --git a/local/compose/start.go b/local/compose/start.go index edd8c3e2e..9461ad168 100644 --- a/local/compose/start.go +++ b/local/compose/start.go @@ -24,17 +24,17 @@ import ( "github.com/pkg/errors" "golang.org/x/sync/errgroup" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/progress" + "github.com/docker/compose-cli/pkg/api" ) -func (s *composeService) Start(ctx context.Context, project *types.Project, options compose.StartOptions) error { +func (s *composeService) Start(ctx context.Context, project *types.Project, options api.StartOptions) error { return progress.Run(ctx, func(ctx context.Context) error { return s.start(ctx, project, options, nil) }) } -func (s *composeService) start(ctx context.Context, project *types.Project, options compose.StartOptions, listener compose.ContainerEventListener) error { +func (s *composeService) start(ctx context.Context, project *types.Project, options api.StartOptions, listener api.ContainerEventListener) error { if len(options.AttachTo) == 0 { options.AttachTo = project.ServiceNames() } @@ -65,16 +65,16 @@ func (s *composeService) start(ctx context.Context, project *types.Project, opti type containerWatchFn func(container moby.Container) error // watchContainers uses engine events to capture container start/die and notify ContainerEventListener -func (s *composeService) watchContainers(project *types.Project, services []string, listener compose.ContainerEventListener, containers Containers, onStart containerWatchFn) error { +func (s *composeService) watchContainers(project *types.Project, services []string, listener api.ContainerEventListener, containers Containers, onStart containerWatchFn) error { watched := map[string]int{} for _, c := range containers { watched[c.ID] = 0 } ctx, stop := context.WithCancel(context.Background()) - err := s.Events(ctx, project.Name, compose.EventsOptions{ + err := s.Events(ctx, project.Name, api.EventsOptions{ Services: services, - Consumer: func(event compose.Event) error { + Consumer: func(event api.Event) error { inspected, err := s.apiClient.ContainerInspect(ctx, event.Container) if err != nil { return err @@ -92,10 +92,10 @@ func (s *composeService) watchContainers(project *types.Project, services []stri // Container terminated. willRestart := inspected.HostConfig.RestartPolicy.MaximumRetryCount > restarted - listener(compose.ContainerEvent{ - Type: compose.ContainerEventExit, + listener(api.ContainerEvent{ + Type: api.ContainerEventExit, Container: name, - Service: container.Labels[compose.ServiceLabel], + Service: container.Labels[api.ServiceLabel], ExitCode: inspected.State.ExitCode, Restarting: willRestart, }) diff --git a/local/compose/stop.go b/local/compose/stop.go index 282c8359f..d0e68a722 100644 --- a/local/compose/stop.go +++ b/local/compose/stop.go @@ -19,19 +19,19 @@ package compose import ( "context" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/progress" + "github.com/docker/compose-cli/pkg/api" "github.com/compose-spec/compose-go/types" ) -func (s *composeService) Stop(ctx context.Context, project *types.Project, options compose.StopOptions) error { +func (s *composeService) Stop(ctx context.Context, project *types.Project, options api.StopOptions) error { return progress.Run(ctx, func(ctx context.Context) error { return s.stop(ctx, project, options) }) } -func (s *composeService) stop(ctx context.Context, project *types.Project, options compose.StopOptions) error { +func (s *composeService) stop(ctx context.Context, project *types.Project, options api.StopOptions) error { w := progress.ContextWriter(ctx) services := options.Services diff --git a/local/compose/stop_test.go b/local/compose/stop_test.go index a3ce3818c..92c6d3f91 100644 --- a/local/compose/stop_test.go +++ b/local/compose/stop_test.go @@ -23,8 +23,8 @@ import ( moby "github.com/docker/docker/api/types" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/local/mocks" + compose "github.com/docker/compose-cli/pkg/api" "github.com/compose-spec/compose-go/types" "github.com/golang/mock/gomock" diff --git a/local/compose/top.go b/local/compose/top.go index 6e038a1a0..4eeeb7711 100644 --- a/local/compose/top.go +++ b/local/compose/top.go @@ -19,11 +19,11 @@ package compose import ( "context" - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" "golang.org/x/sync/errgroup" ) -func (s *composeService) Top(ctx context.Context, projectName string, services []string) ([]compose.ContainerProcSummary, error) { +func (s *composeService) Top(ctx context.Context, projectName string, services []string) ([]api.ContainerProcSummary, error) { var containers Containers containers, err := s.getContainers(ctx, projectName, oneOffInclude, false) if err != nil { @@ -32,7 +32,7 @@ func (s *composeService) Top(ctx context.Context, projectName string, services [ if len(services) > 0 { containers = containers.filter(isService(services...)) } - summary := make([]compose.ContainerProcSummary, len(containers)) + summary := make([]api.ContainerProcSummary, len(containers)) eg, ctx := errgroup.WithContext(ctx) for i, c := range containers { container := c @@ -42,7 +42,7 @@ func (s *composeService) Top(ctx context.Context, projectName string, services [ if err != nil { return err } - summary[i] = compose.ContainerProcSummary{ + summary[i] = api.ContainerProcSummary{ ID: container.ID, Name: getCanonicalContainerName(container), Processes: topContent.Processes, diff --git a/local/compose/up.go b/local/compose/up.go index 3d2bfd96d..6da29a90f 100644 --- a/local/compose/up.go +++ b/local/compose/up.go @@ -23,15 +23,15 @@ import ( "os/signal" "syscall" - "github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/progress" + "github.com/docker/compose-cli/pkg/api" "github.com/compose-spec/compose-go/types" "github.com/docker/cli/cli" "golang.org/x/sync/errgroup" ) -func (s *composeService) Up(ctx context.Context, project *types.Project, options compose.UpOptions) error { +func (s *composeService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error { err := progress.Run(ctx, func(ctx context.Context) error { err := s.create(ctx, project, options.Create) if err != nil { @@ -57,10 +57,10 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options return progress.Run(ctx, func(ctx context.Context) error { go func() { <-signalChan - s.Kill(ctx, project, compose.KillOptions{}) // nolint:errcheck + s.Kill(ctx, project, api.KillOptions{}) // nolint:errcheck }() - return s.Stop(ctx, project, compose.StopOptions{}) + return s.Stop(ctx, project, api.StopOptions{}) }) } go func() { diff --git a/local/containers.go b/local/containers.go index f2b28738a..358b2f56e 100644 --- a/local/containers.go +++ b/local/containers.go @@ -34,8 +34,8 @@ import ( "github.com/pkg/errors" "github.com/docker/compose-cli/api/containers" - "github.com/docker/compose-cli/api/errdefs" "github.com/docker/compose-cli/local/moby" + "github.com/docker/compose-cli/pkg/api" ) type containerService struct { @@ -111,7 +111,7 @@ func (cs *containerService) Run(ctx context.Context, r containers.ContainerConfi for _, v := range r.Volumes { tokens := strings.Split(v, ":") if len(tokens) != 2 { - return errors.Wrapf(errdefs.ErrParsingFailed, "volume %q has invalid format", v) + return errors.Wrapf(api.ErrParsingFailed, "volume %q has invalid format", v) } src := tokens[0] tgt := tokens[1] @@ -271,7 +271,7 @@ func (cs *containerService) Delete(ctx context.Context, containerID string, requ Force: request.Force, }) if client.IsErrNotFound(err) { - return errors.Wrapf(errdefs.ErrNotFound, "container %q", containerID) + return errors.Wrapf(api.ErrNotFound, "container %q", containerID) } return err } diff --git a/main.go b/main.go index 725cf4172..6e23a7302 100644 --- a/main.go +++ b/main.go @@ -25,12 +25,12 @@ import ( "github.com/docker/cli/cli/command" "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/cli/cmd/compose" "github.com/docker/compose-cli/cli/metrics" "github.com/docker/compose-cli/internal" impl "github.com/docker/compose-cli/local/compose" + api "github.com/docker/compose-cli/pkg/api" ) func main() { diff --git a/api/compose/api.go b/pkg/api/api.go similarity index 99% rename from api/compose/api.go rename to pkg/api/api.go index b63c244fc..7e37d32ed 100644 --- a/api/compose/api.go +++ b/pkg/api/api.go @@ -14,7 +14,7 @@ limitations under the License. */ -package compose +package api import ( "context" diff --git a/api/compose/api_test.go b/pkg/api/api_test.go similarity index 98% rename from api/compose/api_test.go rename to pkg/api/api_test.go index fca9d0fcc..0d9633151 100644 --- a/api/compose/api_test.go +++ b/pkg/api/api_test.go @@ -14,7 +14,7 @@ limitations under the License. */ -package compose +package api import ( "testing" diff --git a/api/errdefs/errors.go b/pkg/api/errors.go similarity index 99% rename from api/errdefs/errors.go rename to pkg/api/errors.go index 44bd93646..10f628be5 100644 --- a/api/errdefs/errors.go +++ b/pkg/api/errors.go @@ -14,7 +14,7 @@ limitations under the License. */ -package errdefs +package api import ( "github.com/pkg/errors" diff --git a/api/errdefs/errors_test.go b/pkg/api/errors_test.go similarity index 98% rename from api/errdefs/errors_test.go rename to pkg/api/errors_test.go index 5d9253c41..ea47edb61 100644 --- a/api/errdefs/errors_test.go +++ b/pkg/api/errors_test.go @@ -14,7 +14,7 @@ limitations under the License. */ -package errdefs +package api import ( "testing" diff --git a/api/compose/labels.go b/pkg/api/labels.go similarity index 99% rename from api/compose/labels.go rename to pkg/api/labels.go index dbe762b55..db51df5fe 100644 --- a/api/compose/labels.go +++ b/pkg/api/labels.go @@ -14,7 +14,7 @@ limitations under the License. */ -package compose +package api const ( // ProjectLabel allow to track resource related to a compose project diff --git a/api/compose/proxy.go b/pkg/api/proxy.go similarity index 91% rename from api/compose/proxy.go rename to pkg/api/proxy.go index 765902b1d..9d01eee06 100644 --- a/api/compose/proxy.go +++ b/pkg/api/proxy.go @@ -14,13 +14,11 @@ limitations under the License. */ -package compose +package api import ( "context" - "github.com/docker/compose-cli/api/errdefs" - "github.com/compose-spec/compose-go/types" ) @@ -101,7 +99,7 @@ func (s *ServiceProxy) WithInterceptor(interceptors ...Interceptor) *ServiceProx //Build implements Service interface func (s *ServiceProxy) Build(ctx context.Context, project *types.Project, options BuildOptions) error { if s.BuildFn == nil { - return errdefs.ErrNotImplemented + return ErrNotImplemented } for _, i := range s.interceptors { i(ctx, project) @@ -112,7 +110,7 @@ func (s *ServiceProxy) Build(ctx context.Context, project *types.Project, option //Push implements Service interface func (s *ServiceProxy) Push(ctx context.Context, project *types.Project, options PushOptions) error { if s.PushFn == nil { - return errdefs.ErrNotImplemented + return ErrNotImplemented } for _, i := range s.interceptors { i(ctx, project) @@ -123,7 +121,7 @@ func (s *ServiceProxy) Push(ctx context.Context, project *types.Project, options //Pull implements Service interface func (s *ServiceProxy) Pull(ctx context.Context, project *types.Project, options PullOptions) error { if s.PullFn == nil { - return errdefs.ErrNotImplemented + return ErrNotImplemented } for _, i := range s.interceptors { i(ctx, project) @@ -134,7 +132,7 @@ func (s *ServiceProxy) Pull(ctx context.Context, project *types.Project, options //Create implements Service interface func (s *ServiceProxy) Create(ctx context.Context, project *types.Project, options CreateOptions) error { if s.CreateFn == nil { - return errdefs.ErrNotImplemented + return ErrNotImplemented } for _, i := range s.interceptors { i(ctx, project) @@ -145,7 +143,7 @@ func (s *ServiceProxy) Create(ctx context.Context, project *types.Project, optio //Start implements Service interface func (s *ServiceProxy) Start(ctx context.Context, project *types.Project, options StartOptions) error { if s.StartFn == nil { - return errdefs.ErrNotImplemented + return ErrNotImplemented } for _, i := range s.interceptors { i(ctx, project) @@ -156,7 +154,7 @@ func (s *ServiceProxy) Start(ctx context.Context, project *types.Project, option //Restart implements Service interface func (s *ServiceProxy) Restart(ctx context.Context, project *types.Project, options RestartOptions) error { if s.RestartFn == nil { - return errdefs.ErrNotImplemented + return ErrNotImplemented } for _, i := range s.interceptors { i(ctx, project) @@ -167,7 +165,7 @@ func (s *ServiceProxy) Restart(ctx context.Context, project *types.Project, opti //Stop implements Service interface func (s *ServiceProxy) Stop(ctx context.Context, project *types.Project, options StopOptions) error { if s.StopFn == nil { - return errdefs.ErrNotImplemented + return ErrNotImplemented } for _, i := range s.interceptors { i(ctx, project) @@ -178,7 +176,7 @@ func (s *ServiceProxy) Stop(ctx context.Context, project *types.Project, options //Up implements Service interface func (s *ServiceProxy) Up(ctx context.Context, project *types.Project, options UpOptions) error { if s.UpFn == nil { - return errdefs.ErrNotImplemented + return ErrNotImplemented } for _, i := range s.interceptors { i(ctx, project) @@ -189,7 +187,7 @@ func (s *ServiceProxy) Up(ctx context.Context, project *types.Project, options U //Down implements Service interface func (s *ServiceProxy) Down(ctx context.Context, project string, options DownOptions) error { if s.DownFn == nil { - return errdefs.ErrNotImplemented + return ErrNotImplemented } return s.DownFn(ctx, project, options) } @@ -197,7 +195,7 @@ func (s *ServiceProxy) Down(ctx context.Context, project string, options DownOpt //Logs implements Service interface func (s *ServiceProxy) Logs(ctx context.Context, project string, consumer LogConsumer, options LogOptions) error { if s.LogsFn == nil { - return errdefs.ErrNotImplemented + return ErrNotImplemented } return s.LogsFn(ctx, project, consumer, options) } @@ -205,7 +203,7 @@ func (s *ServiceProxy) Logs(ctx context.Context, project string, consumer LogCon //Ps implements Service interface func (s *ServiceProxy) Ps(ctx context.Context, project string, options PsOptions) ([]ContainerSummary, error) { if s.PsFn == nil { - return nil, errdefs.ErrNotImplemented + return nil, ErrNotImplemented } return s.PsFn(ctx, project, options) } @@ -213,7 +211,7 @@ func (s *ServiceProxy) Ps(ctx context.Context, project string, options PsOptions //List implements Service interface func (s *ServiceProxy) List(ctx context.Context, options ListOptions) ([]Stack, error) { if s.ListFn == nil { - return nil, errdefs.ErrNotImplemented + return nil, ErrNotImplemented } return s.ListFn(ctx, options) } @@ -221,7 +219,7 @@ func (s *ServiceProxy) List(ctx context.Context, options ListOptions) ([]Stack, //Convert implements Service interface func (s *ServiceProxy) Convert(ctx context.Context, project *types.Project, options ConvertOptions) ([]byte, error) { if s.ConvertFn == nil { - return nil, errdefs.ErrNotImplemented + return nil, ErrNotImplemented } for _, i := range s.interceptors { i(ctx, project) @@ -232,7 +230,7 @@ func (s *ServiceProxy) Convert(ctx context.Context, project *types.Project, opti //Kill implements Service interface func (s *ServiceProxy) Kill(ctx context.Context, project *types.Project, options KillOptions) error { if s.KillFn == nil { - return errdefs.ErrNotImplemented + return ErrNotImplemented } for _, i := range s.interceptors { i(ctx, project) @@ -243,7 +241,7 @@ func (s *ServiceProxy) Kill(ctx context.Context, project *types.Project, options //RunOneOffContainer implements Service interface func (s *ServiceProxy) RunOneOffContainer(ctx context.Context, project *types.Project, options RunOptions) (int, error) { if s.RunOneOffContainerFn == nil { - return 0, errdefs.ErrNotImplemented + return 0, ErrNotImplemented } for _, i := range s.interceptors { i(ctx, project) @@ -254,7 +252,7 @@ func (s *ServiceProxy) RunOneOffContainer(ctx context.Context, project *types.Pr //Remove implements Service interface func (s *ServiceProxy) Remove(ctx context.Context, project *types.Project, options RemoveOptions) error { if s.RemoveFn == nil { - return errdefs.ErrNotImplemented + return ErrNotImplemented } for _, i := range s.interceptors { i(ctx, project) @@ -265,7 +263,7 @@ func (s *ServiceProxy) Remove(ctx context.Context, project *types.Project, optio //Exec implements Service interface func (s *ServiceProxy) Exec(ctx context.Context, project *types.Project, options RunOptions) (int, error) { if s.ExecFn == nil { - return 0, errdefs.ErrNotImplemented + return 0, ErrNotImplemented } for _, i := range s.interceptors { i(ctx, project) @@ -276,7 +274,7 @@ func (s *ServiceProxy) Exec(ctx context.Context, project *types.Project, options //Copy implements Service interface func (s *ServiceProxy) Copy(ctx context.Context, project *types.Project, options CopyOptions) error { if s.CopyFn == nil { - return errdefs.ErrNotImplemented + return ErrNotImplemented } for _, i := range s.interceptors { i(ctx, project) @@ -287,7 +285,7 @@ func (s *ServiceProxy) Copy(ctx context.Context, project *types.Project, options //Pause implements Service interface func (s *ServiceProxy) Pause(ctx context.Context, project string, options PauseOptions) error { if s.PauseFn == nil { - return errdefs.ErrNotImplemented + return ErrNotImplemented } return s.PauseFn(ctx, project, options) } @@ -295,7 +293,7 @@ func (s *ServiceProxy) Pause(ctx context.Context, project string, options PauseO //UnPause implements Service interface func (s *ServiceProxy) UnPause(ctx context.Context, project string, options PauseOptions) error { if s.UnPauseFn == nil { - return errdefs.ErrNotImplemented + return ErrNotImplemented } return s.UnPauseFn(ctx, project, options) } @@ -303,7 +301,7 @@ func (s *ServiceProxy) UnPause(ctx context.Context, project string, options Paus //Top implements Service interface func (s *ServiceProxy) Top(ctx context.Context, project string, services []string) ([]ContainerProcSummary, error) { if s.TopFn == nil { - return nil, errdefs.ErrNotImplemented + return nil, ErrNotImplemented } return s.TopFn(ctx, project, services) } @@ -311,7 +309,7 @@ func (s *ServiceProxy) Top(ctx context.Context, project string, services []strin //Events implements Service interface func (s *ServiceProxy) Events(ctx context.Context, project string, options EventsOptions) error { if s.EventsFn == nil { - return errdefs.ErrNotImplemented + return ErrNotImplemented } return s.EventsFn(ctx, project, options) } @@ -319,7 +317,7 @@ func (s *ServiceProxy) Events(ctx context.Context, project string, options Event //Port implements Service interface func (s *ServiceProxy) Port(ctx context.Context, project string, service string, port int, options PortOptions) (string, int, error) { if s.PortFn == nil { - return "", 0, errdefs.ErrNotImplemented + return "", 0, ErrNotImplemented } return s.PortFn(ctx, project, service, port, options) } @@ -327,7 +325,7 @@ func (s *ServiceProxy) Port(ctx context.Context, project string, service string, //Images implements Service interface func (s *ServiceProxy) Images(ctx context.Context, project string, options ImagesOptions) ([]ImageSummary, error) { if s.ImagesFn == nil { - return nil, errdefs.ErrNotImplemented + return nil, ErrNotImplemented } return s.ImagesFn(ctx, project, options) } diff --git a/utils/logs.go b/utils/logs.go index 793ece9d0..be0526401 100644 --- a/utils/logs.go +++ b/utils/logs.go @@ -17,11 +17,11 @@ package utils import ( - "github.com/docker/compose-cli/api/compose" + "github.com/docker/compose-cli/pkg/api" ) // FilteredLogConsumer filters logs for given services -func FilteredLogConsumer(consumer compose.LogConsumer, services []string) compose.LogConsumer { +func FilteredLogConsumer(consumer api.LogConsumer, services []string) api.LogConsumer { if len(services) == 0 { return consumer } @@ -37,7 +37,7 @@ func FilteredLogConsumer(consumer compose.LogConsumer, services []string) compos type allowListLogConsumer struct { allowList map[string]bool - delegate compose.LogConsumer + delegate api.LogConsumer } func (a *allowListLogConsumer) Log(container, service, message string) {