2021-01-19 11:49:50 +01:00
|
|
|
// +build kube
|
|
|
|
|
|
|
|
/*
|
|
|
|
Copyright 2020 Docker Compose CLI authors
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package kube
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/compose-spec/compose-go/types"
|
2021-01-26 22:42:49 +01:00
|
|
|
|
2021-01-19 11:49:50 +01:00
|
|
|
"github.com/docker/compose-cli/api/compose"
|
|
|
|
"github.com/docker/compose-cli/api/errdefs"
|
|
|
|
"github.com/docker/compose-cli/kube/charts"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewComposeService create a kubernetes implementation of the compose.Service API
|
2021-01-28 14:14:13 +01:00
|
|
|
func NewComposeService(ctx context.Context) (compose.Service, error) {
|
2021-01-26 09:43:12 +01:00
|
|
|
chartsAPI, err := charts.NewSDK(ctx)
|
2021-01-19 11:49:50 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &composeService{
|
2021-01-26 09:43:12 +01:00
|
|
|
sdk: chartsAPI,
|
2021-01-19 11:49:50 +01:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type composeService struct {
|
2021-01-21 14:55:31 +01:00
|
|
|
sdk charts.SDK
|
2021-01-19 11:49:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Up executes the equivalent to a `compose up`
|
|
|
|
func (s *composeService) Up(ctx context.Context, project *types.Project, options compose.UpOptions) error {
|
|
|
|
return s.sdk.Install(project)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Down executes the equivalent to a `compose down`
|
|
|
|
func (s *composeService) Down(ctx context.Context, projectName string, options compose.DownOptions) error {
|
|
|
|
return s.sdk.Uninstall(projectName)
|
|
|
|
}
|
|
|
|
|
|
|
|
// List executes the equivalent to a `docker stack ls`
|
2021-01-26 09:43:12 +01:00
|
|
|
func (s *composeService) List(ctx context.Context) ([]compose.Stack, error) {
|
|
|
|
return s.sdk.List()
|
2021-01-19 11:49:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Build executes the equivalent to a `compose build`
|
|
|
|
func (s *composeService) Build(ctx context.Context, project *types.Project) error {
|
|
|
|
return errdefs.ErrNotImplemented
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push executes the equivalent ot a `compose push`
|
|
|
|
func (s *composeService) Push(ctx context.Context, project *types.Project) error {
|
|
|
|
return errdefs.ErrNotImplemented
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pull executes the equivalent of a `compose pull`
|
|
|
|
func (s *composeService) Pull(ctx context.Context, project *types.Project) error {
|
|
|
|
return errdefs.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
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start executes the equivalent to a `compose start`
|
|
|
|
func (s *composeService) Start(ctx context.Context, project *types.Project, consumer compose.LogConsumer) error {
|
|
|
|
return errdefs.ErrNotImplemented
|
|
|
|
}
|
|
|
|
|
2021-01-26 18:20:00 +01:00
|
|
|
// Stop executes the equivalent to a `compose stop`
|
2021-01-26 22:42:49 +01:00
|
|
|
func (s *composeService) Stop(ctx context.Context, project *types.Project) error {
|
2021-01-26 18:20:00 +01:00
|
|
|
return errdefs.ErrNotImplemented
|
|
|
|
}
|
|
|
|
|
2021-01-19 11:49:50 +01:00
|
|
|
// Logs executes the equivalent to a `compose logs`
|
|
|
|
func (s *composeService) Logs(ctx context.Context, projectName string, consumer compose.LogConsumer, options compose.LogOptions) error {
|
|
|
|
return errdefs.ErrNotImplemented
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ps executes the equivalent to a `compose ps`
|
2021-01-29 14:41:44 +01:00
|
|
|
func (s *composeService) Ps(ctx context.Context, projectName string, options compose.PsOptions) ([]compose.ContainerSummary, error) {
|
2021-01-19 11:49:50 +01:00
|
|
|
return nil, errdefs.ErrNotImplemented
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert translate compose model into backend's native format
|
|
|
|
func (s *composeService) Convert(ctx context.Context, project *types.Project, options compose.ConvertOptions) ([]byte, error) {
|
|
|
|
return nil, errdefs.ErrNotImplemented
|
|
|
|
}
|
|
|
|
|
|
|
|
// RunOneOffContainer creates a service oneoff container and starts its dependencies
|
|
|
|
func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.Project, opts compose.RunOptions) error {
|
|
|
|
return errdefs.ErrNotImplemented
|
|
|
|
}
|