Adding volume API & initial CLI command

Signed-off-by: Guillaume Tardif <guillaume.tardif@docker.com>
This commit is contained in:
Guillaume Tardif 2020-09-07 14:39:19 +02:00
parent 45179a5bff
commit 9ed06ece5b
11 changed files with 191 additions and 1 deletions

View File

@ -35,6 +35,7 @@ import (
"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/volumes"
"github.com/docker/compose-cli/api/secrets"
"github.com/docker/compose-cli/backend"
apicontext "github.com/docker/compose-cli/context"
@ -115,6 +116,7 @@ func getAciAPIService(aciCtx store.AciContext) *aciAPIService {
type aciAPIService struct {
*aciContainerService
*aciComposeService
*aciVolumeService
}
func (a *aciAPIService) ContainerService() containers.Service {
@ -129,6 +131,10 @@ func (a *aciAPIService) SecretsService() secrets.Service {
return nil
}
func (a *aciAPIService) VolumeService() volumes.Service {
return a.aciVolumeService
}
type aciContainerService struct {
ctx store.AciContext
}
@ -496,6 +502,18 @@ func (cs *aciComposeService) Convert(ctx context.Context, project *types.Project
return nil, errdefs.ErrNotImplemented
}
type aciVolumeService struct {
ctx store.AciContext
}
func (cs *aciVolumeService) List(ctx context.Context) ([]volumes.Volume, error) {
return nil, nil
}
func (cs *aciVolumeService) Create(ctx context.Context, options interface{}) (volumes.Volume, error) {
return volumes.Volume{}, nil
}
type aciCloudService struct {
loginService login.AzureLoginServiceAPI
}

View File

@ -18,6 +18,7 @@ package client
import (
"context"
"github.com/docker/compose-cli/api/volumes"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/containers"
@ -86,3 +87,11 @@ func (c *Client) SecretsService() secrets.Service {
return &secretsService{}
}
// VolumeService returns the backend service for the current context
func (c *Client) VolumeService() volumes.Service {
if vs := c.bs.VolumeService(); vs != nil {
return vs
}
return &volumeService{}
}

36
api/client/volume.go Normal file
View File

@ -0,0 +1,36 @@
/*
Copyright 2020 Docker, Inc.
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 client
import (
"context"
"github.com/docker/compose-cli/api/volumes"
"github.com/docker/compose-cli/errdefs"
)
type volumeService struct {
}
// List list volumes
func (c *volumeService) List(ctx context.Context) ([]volumes.Volume, error) {
return nil, errdefs.ErrNotImplemented
}
// Create creates a volume
func (c *volumeService) Create(ctx context.Context, options interface {}) (volumes.Volume, error) {
return volumes.Volume{}, errdefs.ErrNotImplemented
}

37
api/volumes/api.go Normal file
View File

@ -0,0 +1,37 @@
/*
Copyright 2020 Docker, Inc.
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 volumes
import (
"context"
)
type Volume struct {
Name string
}
type VolumeCreateOptions struct {
account string
fileshare string
}
// Service interacts with the underlying container backend
type Service interface {
// List returns all available volumes
List(ctx context.Context) ([]Volume, error)
Create(ctx context.Context, options interface{}) (Volume, error)
}

View File

@ -26,6 +26,7 @@ import (
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/containers"
"github.com/docker/compose-cli/api/secrets"
"github.com/docker/compose-cli/api/volumes"
"github.com/docker/compose-cli/context/cloud"
"github.com/docker/compose-cli/errdefs"
)
@ -53,8 +54,9 @@ var backends = struct {
// Service aggregates the service interfaces
type Service interface {
ContainerService() containers.Service
SecretsService() secrets.Service
ComposeService() compose.Service
SecretsService() secrets.Service
VolumeService() volumes.Service
}
// Register adds a typed backend to the registry

66
cli/cmd/volume/create.go Normal file
View File

@ -0,0 +1,66 @@
package volume
/*
Copyright 2020 Docker, Inc.
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.
*/
import (
"fmt"
"github.com/docker/compose-cli/api/client"
"github.com/spf13/cobra"
)
type createVolumeOptions struct {
Account string
Fileshare string
}
// SecretCommand manage secrets
func VolumeCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "volume",
Short: "Manages volumes",
}
cmd.AddCommand(
createVolume(),
)
return cmd
}
func createVolume() *cobra.Command {
opts := createVolumeOptions{}
cmd := &cobra.Command{
Use: "create",
Short: "Creates an Azure file share to use as ACI volume.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
c, err := client.New(cmd.Context())
if err != nil {
return err
}
id, err := c.VolumeService().Create(cmd.Context(), opts)
if err != nil {
return err
}
fmt.Println(id)
return nil
},
}
cmd.Flags().StringVar(&opts.Account, "storage-account", "", "Storage account name")
cmd.Flags().StringVar(&opts.Fileshare, "fileshare", "", "Fileshare name")
return cmd
}

View File

@ -19,6 +19,7 @@ package main
import (
"context"
"fmt"
volume "github.com/docker/compose-cli/cli/cmd/volume"
"math/rand"
"os"
"os/signal"
@ -133,6 +134,7 @@ func main() {
// Place holders
cmd.EcsCommand(),
volume.VolumeCommand(),
)
helpFunc := root.HelpFunc()

View File

@ -18,6 +18,7 @@ package ecs
import (
"context"
"github.com/docker/compose-cli/api/volumes"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
@ -97,6 +98,10 @@ func (a *ecsAPIService) SecretsService() secrets.Service {
return a
}
func (a *ecsAPIService) VolumeService() volumes.Service {
return nil
}
func getCloudService() (cloud.Service, error) {
return ecsCloudService{}, nil
}

View File

@ -18,6 +18,7 @@ package local
import (
"context"
"github.com/docker/compose-cli/api/volumes"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/containers"
@ -58,6 +59,10 @@ func (e ecsLocalSimulation) ContainerService() containers.Service {
return nil
}
func (e ecsLocalSimulation) VolumeService() volumes.Service {
return nil
}
func (e ecsLocalSimulation) SecretsService() secrets.Service {
return nil
}

View File

@ -29,6 +29,7 @@ import (
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/containers"
"github.com/docker/compose-cli/api/secrets"
"github.com/docker/compose-cli/api/volumes"
"github.com/docker/compose-cli/backend"
"github.com/docker/compose-cli/context/cloud"
"github.com/docker/compose-cli/errdefs"
@ -51,6 +52,10 @@ func (a *apiService) SecretsService() secrets.Service {
return nil
}
func (a *apiService) VolumeService() volumes.Service {
return nil
}
func init() {
backend.Register("example", "example", service, cloud.NotImplementedCloudService)
}

View File

@ -38,6 +38,7 @@ import (
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/containers"
"github.com/docker/compose-cli/api/volumes"
"github.com/docker/compose-cli/api/secrets"
"github.com/docker/compose-cli/backend"
"github.com/docker/compose-cli/context/cloud"
@ -75,6 +76,10 @@ func (ms *local) SecretsService() secrets.Service {
return nil
}
func (ms *local) VolumeService() volumes.Service {
return nil
}
func (ms *local) Inspect(ctx context.Context, id string) (containers.Container, error) {
c, err := ms.apiClient.ContainerInspect(ctx, id)
if err != nil {