diff --git a/clab/config.go b/clab/config.go index 034522cc6..651f45201 100644 --- a/clab/config.go +++ b/clab/config.go @@ -218,6 +218,7 @@ func (c *CLab) createNodeCfg(nodeName string, nodeDef *types.NodeDefinition, idx Position: c.Config.Topology.GetNodePosition(nodeName), Image: c.Config.Topology.GetNodeImage(nodeName), User: c.Config.Topology.GetNodeUser(nodeName), + Entrypoint: c.Config.Topology.GetNodeEntrypoint(nodeName), Cmd: c.Config.Topology.GetNodeCmd(nodeName), Env: c.Config.Topology.GetNodeEnv(nodeName), NetworkMode: strings.ToLower(c.Config.Topology.GetNodeNetworkMode(nodeName)), diff --git a/docs/manual/nodes.md b/docs/manual/nodes.md index 658eca686..cb958cc12 100644 --- a/docs/manual/nodes.md +++ b/docs/manual/nodes.md @@ -202,6 +202,21 @@ topology: user: clab # clab user will be used for node1 ``` +### entrypoint +Changing the entrypoint of the container is done with `entrypoint` config option. It accepts the "shell" form and can be set on all levels. + +```yaml +topology: + defaults: + entrypoint: entrypoint.sh + kinds: + srl: + cmd: entrypoint.sh + nodes: + node1: + cmd: entrypoint.sh +``` + ### cmd It is possible to set/override the command of the container image with `cmd` configuration option. It accepts the "shell" form and can be set on all levels. diff --git a/runtime/docker/docker.go b/runtime/docker/docker.go index 265ac97ee..732152bd8 100644 --- a/runtime/docker/docker.go +++ b/runtime/docker/docker.go @@ -245,8 +245,18 @@ func (c *DockerRuntime) CreateContainer(ctx context.Context, node *types.NodeCon return nil, err } + var entrypoint []string + if node.Entrypoint != "" { + entrypoint, err = shlex.Split(node.Entrypoint) + if err != nil { + return nil, err + } + + } + containerConfig := &container.Config{ Image: node.Image, + Entrypoint: entrypoint, Cmd: cmd, Env: utils.ConvertEnvs(node.Env), AttachStdout: true, diff --git a/types/node_definition.go b/types/node_definition.go index 7f425bfda..c935173c0 100644 --- a/types/node_definition.go +++ b/types/node_definition.go @@ -21,6 +21,7 @@ type NodeDefinition struct { Image string `yaml:"image,omitempty"` License string `yaml:"license,omitempty"` Position string `yaml:"position,omitempty"` + Entrypoint string `yaml:"entrypoint,omitempty"` Cmd string `yaml:"cmd,omitempty"` // list of bind mount compatible strings Binds []string `yaml:"binds,omitempty"` @@ -122,6 +123,13 @@ func (n *NodeDefinition) GetPostion() string { return n.Position } +func (n *NodeDefinition) GetEntrypoint() string { + if n == nil { + return "" + } + return n.Entrypoint +} + func (n *NodeDefinition) GetCmd() string { if n == nil { return "" @@ -246,8 +254,8 @@ func (n *NodeDefinition) ImportEnvs() { kv := strings.Split(e, "=") if _, exists := n.Env[kv[0]]; exists { continue - } else { - n.Env[kv[0]] = kv[1] } + + n.Env[kv[0]] = kv[1] } } diff --git a/types/topology.go b/types/topology.go index cb74d6131..9d82b908e 100644 --- a/types/topology.go +++ b/types/topology.go @@ -272,6 +272,19 @@ func (t *Topology) GetNodePosition(name string) string { return "" } +func (t *Topology) GetNodeEntrypoint(name string) string { + if ndef, ok := t.Nodes[name]; ok { + if ndef.GetEntrypoint() != "" { + return ndef.GetEntrypoint() + } + if t.GetKind(t.GetNodeKind(name)).GetEntrypoint() != "" { + return t.GetKind(t.GetNodeKind(name)).GetEntrypoint() + } + return t.GetDefaults().GetEntrypoint() + } + return "" +} + func (t *Topology) GetNodeCmd(name string) string { if ndef, ok := t.Nodes[name]; ok { if ndef.GetCmd() != "" {