2020-06-18 16:13:24 +02:00
|
|
|
/*
|
2020-09-22 12:13:00 +02:00
|
|
|
Copyright 2020 Docker Compose CLI authors
|
2020-06-18 16:13:24 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2020-06-12 15:00:30 +02:00
|
|
|
package local
|
2020-05-04 19:50:01 +02:00
|
|
|
|
|
|
|
import (
|
2021-04-15 09:09:35 +02:00
|
|
|
"os"
|
|
|
|
|
2021-03-04 19:21:42 +01:00
|
|
|
"github.com/docker/cli/cli/command"
|
2021-04-15 09:09:35 +02:00
|
|
|
cliconfig "github.com/docker/cli/cli/config"
|
2021-03-04 19:21:42 +01:00
|
|
|
cliflags "github.com/docker/cli/cli/flags"
|
2021-03-11 11:43:40 +01:00
|
|
|
"github.com/docker/docker/client"
|
2020-11-18 17:18:41 +01:00
|
|
|
|
2021-01-15 15:44:42 +01:00
|
|
|
"github.com/docker/compose-cli/api/backend"
|
2020-09-07 13:22:08 +02:00
|
|
|
"github.com/docker/compose-cli/api/containers"
|
2020-10-12 10:18:45 +02:00
|
|
|
"github.com/docker/compose-cli/api/resources"
|
2020-09-07 13:22:08 +02:00
|
|
|
"github.com/docker/compose-cli/api/secrets"
|
2020-09-07 18:23:28 +02:00
|
|
|
"github.com/docker/compose-cli/api/volumes"
|
2021-03-04 19:21:42 +01:00
|
|
|
cliopts "github.com/docker/compose-cli/cli/options"
|
2021-06-14 16:26:14 +02:00
|
|
|
"github.com/docker/compose-cli/pkg/api"
|
2021-06-15 09:57:38 +02:00
|
|
|
"github.com/docker/compose-cli/pkg/compose"
|
2020-05-04 19:50:01 +02:00
|
|
|
)
|
|
|
|
|
2020-06-12 15:00:30 +02:00
|
|
|
type local struct {
|
2020-12-08 11:53:36 +01:00
|
|
|
containerService *containerService
|
|
|
|
volumeService *volumeService
|
2021-06-14 16:26:14 +02:00
|
|
|
composeService api.Service
|
2020-05-04 19:50:01 +02:00
|
|
|
}
|
|
|
|
|
2021-03-11 11:43:40 +01:00
|
|
|
// NewService build a backend for "local" context, using Docker API client
|
|
|
|
func NewService(apiClient client.APIClient) backend.Service {
|
2021-04-15 09:09:35 +02:00
|
|
|
file := cliconfig.LoadDefaultConfigFile(os.Stderr)
|
2020-06-12 15:00:30 +02:00
|
|
|
return &local{
|
2020-11-03 21:01:56 +01:00
|
|
|
containerService: &containerService{apiClient},
|
2020-11-03 21:15:14 +01:00
|
|
|
volumeService: &volumeService{apiClient},
|
2021-06-15 09:57:38 +02:00
|
|
|
composeService: compose.NewComposeService(apiClient, file),
|
2021-03-11 11:43:40 +01:00
|
|
|
}
|
2020-05-04 19:50:01 +02:00
|
|
|
}
|
|
|
|
|
2021-03-04 19:21:42 +01:00
|
|
|
// GetLocalBackend initialize local backend
|
|
|
|
func GetLocalBackend(configDir string, opts cliopts.GlobalOpts) (backend.Service, error) {
|
|
|
|
configFile, err := cliconfig.Load(configDir)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
options := cliflags.CommonOptions{
|
|
|
|
Context: opts.Context,
|
|
|
|
Debug: opts.Debug,
|
|
|
|
Hosts: opts.Hosts,
|
|
|
|
LogLevel: opts.LogLevel,
|
|
|
|
}
|
|
|
|
|
|
|
|
if opts.TLSVerify {
|
|
|
|
options.TLS = opts.TLS
|
|
|
|
options.TLSVerify = opts.TLSVerify
|
|
|
|
options.TLSOptions = opts.TLSOptions
|
|
|
|
}
|
|
|
|
apiClient, err := command.NewAPIClientFromFlags(&options, configFile)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return NewService(apiClient), nil
|
|
|
|
}
|
|
|
|
|
2020-11-13 09:38:21 +01:00
|
|
|
func (s *local) ContainerService() containers.Service {
|
|
|
|
return s.containerService
|
2020-05-04 19:50:01 +02:00
|
|
|
}
|
|
|
|
|
2021-06-14 16:26:14 +02:00
|
|
|
func (s *local) ComposeService() api.Service {
|
2020-11-26 14:44:55 +01:00
|
|
|
return s.composeService
|
2020-05-04 19:50:01 +02:00
|
|
|
}
|
|
|
|
|
2020-11-13 09:38:21 +01:00
|
|
|
func (s *local) SecretsService() secrets.Service {
|
2020-08-18 09:13:58 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-13 09:38:21 +01:00
|
|
|
func (s *local) VolumeService() volumes.Service {
|
|
|
|
return s.volumeService
|
2020-09-07 14:39:19 +02:00
|
|
|
}
|
|
|
|
|
2020-11-13 09:38:21 +01:00
|
|
|
func (s *local) ResourceService() resources.Service {
|
2020-10-12 10:18:45 +02:00
|
|
|
return nil
|
|
|
|
}
|