Skip to content

Commit 542cecf

Browse files
authored
Merge pull request #166 from thin-edge/feat-set-container-host-in-config
feat: support setting explicit container host socket path in config file
2 parents 9822290 + 9137f79 commit 542cecf

File tree

19 files changed

+87
-22
lines changed

19 files changed

+87
-22
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,34 @@ The following features are supported by the plugin:
5151

5252
## Documentation
5353

54+
### Container Engine Detection
55+
56+
The plugin primarily uses the unix socket to interact with the container engine.
57+
58+
By default, the socket is auto detected by checking a list of known socket paths, and taking the first matching socket that exists. If no socket is found, then the application will repeat the socket detection and eventually giving up after a period of time.
59+
60+
The following table shows the list container engine socket paths and the order of precedence (where the first existing socket is used).
61+
62+
|Socket Path|Description|
63+
|-----------|-----------|
64+
|$DOCKER_HOST|Default Docker Environment variable|
65+
|$CONTAINER_HOST|Default Podman Environment variable|
66+
|unix:///run/user/{uid}/docker.sock|Docker rootless|
67+
|unix://$XDG_RUNTIME_DIR/podman/podman.sock|Podman rootless|
68+
|unix:///tmp/storage-run-{uid}/podman/podman.sock|Podman rootless|
69+
|unix:///var/run/docker.sock|Docker (rootful)|
70+
|unix:///run/podman/podman.sock|Podman (rootful)|
71+
|unix:///run/user/0/podman/podman.sock|Podman (rootful)|
72+
73+
Where `{uid}` is either the value of the `SUDO_UID` environment variable (if present), or the process's effective user ID.
74+
75+
If your device is not finding the correct socket path for your container engine, then you can explicitly set the socket path in the `tedge-container-plugin.toml` file. Below shows an example of such a snippet which forces the usage of the rootful podman api endpoint. You will need to restart the tedge-container-plugin service before the setting will take effect.
76+
77+
```toml
78+
[container]
79+
host = "unix:///run/podman/podman.sock"
80+
```
81+
5482
### Install/remove single containers
5583

5684
Containers can be installed and removed via the Cumulocity Software Management interface in the Device Management Application.

