2020-06-15 17:41:59 +02:00
|
|
|
// +build example
|
|
|
|
|
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-04-29 19:57:53 +02:00
|
|
|
package example
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-05-16 12:13:51 +02:00
|
|
|
"errors"
|
2020-05-01 15:28:44 +02:00
|
|
|
"fmt"
|
2020-08-17 17:48:52 +02:00
|
|
|
"io"
|
2020-04-29 19:57:53 +02:00
|
|
|
|
2020-08-20 16:42:37 +02:00
|
|
|
"github.com/compose-spec/compose-go/types"
|
2020-08-10 14:36:05 +02:00
|
|
|
|
2020-09-07 13:22:08 +02:00
|
|
|
"github.com/docker/compose-cli/api/compose"
|
|
|
|
"github.com/docker/compose-cli/api/containers"
|
|
|
|
"github.com/docker/compose-cli/api/secrets"
|
2020-09-07 14:39:19 +02:00
|
|
|
"github.com/docker/compose-cli/api/volumes"
|
2020-08-21 17:24:53 +02:00
|
|
|
"github.com/docker/compose-cli/backend"
|
|
|
|
"github.com/docker/compose-cli/context/cloud"
|
|
|
|
"github.com/docker/compose-cli/errdefs"
|
2020-04-29 19:57:53 +02:00
|
|
|
)
|
|
|
|
|
2020-05-05 17:14:26 +02:00
|
|
|
type apiService struct {
|
|
|
|
containerService
|
|
|
|
composeService
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *apiService) ContainerService() containers.Service {
|
|
|
|
return &a.containerService
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *apiService) ComposeService() compose.Service {
|
|
|
|
return &a.composeService
|
|
|
|
}
|
2020-04-29 19:57:53 +02:00
|
|
|
|
2020-08-18 09:13:58 +02:00
|
|
|
func (a *apiService) SecretsService() secrets.Service {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-07 14:39:19 +02:00
|
|
|
func (a *apiService) VolumeService() volumes.Service {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-28 17:37:59 +02:00
|
|
|
func init() {
|
|
|
|
backend.Register("example", "example", service, cloud.NotImplementedCloudService)
|
2020-05-12 13:37:28 +02:00
|
|
|
}
|
|
|
|
|
2020-05-28 17:37:59 +02:00
|
|
|
func service(ctx context.Context) (backend.Service, error) {
|
|
|
|
return &apiService{}, nil
|
2020-04-29 19:57:53 +02:00
|
|
|
}
|
|
|
|
|
2020-05-05 17:14:26 +02:00
|
|
|
type containerService struct{}
|
|
|
|
|
2020-06-12 10:53:06 +02:00
|
|
|
func (cs *containerService) Inspect(ctx context.Context, id string) (containers.Container, error) {
|
|
|
|
return containers.Container{
|
2020-08-04 10:22:07 +02:00
|
|
|
ID: "id",
|
|
|
|
Image: "nginx",
|
|
|
|
Platform: "Linux",
|
|
|
|
RestartPolicyCondition: "none",
|
2020-06-12 10:53:06 +02:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-05-18 14:16:32 +02:00
|
|
|
func (cs *containerService) List(ctx context.Context, all bool) ([]containers.Container, error) {
|
|
|
|
result := []containers.Container{
|
2020-04-29 19:57:53 +02:00
|
|
|
{
|
|
|
|
ID: "id",
|
|
|
|
Image: "nginx",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "1234",
|
|
|
|
Image: "alpine",
|
|
|
|
},
|
2020-05-18 14:16:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if all {
|
|
|
|
result = append(result, containers.Container{
|
|
|
|
ID: "stopped",
|
|
|
|
Image: "nginx",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
2020-04-29 19:57:53 +02:00
|
|
|
}
|
2020-05-01 15:28:44 +02:00
|
|
|
|
|
|
|
func (cs *containerService) Run(ctx context.Context, r containers.ContainerConfig) error {
|
|
|
|
fmt.Printf("Running container %q with name %q\n", r.Image, r.ID)
|
|
|
|
return nil
|
|
|
|
}
|
2020-05-03 13:35:25 +02:00
|
|
|
|
2020-08-12 10:35:15 +02:00
|
|
|
func (cs *containerService) Start(ctx context.Context, containerID string) error {
|
|
|
|
return errors.New("not implemented")
|
|
|
|
}
|
|
|
|
|
2020-05-18 12:02:04 +02:00
|
|
|
func (cs *containerService) Stop(ctx context.Context, containerName string, timeout *uint32) error {
|
2020-05-16 12:13:51 +02:00
|
|
|
return errors.New("not implemented")
|
|
|
|
}
|
|
|
|
|
2020-09-01 16:06:07 +02:00
|
|
|
func (cs *containerService) Kill(ctx context.Context, containerName string, signal string) error {
|
|
|
|
return errors.New("not implemented")
|
|
|
|
}
|
|
|
|
|
2020-07-08 14:31:27 +02:00
|
|
|
func (cs *containerService) Exec(ctx context.Context, name string, request containers.ExecRequest) error {
|
|
|
|
fmt.Printf("Executing command %q on container %q", request.Command, name)
|
2020-05-03 13:35:25 +02:00
|
|
|
return nil
|
|
|
|
}
|
2020-05-03 13:41:45 +02:00
|
|
|
|
2020-05-04 16:38:02 +02:00
|
|
|
func (cs *containerService) Logs(ctx context.Context, containerName string, request containers.LogsRequest) error {
|
|
|
|
fmt.Fprintf(request.Writer, "Following logs for container %q", containerName)
|
2020-05-03 13:41:45 +02:00
|
|
|
return nil
|
|
|
|
}
|
2020-05-05 17:14:26 +02:00
|
|
|
|
2020-08-11 15:46:29 +02:00
|
|
|
func (cs *containerService) Delete(ctx context.Context, id string, request containers.DeleteRequest) error {
|
|
|
|
fmt.Printf("Deleting container %q with force = %t\n", id, request.Force)
|
2020-05-10 22:37:28 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-05 17:14:26 +02:00
|
|
|
type composeService struct{}
|
|
|
|
|
2020-08-20 16:42:37 +02:00
|
|
|
func (cs *composeService) Up(ctx context.Context, project *types.Project) error {
|
|
|
|
fmt.Printf("Up command on project %q", project.Name)
|
2020-05-05 17:14:26 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-20 16:42:37 +02:00
|
|
|
func (cs *composeService) Down(ctx context.Context, project string) error {
|
|
|
|
fmt.Printf("Down command on project %q", project)
|
2020-05-05 17:14:26 +02:00
|
|
|
return nil
|
|
|
|
}
|
2020-08-07 10:16:12 +02:00
|
|
|
|
2020-08-20 16:42:37 +02:00
|
|
|
func (cs *composeService) Ps(ctx context.Context, project string) ([]compose.ServiceStatus, error) {
|
2020-08-05 16:32:51 +02:00
|
|
|
return nil, errdefs.ErrNotImplemented
|
|
|
|
}
|
2020-09-04 13:20:11 +02:00
|
|
|
func (cs *composeService) List(ctx context.Context, project string) ([]compose.Stack, error) {
|
|
|
|
return nil, errdefs.ErrNotImplemented
|
|
|
|
}
|
2020-08-20 16:42:37 +02:00
|
|
|
func (cs *composeService) Logs(ctx context.Context, project string, w io.Writer) error {
|
2020-08-05 16:32:51 +02:00
|
|
|
return errdefs.ErrNotImplemented
|
|
|
|
}
|
2020-08-18 08:58:37 +02:00
|
|
|
|
2020-08-20 16:42:37 +02:00
|
|
|
func (cs *composeService) Convert(ctx context.Context, project *types.Project) ([]byte, error) {
|
2020-08-18 08:58:37 +02:00
|
|
|
return nil, errdefs.ErrNotImplemented
|
|
|
|
}
|