mirror of
https://github.com/docker/compose.git
synced 2025-07-20 20:24:30 +02:00
commit
53bc852e3e
1
Makefile
1
Makefile
@ -32,6 +32,7 @@ all: cli
|
|||||||
|
|
||||||
protos: ## Generate go code from .proto files
|
protos: ## Generate go code from .proto files
|
||||||
@docker build . \
|
@docker build . \
|
||||||
|
--output type=local,dest=. \
|
||||||
--target protos
|
--target protos
|
||||||
|
|
||||||
cli: ## Compile the cli
|
cli: ## Compile the cli
|
||||||
|
@ -98,11 +98,12 @@ func createACIContainers(ctx context.Context, aciContext store.AciContext, group
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteACIContainerGroup(ctx context.Context, aciContext store.AciContext, containerGroupName string) (c containerinstance.ContainerGroup, err error) {
|
func deleteACIContainerGroup(ctx context.Context, aciContext store.AciContext, containerGroupName string) (containerinstance.ContainerGroup, error) {
|
||||||
containerGroupsClient, err := getContainerGroupsClient(aciContext.SubscriptionID)
|
containerGroupsClient, err := getContainerGroupsClient(aciContext.SubscriptionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c, fmt.Errorf("cannot get container group client: %v", err)
|
return containerinstance.ContainerGroup{}, fmt.Errorf("cannot get container group client: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return containerGroupsClient.Delete(ctx, aciContext.ResourceGroup, containerGroupName)
|
return containerGroupsClient.Delete(ctx, aciContext.ResourceGroup, containerGroupName)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,7 +272,7 @@ func getSubscriptionsClient() subscription.SubscriptionsClient {
|
|||||||
return subc
|
return subc
|
||||||
}
|
}
|
||||||
|
|
||||||
//GetGroupsClient ...
|
// GetGroupsClient ...
|
||||||
func GetGroupsClient(subscriptionID string) resources.GroupsClient {
|
func GetGroupsClient(subscriptionID string) resources.GroupsClient {
|
||||||
groupsClient := resources.NewGroupsClient(subscriptionID)
|
groupsClient := resources.NewGroupsClient(subscriptionID)
|
||||||
authorizer, _ := auth.NewAuthorizerFromCLI()
|
authorizer, _ := auth.NewAuthorizerFromCLI()
|
||||||
@ -279,7 +280,7 @@ func GetGroupsClient(subscriptionID string) resources.GroupsClient {
|
|||||||
return groupsClient
|
return groupsClient
|
||||||
}
|
}
|
||||||
|
|
||||||
//GetSubscriptionID ...
|
// GetSubscriptionID ...
|
||||||
func GetSubscriptionID(ctx context.Context) (string, error) {
|
func GetSubscriptionID(ctx context.Context) (string, error) {
|
||||||
c := getSubscriptionsClient()
|
c := getSubscriptionsClient()
|
||||||
res, err := c.List(ctx)
|
res, err := c.List(ctx)
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -23,6 +24,9 @@ import (
|
|||||||
|
|
||||||
const singleContainerName = "single--container--aci"
|
const singleContainerName = "single--container--aci"
|
||||||
|
|
||||||
|
// ErrNoSuchContainer is returned when the mentioned container does not exist
|
||||||
|
var ErrNoSuchContainer = errors.New("no such container")
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
backend.Register("aci", "aci", func(ctx context.Context) (backend.Service, error) {
|
backend.Register("aci", "aci", func(ctx context.Context) (backend.Service, error) {
|
||||||
return New(ctx)
|
return New(ctx)
|
||||||
@ -214,6 +218,18 @@ func (cs *aciContainerService) Logs(ctx context.Context, containerName string, r
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cs *aciContainerService) Delete(ctx context.Context, containerID string, _ bool) error {
|
||||||
|
cg, err := deleteACIContainerGroup(ctx, cs.ctx, containerID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if cg.StatusCode == http.StatusNoContent {
|
||||||
|
return ErrNoSuchContainer
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
type aciComposeService struct {
|
type aciComposeService struct {
|
||||||
containerGroupsClient containerinstance.ContainerGroupsClient
|
containerGroupsClient containerinstance.ContainerGroupsClient
|
||||||
ctx store.AciContext
|
ctx store.AciContext
|
||||||
@ -239,6 +255,14 @@ func (cs *aciComposeService) Down(ctx context.Context, opts compose.ProjectOptio
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logrus.Debugf("Down on project with name %q\n", project.Name)
|
logrus.Debugf("Down on project with name %q\n", project.Name)
|
||||||
_, err = deleteACIContainerGroup(ctx, cs.ctx, project.Name)
|
|
||||||
|
cg, err := deleteACIContainerGroup(ctx, cs.ctx, project.Name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if cg.StatusCode == http.StatusNoContent {
|
||||||
|
return ErrNoSuchContainer
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/Azure/azure-sdk-for-go/profiles/latest/containerinstance/mgmt/containerinstance"
|
"github.com/Azure/azure-sdk-for-go/profiles/latest/containerinstance/mgmt/containerinstance"
|
||||||
"github.com/Azure/go-autorest/autorest/to"
|
"github.com/Azure/go-autorest/autorest/to"
|
||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
|
|
||||||
"github.com/docker/api/compose"
|
"github.com/docker/api/compose"
|
||||||
"github.com/docker/api/context/store"
|
"github.com/docker/api/context/store"
|
||||||
)
|
)
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.21.0-devel
|
// protoc-gen-go v1.22.0
|
||||||
// protoc v3.6.1
|
// protoc v3.6.1
|
||||||
// source: backend/v1/backend.proto
|
// source: backend/v1/backend.proto
|
||||||
|
|
||||||
|
52
cli/cmd/rm.go
Normal file
52
cli/cmd/rm.go
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/docker/api/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
type rmOpts struct {
|
||||||
|
force bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// RmCommand deletes containers
|
||||||
|
func RmCommand() *cobra.Command {
|
||||||
|
var opts rmOpts
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "rm",
|
||||||
|
Aliases: []string{"delete"},
|
||||||
|
Short: "Remove containers",
|
||||||
|
Args: cobra.MinimumNArgs(1),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
var errs []string
|
||||||
|
c, err := client.New(cmd.Context())
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "cannot connect to backend")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, id := range args {
|
||||||
|
err := c.ContainerService().Delete(cmd.Context(), id, opts.force)
|
||||||
|
if err != nil {
|
||||||
|
errs = append(errs, err.Error()+" "+id)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fmt.Println(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(errs) > 0 {
|
||||||
|
return errors.New(strings.Join(errs, "\n"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Flags().BoolVarP(&opts.force, "force", "f", false, "Force removal")
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
@ -108,6 +108,7 @@ func main() {
|
|||||||
run.Command(),
|
run.Command(),
|
||||||
cmd.ExecCommand(),
|
cmd.ExecCommand(),
|
||||||
cmd.LogsCommand(),
|
cmd.LogsCommand(),
|
||||||
|
cmd.RmCommand(),
|
||||||
compose.Command(),
|
compose.Command(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.21.0-devel
|
// protoc-gen-go v1.22.0
|
||||||
// protoc v3.6.1
|
// protoc v3.6.1
|
||||||
// source: cli/v1/cli.proto
|
// source: cli/v1/cli.proto
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.21.0-devel
|
// protoc-gen-go v1.22.0
|
||||||
// protoc v3.6.1
|
// protoc v3.6.1
|
||||||
// source: compose/v1/compose.proto
|
// source: compose/v1/compose.proto
|
||||||
|
|
||||||
|
@ -54,4 +54,6 @@ type Service interface {
|
|||||||
Exec(ctx context.Context, containerName string, command string, reader io.Reader, writer io.Writer) error
|
Exec(ctx context.Context, containerName string, command string, reader io.Reader, writer io.Writer) error
|
||||||
// Logs returns all the logs of a container
|
// Logs returns all the logs of a container
|
||||||
Logs(ctx context.Context, containerName string, request LogsRequest) error
|
Logs(ctx context.Context, containerName string, request LogsRequest) error
|
||||||
|
// Delete removes containers
|
||||||
|
Delete(ctx context.Context, id string, force bool) error
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.21.0-devel
|
// protoc-gen-go v1.22.0
|
||||||
// protoc v3.6.1
|
// protoc v3.6.1
|
||||||
// source: containers/v1/containers.proto
|
// source: containers/v1/containers.proto
|
||||||
|
|
||||||
|
@ -59,6 +59,11 @@ func (cs *containerService) Logs(ctx context.Context, containerName string, requ
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cs *containerService) Delete(ctx context.Context, id string, force bool) error {
|
||||||
|
fmt.Printf("Deleting container %q with force = %t\n", id, force)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type composeService struct{}
|
type composeService struct{}
|
||||||
|
|
||||||
func (cs *composeService) Up(ctx context.Context, opts compose.ProjectOptions) error {
|
func (cs *composeService) Up(ctx context.Context, opts compose.ProjectOptions) error {
|
||||||
|
@ -125,3 +125,9 @@ func (ms *mobyService) Logs(ctx context.Context, containerName string, request c
|
|||||||
_, err = io.Copy(request.Writer, r)
|
_, err = io.Copy(request.Writer, r)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ms *mobyService) Delete(ctx context.Context, containerID string, force bool) error {
|
||||||
|
return ms.apiClient.ContainerRemove(ctx, containerID, types.ContainerRemoveOptions{
|
||||||
|
Force: force,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -72,8 +72,13 @@ func (p *proxyContainerAPI) Kill(_ context.Context, _ *v1.KillRequest) (*v1.Kill
|
|||||||
panic("not implemented") // TODO: Implement
|
panic("not implemented") // TODO: Implement
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *proxyContainerAPI) Delete(_ context.Context, _ *v1.DeleteRequest) (*v1.DeleteResponse, error) {
|
func (p *proxyContainerAPI) Delete(ctx context.Context, request *v1.DeleteRequest) (*v1.DeleteResponse, error) {
|
||||||
panic("not implemented") // TODO: Implement
|
err := Client(ctx).ContainerService().Delete(ctx, request.Id, request.Force)
|
||||||
|
if err != nil {
|
||||||
|
return &v1.DeleteResponse{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &v1.DeleteResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *proxyContainerAPI) Update(_ context.Context, _ *v1.UpdateRequest) (*v1.UpdateResponse, error) {
|
func (p *proxyContainerAPI) Update(_ context.Context, _ *v1.UpdateRequest) (*v1.UpdateResponse, error) {
|
||||||
|
@ -5,16 +5,18 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/profiles/2019-03-01/resources/mgmt/resources"
|
"github.com/Azure/azure-sdk-for-go/profiles/2019-03-01/resources/mgmt/resources"
|
||||||
|
"github.com/Azure/go-autorest/autorest/to"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"github.com/docker/api/azure"
|
"github.com/docker/api/azure"
|
||||||
. "github.com/docker/api/tests/framework"
|
. "github.com/docker/api/tests/framework"
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const resourceGroupName = "resourceGroupTest"
|
const (
|
||||||
|
resourceGroupName = "resourceGroupTest"
|
||||||
var location = "westeurope"
|
location = "westeurope"
|
||||||
|
contextName = "acitest"
|
||||||
const contextName = "acitest"
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
SetupTest()
|
SetupTest()
|
||||||
@ -45,7 +47,7 @@ func main() {
|
|||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
NewDockerCommand("context", "create", contextName, "aci", "--aci-subscription-id", subscriptionID, "--aci-resource-group", resourceGroupName, "--aci-location", location).ExecOrDie()
|
NewDockerCommand("context", "create", contextName, "aci", "--aci-subscription-id", subscriptionID, "--aci-resource-group", resourceGroupName, "--aci-location", location).ExecOrDie()
|
||||||
//Expect(output).To(ContainSubstring("ACI context acitest created"))
|
// Expect(output).To(ContainSubstring("ACI context acitest created"))
|
||||||
})
|
})
|
||||||
|
|
||||||
defer deleteResourceGroup(resourceGroupName)
|
defer deleteResourceGroup(resourceGroupName)
|
||||||
@ -62,35 +64,33 @@ func main() {
|
|||||||
Expect(len(Lines(output))).To(Equal(1))
|
Expect(len(Lines(output))).To(Equal(1))
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
var nginxID string
|
||||||
var nginxID string
|
It("runs nginx on port 80 (PORT NOT CHECKED YET!!! REMOVE THAT WHEN IMPLEMENTED)", func() {
|
||||||
It("runs nginx on port 80", func() {
|
NewDockerCommand("run", "nginx", "-p", "80:80").ExecOrDie()
|
||||||
NewDockerCommand("run", "nginx", "-p", "80:80").ExecOrDie()
|
output := NewDockerCommand("ps").ExecOrDie()
|
||||||
output := NewDockerCommand("ps").ExecOrDie()
|
lines := Lines(output)
|
||||||
Lines := Lines(output)
|
Expect(len(lines)).To(Equal(2))
|
||||||
Expect(len(Lines)).To(Equal(2))
|
|
||||||
|
|
||||||
containerFields := Columns(Lines[1])
|
containerFields := Columns(lines[1])
|
||||||
nginxID = containerFields[0]
|
nginxID = containerFields[0]
|
||||||
Expect(containerFields[1]).To(Equal("nginx"))
|
Expect(containerFields[1]).To(Equal("nginx"))
|
||||||
Expect(containerFields[2]).To(Equal("Running"))
|
Expect(containerFields[2]).To(Equal("Running"))
|
||||||
exposedIP := containerFields[3]
|
// exposedIP := containerFields[3]
|
||||||
Expect(exposedIP).To(ContainSubstring(":80->80/TCP"))
|
// Expect(exposedIP).To(ContainSubstring(":80->80/TCP"))
|
||||||
|
|
||||||
url := strings.ReplaceAll(exposedIP, "->80/TCP", "")
|
// url := strings.ReplaceAll(exposedIP, "->80/TCP", "")
|
||||||
output = NewCommand("curl", url).ExecOrDie()
|
// output = NewCommand("curl", url).ExecOrDie()
|
||||||
Expect(output).To(ContainSubstring("Welcome to nginx!"))
|
// Expect(output).To(ContainSubstring("Welcome to nginx!"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("removes container nginx", func() {
|
It("removes container nginx", func() {
|
||||||
output := NewDockerCommand("rm", nginxID).ExecOrDie()
|
output := NewDockerCommand("rm", nginxID).ExecOrDie()
|
||||||
Expect(Lines(output)[0]).To(Equal(nginxID))
|
Expect(Lines(output)[0]).To(Equal(nginxID))
|
||||||
})
|
})
|
||||||
*/
|
|
||||||
|
|
||||||
It("deploys a compose app", func() {
|
It("deploys a compose app", func() {
|
||||||
NewDockerCommand("compose", "up", "-f", "./tests/composefiles/aci-demo/aci_demo_port.yaml", "--name", "acidemo").ExecOrDie()
|
NewDockerCommand("compose", "up", "-f", "./tests/composefiles/aci-demo/aci_demo_port.yaml", "--name", "acidemo").ExecOrDie()
|
||||||
//Expect(output).To(ContainSubstring("Successfully deployed"))
|
// Expect(output).To(ContainSubstring("Successfully deployed"))
|
||||||
output := NewDockerCommand("ps").ExecOrDie()
|
output := NewDockerCommand("ps").ExecOrDie()
|
||||||
Lines := Lines(output)
|
Lines := Lines(output)
|
||||||
Expect(len(Lines)).To(Equal(4))
|
Expect(len(Lines)).To(Equal(4))
|
||||||
@ -141,7 +141,7 @@ func setupTestResourecGroup(groupName string) {
|
|||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
gc := azure.GetGroupsClient(subscriptionID)
|
gc := azure.GetGroupsClient(subscriptionID)
|
||||||
_, err = gc.CreateOrUpdate(ctx, groupName, resources.Group{
|
_, err = gc.CreateOrUpdate(ctx, groupName, resources.Group{
|
||||||
Location: &location,
|
Location: to.StringPtr(location),
|
||||||
})
|
})
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,9 @@ package main
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/docker/api/tests/framework"
|
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
|
. "github.com/docker/api/tests/framework"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user