cli/container/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func NewListCommand(cliContext cli.Cli) *cobra.Command {
2222
RunE: func(cmd *cobra.Command, args []string) error {
2323
slog.Info("Executing", "cmd", cmd.CalledAs(), "args", args)
2424
ctx := context.Background()
25-
cli, err := container.NewContainerClient(ctx)
25+
cli, err := container.NewContainerClient(ctx, cliContext.GetContainerClientOptions()...)
2626
if err != nil {
2727
return err
2828
}

cli/container/remove.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type RemoveCommand struct {
1919
}
2020

2121
// removeCmd represents the remove command
22-
func NewRemoveCommand(ctx cli.Cli) *cobra.Command {
22+
func NewRemoveCommand(cliContext cli.Cli) *cobra.Command {
2323
command := &RemoveCommand{}
2424
cmd := &cobra.Command{
2525
Use: "remove",
@@ -35,7 +35,7 @@ Example 1: Remove a container
3535
ctx := context.Background()
3636
containerName := args[0]
3737

38-
cli, err := container.NewContainerClient(ctx)
38+
cli, err := container.NewContainerClient(ctx, cliContext.GetContainerClientOptions()...)
3939
if err != nil {
4040
return err
4141
}

cli/container_group/finalize.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ import (
1313
"github.com/thin-edge/tedge-container-plugin/pkg/container"
1414
)
1515

16-
func NewFinalizeCommand(ctx cli.Cli) *cobra.Command {
16+
func NewFinalizeCommand(cliContext cli.Cli) *cobra.Command {
1717
return &cobra.Command{
1818
Use: "finalize",
1919
Short: "Finalize container install/remove operation",
2020
RunE: func(cmd *cobra.Command, args []string) error {
2121
slog.Info("Executing", "cmd", cmd.CalledAs(), "args", args)
2222

23-
pruneImages := ctx.GetBool("container.pruneImages")
23+
pruneImages := cliContext.GetBool("container.pruneImages")
2424
if !pruneImages {
2525
return nil
2626
}
27-
cli, err := container.NewContainerClient(context.TODO())
27+
cli, err := container.NewContainerClient(context.TODO(), cliContext.GetContainerClientOptions()...)
2828
if err != nil {
2929
return err
3030
}

cli/container_group/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (c *InstallCommand) RunE(cmd *cobra.Command, args []string) error {
5252
projectName := args[0]
5353
stderr := cmd.ErrOrStderr()
5454

55-
cli, err := container.NewContainerClient(context.TODO())
55+
cli, err := container.NewContainerClient(context.TODO(), c.CommandContext.GetContainerClientOptions()...)
5656
if err != nil {
5757
return err
5858
}

cli/container_group/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func NewListCommand(cliContext cli.Cli) *cobra.Command {
4242
RunE: func(cmd *cobra.Command, args []string) error {
4343
slog.Info("Executing", "cmd", cmd.CalledAs(), "args", args)
4444
ctx := context.Background()
45-
cli, err := container.NewContainerClient(context.TODO())
45+
cli, err := container.NewContainerClient(context.TODO(), cliContext.GetContainerClientOptions()...)
4646
if err != nil {
4747
return err
4848
}

cli/container_group/remove.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (c *RemoveCommand) RunE(cmd *cobra.Command, args []string) error {
4040
ctx := context.Background()
4141
projectName := args[0]
4242

43-
cli, err := container.NewContainerClient(context.TODO())
43+
cli, err := container.NewContainerClient(context.TODO(), c.CommandContext.GetContainerClientOptions()...)
4444
if err != nil {
4545
return err
4646
}

cli/engine/docker.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ import (
1515

1616
type DockerCommand struct {
1717
*cobra.Command
18+
19+
CommandContext cli.Cli
1820
}
1921

2022
// NewRunCommand create a new run command
2123
func NewRunCommand(ctx cli.Cli) *cobra.Command {
22-
command := &DockerCommand{}
24+
command := &DockerCommand{
25+
CommandContext: ctx,
26+
}
2327
cmd := &cobra.Command{
2428
Use: "docker",
2529
Short: "Run a command using the detected container engine",
@@ -34,7 +38,7 @@ func NewRunCommand(ctx cli.Cli) *cobra.Command {
3438

3539
func (c *DockerCommand) RunE(cmd *cobra.Command, args []string) error {
3640
slog.Debug("Executing", "cmd", cmd.CalledAs(), "args", args)
37-
containerCli, err := container.NewContainerClient(context.TODO())
41+
containerCli, err := container.NewContainerClient(context.TODO(), c.CommandContext.GetContainerClientOptions()...)
3842
if err != nil {
3943
return err
4044
}

cli/run/cmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func NewRunCommand(cliContext cli.Cli) *cobra.Command {
4545

4646
device := cliContext.GetDeviceTarget()
4747
application, err := app.NewApp(device, app.Config{
48+
ContainerHost: cliContext.GetContainerHost(),
4849
ServiceName: cliContext.GetServiceName(),
4950
EnableMetrics: cliContext.MetricsEnabled(),
5051
DeleteFromCloud: cliContext.DeleteFromCloud(),

cli/self/check.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,15 @@ var SoftwareManagementActionRemove = "remove"
5252
type CheckCommand struct {
5353
*cobra.Command
5454

55-
ContainerName string
55+
CommandContext cli.Cli
56+
ContainerName string
5657
}
5758

5859
// NewCheckCommand represents the check command
5960
func NewCheckCommand(ctx cli.Cli) *cobra.Command {
60-
command := &CheckCommand{}
61+
command := &CheckCommand{
62+
CommandContext: ctx,
63+
}
6164
cmd := &cobra.Command{
6265
Use: "check",
6366
Args: cobra.ExactArgs(1),
@@ -78,7 +81,7 @@ func (c *CheckCommand) RunE(cmd *cobra.Command, args []string) error {
7881
}
7982

8083
// Check container self
81-
containerCLI, err := container.NewContainerClient(context.TODO())
84+
containerCLI, err := container.NewContainerClient(context.TODO(), c.CommandContext.GetContainerClientOptions()...)
8285
if err != nil {
8386
return err
8487
}

0 commit comments

Comments
 (0)