mirror of
https://github.com/docker/compose.git
synced 2025-07-23 13:45:00 +02:00
Only add --domainname
flag to docker run
in ACI context
Signed-off-by: Guillaume Tardif <guillaume.tardif@docker.com>
This commit is contained in:
parent
701d1b834e
commit
268c02523a
@ -25,15 +25,15 @@ import (
|
|||||||
"github.com/containerd/console"
|
"github.com/containerd/console"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/docker/compose-cli/api/containers"
|
|
||||||
|
|
||||||
"github.com/docker/compose-cli/api/client"
|
"github.com/docker/compose-cli/api/client"
|
||||||
|
"github.com/docker/compose-cli/api/containers"
|
||||||
"github.com/docker/compose-cli/cli/options/run"
|
"github.com/docker/compose-cli/cli/options/run"
|
||||||
|
"github.com/docker/compose-cli/context/store"
|
||||||
"github.com/docker/compose-cli/progress"
|
"github.com/docker/compose-cli/progress"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Command runs a container
|
// Command runs a container
|
||||||
func Command() *cobra.Command {
|
func Command(contextType string) *cobra.Command {
|
||||||
var opts run.Opts
|
var opts run.Opts
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "run",
|
Use: "run",
|
||||||
@ -46,7 +46,6 @@ func Command() *cobra.Command {
|
|||||||
|
|
||||||
cmd.Flags().StringArrayVarP(&opts.Publish, "publish", "p", []string{}, "Publish a container's port(s). [HOST_PORT:]CONTAINER_PORT")
|
cmd.Flags().StringArrayVarP(&opts.Publish, "publish", "p", []string{}, "Publish a container's port(s). [HOST_PORT:]CONTAINER_PORT")
|
||||||
cmd.Flags().StringVar(&opts.Name, "name", "", "Assign a name to the container")
|
cmd.Flags().StringVar(&opts.Name, "name", "", "Assign a name to the container")
|
||||||
cmd.Flags().StringVar(&opts.DomainName, "domainname", "", "Container NIS domain name")
|
|
||||||
cmd.Flags().StringArrayVarP(&opts.Labels, "label", "l", []string{}, "Set meta data on a container")
|
cmd.Flags().StringArrayVarP(&opts.Labels, "label", "l", []string{}, "Set meta data on a container")
|
||||||
cmd.Flags().StringArrayVarP(&opts.Volumes, "volume", "v", []string{}, "Volume. Ex: storageaccount/my_share[:/absolute/path/to/target][:ro]")
|
cmd.Flags().StringArrayVarP(&opts.Volumes, "volume", "v", []string{}, "Volume. Ex: storageaccount/my_share[:/absolute/path/to/target][:ro]")
|
||||||
cmd.Flags().BoolVarP(&opts.Detach, "detach", "d", false, "Run container in background and print container ID")
|
cmd.Flags().BoolVarP(&opts.Detach, "detach", "d", false, "Run container in background and print container ID")
|
||||||
@ -55,6 +54,10 @@ func Command() *cobra.Command {
|
|||||||
cmd.Flags().StringArrayVarP(&opts.Environment, "env", "e", []string{}, "Set environment variables")
|
cmd.Flags().StringArrayVarP(&opts.Environment, "env", "e", []string{}, "Set environment variables")
|
||||||
cmd.Flags().StringVarP(&opts.RestartPolicyCondition, "restart", "", containers.RestartPolicyNone, "Restart policy to apply when a container exits")
|
cmd.Flags().StringVarP(&opts.RestartPolicyCondition, "restart", "", containers.RestartPolicyNone, "Restart policy to apply when a container exits")
|
||||||
|
|
||||||
|
if contextType == store.AciContextType {
|
||||||
|
cmd.Flags().StringVar(&opts.DomainName, "domainname", "", "Container NIS domain name")
|
||||||
|
}
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,15 +18,25 @@ package run
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"gotest.tools/v3/assert"
|
||||||
"gotest.tools/v3/golden"
|
"gotest.tools/v3/golden"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHelp(t *testing.T) {
|
func TestHelp(t *testing.T) {
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
c := Command()
|
c := Command("aci")
|
||||||
c.SetOutput(&b)
|
c.SetOutput(&b)
|
||||||
_ = c.Help()
|
_ = c.Help()
|
||||||
golden.Assert(t, b.String(), "run-help.golden")
|
golden.Assert(t, b.String(), "run-help.golden")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHelpNoDomainFlag(t *testing.T) {
|
||||||
|
var b bytes.Buffer
|
||||||
|
c := Command("default")
|
||||||
|
c.SetOutput(&b)
|
||||||
|
_ = c.Help()
|
||||||
|
assert.Assert(t, !strings.Contains(b.String(), "domainname"))
|
||||||
|
}
|
||||||
|
@ -115,7 +115,6 @@ func main() {
|
|||||||
contextcmd.Command(),
|
contextcmd.Command(),
|
||||||
cmd.PsCommand(),
|
cmd.PsCommand(),
|
||||||
cmd.ServeCommand(),
|
cmd.ServeCommand(),
|
||||||
run.Command(),
|
|
||||||
cmd.ExecCommand(),
|
cmd.ExecCommand(),
|
||||||
cmd.LogsCommand(),
|
cmd.LogsCommand(),
|
||||||
cmd.RmCommand(),
|
cmd.RmCommand(),
|
||||||
@ -180,6 +179,8 @@ func main() {
|
|||||||
ctype = cc.Type()
|
ctype = cc.Type()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
root.AddCommand(run.Command(ctype))
|
||||||
|
|
||||||
if ctype == store.AciContextType {
|
if ctype == store.AciContextType {
|
||||||
// we can also pass ctype as a parameter to the volume command and customize subcommands, flags, etc. when we have other backend implementations
|
// we can also pass ctype as a parameter to the volume command and customize subcommands, flags, etc. when we have other backend implementations
|
||||||
root.AddCommand(volume.ACICommand())
|
root.AddCommand(volume.ACICommand())
|
||||||
|
@ -64,7 +64,7 @@ func TestCheckOwnCommand(t *testing.T) {
|
|||||||
assert.Assert(t, isContextAgnosticCommand(login.Command()))
|
assert.Assert(t, isContextAgnosticCommand(login.Command()))
|
||||||
assert.Assert(t, isContextAgnosticCommand(context.Command()))
|
assert.Assert(t, isContextAgnosticCommand(context.Command()))
|
||||||
assert.Assert(t, isContextAgnosticCommand(cmd.ServeCommand()))
|
assert.Assert(t, isContextAgnosticCommand(cmd.ServeCommand()))
|
||||||
assert.Assert(t, !isContextAgnosticCommand(run.Command()))
|
assert.Assert(t, !isContextAgnosticCommand(run.Command("default")))
|
||||||
assert.Assert(t, !isContextAgnosticCommand(cmd.ExecCommand()))
|
assert.Assert(t, !isContextAgnosticCommand(cmd.ExecCommand()))
|
||||||
assert.Assert(t, !isContextAgnosticCommand(cmd.LogsCommand()))
|
assert.Assert(t, !isContextAgnosticCommand(cmd.LogsCommand()))
|
||||||
assert.Assert(t, !isContextAgnosticCommand(cmd.PsCommand()))
|
assert.Assert(t, !isContextAgnosticCommand(cmd.PsCommand()))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user