mirror of
https://github.com/docker/compose.git
synced 2025-07-10 07:14:27 +02:00
use interceptor to implement ACI-specific flags
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
62af4e0cc7
commit
21e2f5c062
@ -45,8 +45,6 @@ type composeOptions struct {
|
|||||||
*projectOptions
|
*projectOptions
|
||||||
Build bool
|
Build bool
|
||||||
noBuild bool
|
noBuild bool
|
||||||
// ACI only
|
|
||||||
DomainName string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type upOptions struct {
|
type upOptions struct {
|
||||||
@ -186,8 +184,6 @@ func upCommand(p *projectOptions, contextType string, backend compose.Service) *
|
|||||||
flags.BoolVar(&opts.noPrefix, "no-log-prefix", false, "Don't print prefix in logs.")
|
flags.BoolVar(&opts.noPrefix, "no-log-prefix", false, "Don't print prefix in logs.")
|
||||||
|
|
||||||
switch contextType {
|
switch contextType {
|
||||||
case store.AciContextType:
|
|
||||||
flags.StringVar(&opts.DomainName, "domainname", "", "Container NIS domain name")
|
|
||||||
case store.LocalContextType, store.DefaultContextType, store.EcsLocalSimulationContextType:
|
case store.LocalContextType, store.DefaultContextType, store.EcsLocalSimulationContextType:
|
||||||
flags.BoolVar(&opts.forceRecreate, "force-recreate", false, "Recreate containers even if their configuration and image haven't changed.")
|
flags.BoolVar(&opts.forceRecreate, "force-recreate", false, "Recreate containers even if their configuration and image haven't changed.")
|
||||||
flags.BoolVar(&opts.noRecreate, "no-recreate", false, "If containers already exist, don't recreate them. Incompatible with --force-recreate.")
|
flags.BoolVar(&opts.noRecreate, "no-recreate", false, "If containers already exist, don't recreate them. Incompatible with --force-recreate.")
|
||||||
@ -360,10 +356,6 @@ func setup(opts composeOptions, services []string) (*types.Project, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.DomainName != "" {
|
|
||||||
// arbitrarily set the domain name on the first service ; ACI backend will expose the entire project
|
|
||||||
project.Services[0].DomainName = opts.DomainName
|
|
||||||
}
|
|
||||||
if opts.Build {
|
if opts.Build {
|
||||||
for i, service := range project.Services {
|
for i, service := range project.Services {
|
||||||
service.PullPolicy = types.PullPolicyBuild
|
service.PullPolicy = types.PullPolicyBuild
|
||||||
|
27
cli/main.go
27
cli/main.go
@ -28,12 +28,14 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/compose-spec/compose-go/types"
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/docker/compose-cli/api/backend"
|
"github.com/docker/compose-cli/api/backend"
|
||||||
|
api "github.com/docker/compose-cli/api/compose"
|
||||||
"github.com/docker/compose-cli/api/config"
|
"github.com/docker/compose-cli/api/config"
|
||||||
apicontext "github.com/docker/compose-cli/api/context"
|
apicontext "github.com/docker/compose-cli/api/context"
|
||||||
"github.com/docker/compose-cli/api/context/store"
|
"github.com/docker/compose-cli/api/context/store"
|
||||||
@ -223,7 +225,14 @@ func main() {
|
|||||||
|
|
||||||
if ctype != store.DefaultContextType {
|
if ctype != store.DefaultContextType {
|
||||||
// On default context, "compose" is implemented by CLI Plugin
|
// On default context, "compose" is implemented by CLI Plugin
|
||||||
root.AddCommand(compose.RootCommand(ctype, service.ComposeService()))
|
proxy := api.NewServiceProxy().WithService(service.ComposeService())
|
||||||
|
command := compose.RootCommand(ctype, proxy)
|
||||||
|
|
||||||
|
if ctype == store.AciContextType {
|
||||||
|
customizeCliForACI(command, proxy)
|
||||||
|
}
|
||||||
|
|
||||||
|
root.AddCommand(command)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = root.ExecuteContext(ctx); err != nil {
|
if err = root.ExecuteContext(ctx); err != nil {
|
||||||
@ -232,6 +241,22 @@ func main() {
|
|||||||
metrics.Track(ctype, os.Args[1:], metrics.SuccessStatus)
|
metrics.Track(ctype, os.Args[1:], metrics.SuccessStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func customizeCliForACI(command *cobra.Command, proxy *api.ServiceProxy) {
|
||||||
|
var domainName string
|
||||||
|
for _, c := range command.Commands() {
|
||||||
|
if c.Name() == "up" {
|
||||||
|
c.Flags().StringVar(&domainName, "domainname", "", "Container NIS domain name")
|
||||||
|
proxy.WithInterceptor(func(ctx context.Context, project *types.Project) {
|
||||||
|
if domainName != "" {
|
||||||
|
// arbitrarily set the domain name on the first service ; ACI backend will expose the entire project
|
||||||
|
project.Services[0].DomainName = domainName
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getBackend(ctype string, configDir string, opts cliopts.GlobalOpts) (backend.Service, error) {
|
func getBackend(ctype string, configDir string, opts cliopts.GlobalOpts) (backend.Service, error) {
|
||||||
switch ctype {
|
switch ctype {
|
||||||
case store.DefaultContextType, store.LocalContextType:
|
case store.DefaultContextType, store.LocalContextType:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user