diff --git a/aci/backend.go b/aci/backend.go index ceabd7cf2..5e374d492 100644 --- a/aci/backend.go +++ b/aci/backend.go @@ -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 } diff --git a/api/client/client.go b/api/client/client.go index a6e19bf22..937aad141 100644 --- a/api/client/client.go +++ b/api/client/client.go @@ -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{} +} diff --git a/api/client/volume.go b/api/client/volume.go new file mode 100644 index 000000000..37ebfac38 --- /dev/null +++ b/api/client/volume.go @@ -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 +} diff --git a/api/volumes/api.go b/api/volumes/api.go new file mode 100644 index 000000000..ce6efe04a --- /dev/null +++ b/api/volumes/api.go @@ -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) +} diff --git a/backend/backend.go b/backend/backend.go index 8185f873c..dc7562617 100644 --- a/backend/backend.go +++ b/backend/backend.go @@ -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 diff --git a/cli/cmd/volume/create.go b/cli/cmd/volume/create.go new file mode 100644 index 000000000..3a3a0af30 --- /dev/null +++ b/cli/cmd/volume/create.go @@ -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 +} diff --git a/cli/main.go b/cli/main.go index 69f9b0ba6..79167ac4b 100644 --- a/cli/main.go +++ b/cli/main.go @@ -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() diff --git a/ecs/backend.go b/ecs/backend.go index ec18fe026..8252ad28d 100644 --- a/ecs/backend.go +++ b/ecs/backend.go @@ -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 } diff --git a/ecs/local/backend.go b/ecs/local/backend.go index 1310cfec8..f0c68ab89 100644 --- a/ecs/local/backend.go +++ b/ecs/local/backend.go @@ -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 } diff --git a/example/backend.go b/example/backend.go index 2f9b420cf..23775841c 100644 --- a/example/backend.go +++ b/example/backend.go @@ -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) } diff --git a/local/backend.go b/local/backend.go index 63acaae60..99e2afc50 100644 --- a/local/backend.go +++ b/local/backend.go @@ -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 {