Skip to content

Commit

Permalink
Merge pull request #603 from srl-labs/entrypoint
Browse files Browse the repository at this point in the history
added entrypoint config
  • Loading branch information
hellt committed Aug 31, 2021
2 parents 356e281 + 63e6e4c commit f40c84e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
15 changes: 15 additions & 0 deletions docs/manual/nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
10 changes: 10 additions & 0 deletions runtime/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 10 additions & 2 deletions types/node_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 ""
Expand Down Expand Up @@ -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]
}
}
13 changes: 13 additions & 0 deletions types/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() != "" {
Expand Down

0 comments on commit f40c84e

Please sign in to comment.