|
@@ -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
|
|
|
}
|