Skip to content

Commit c2a14b0

Browse files
committed
use config file instead of env variable
Signed-off-by: Arjun Raja Yogidas <arjunry@amazon.com>
1 parent 53a6929 commit c2a14b0

12 files changed

Lines changed: 50 additions & 47 deletions

File tree

cmd/nerdctl/compose/compose_start.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ import (
2828
"github.com/containerd/errdefs"
2929

3030
"github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers"
31+
"github.com/containerd/nerdctl/v2/pkg/api/types"
3132
"github.com/containerd/nerdctl/v2/pkg/clientutil"
3233
"github.com/containerd/nerdctl/v2/pkg/cmd/compose"
34+
"github.com/containerd/nerdctl/v2/pkg/config"
3335
"github.com/containerd/nerdctl/v2/pkg/containerutil"
3436
"github.com/containerd/nerdctl/v2/pkg/labels"
3537
)
@@ -86,15 +88,15 @@ func startAction(cmd *cobra.Command, args []string) error {
8688
return fmt.Errorf("service %q has no container to start", svcName)
8789
}
8890

89-
if err := startContainers(ctx, client, containers); err != nil {
91+
if err := startContainers(ctx, client, containers, &globalOptions); err != nil {
9092
return err
9193
}
9294
}
9395

9496
return nil
9597
}
9698

97-
func startContainers(ctx context.Context, client *containerd.Client, containers []containerd.Container) error {
99+
func startContainers(ctx context.Context, client *containerd.Client, containers []containerd.Container, globalOptions *types.GlobalCommandOptions) error {
98100
eg, ctx := errgroup.WithContext(ctx)
99101
for _, c := range containers {
100102
c := c
@@ -112,7 +114,7 @@ func startContainers(ctx context.Context, client *containerd.Client, containers
112114
}
113115

114116
// in compose, always disable attach
115-
if err := containerutil.Start(ctx, c, false, false, client, ""); err != nil {
117+
if err := containerutil.Start(ctx, c, false, false, client, "", (*config.Config)(globalOptions)); err != nil {
116118
return err
117119
}
118120
info, err := c.Info(ctx, containerd.WithoutRefreshedMetadata)

cmd/nerdctl/container/container_run.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/containerd/nerdctl/v2/pkg/api/types"
3434
"github.com/containerd/nerdctl/v2/pkg/clientutil"
3535
"github.com/containerd/nerdctl/v2/pkg/cmd/container"
36+
"github.com/containerd/nerdctl/v2/pkg/config"
3637
"github.com/containerd/nerdctl/v2/pkg/consoleutil"
3738
"github.com/containerd/nerdctl/v2/pkg/containerutil"
3839
"github.com/containerd/nerdctl/v2/pkg/defaults"
@@ -446,10 +447,10 @@ func runAction(cmd *cobra.Command, args []string) error {
446447
}
447448

448449
// Setup container healthchecks.
449-
if err := healthcheck.CreateTimer(ctx, c); err != nil {
450+
if err := healthcheck.CreateTimer(ctx, c, (*config.Config)(&createOpt.GOptions)); err != nil {
450451
return fmt.Errorf("failed to create healthcheck timer: %w", err)
451452
}
452-
if err := healthcheck.StartTimer(ctx, c); err != nil {
453+
if err := healthcheck.StartTimer(ctx, c, (*config.Config)(&createOpt.GOptions)); err != nil {
453454
return fmt.Errorf("failed to start healthcheck timer: %w", err)
454455
}
455456

docs/healthchecks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ On Linux systems with systemd, nerdctl automatically creates and manages systemd
5555

5656
- systemd must be available on the system
5757
- Container must not be running in rootless mode
58-
- Environment variable `DISABLE_HC_SYSTEMD` must not be set to "true"
58+
- Configuration property `disable_hc_systemd` must not be set to `true` in nerdctl.toml
5959

6060
### How It Works
6161

pkg/cmd/compose/compose.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/containerd/nerdctl/v2/pkg/cmd/volume"
3434
"github.com/containerd/nerdctl/v2/pkg/composer"
3535
"github.com/containerd/nerdctl/v2/pkg/composer/serviceparser"
36+
"github.com/containerd/nerdctl/v2/pkg/config"
3637
"github.com/containerd/nerdctl/v2/pkg/imgutil"
3738
"github.com/containerd/nerdctl/v2/pkg/internal/filesystem"
3839
"github.com/containerd/nerdctl/v2/pkg/ipfs"
@@ -156,7 +157,7 @@ func New(client *containerd.Client, globalOptions types.GlobalCommandOptions, op
156157
return err
157158
}
158159

159-
return composer.New(options, client)
160+
return composer.New(options, client, (*config.Config)(&globalOptions))
160161
}
161162

162163
func imageVerifyOptionsFromCompose(ps *serviceparser.Service) types.ImageVerifyOptions {

pkg/cmd/container/restart.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
containerd "github.com/containerd/containerd/v2/client"
2424

2525
"github.com/containerd/nerdctl/v2/pkg/api/types"
26+
"github.com/containerd/nerdctl/v2/pkg/config"
2627
"github.com/containerd/nerdctl/v2/pkg/containerutil"
2728
"github.com/containerd/nerdctl/v2/pkg/idutil/containerwalker"
2829
)
@@ -38,7 +39,7 @@ func Restart(ctx context.Context, client *containerd.Client, containers []string
3839
if err := containerutil.Stop(ctx, found.Container, options.Timeout, options.Signal); err != nil {
3940
return err
4041
}
41-
if err := containerutil.Start(ctx, found.Container, false, false, client, ""); err != nil {
42+
if err := containerutil.Start(ctx, found.Container, false, false, client, "", (*config.Config)(&options.GOption)); err != nil {
4243
return err
4344
}
4445
_, err := fmt.Fprintln(options.Stdout, found.Req)

pkg/cmd/container/start.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
containerd "github.com/containerd/containerd/v2/client"
2424

2525
"github.com/containerd/nerdctl/v2/pkg/api/types"
26+
"github.com/containerd/nerdctl/v2/pkg/config"
2627
"github.com/containerd/nerdctl/v2/pkg/containerutil"
2728
"github.com/containerd/nerdctl/v2/pkg/idutil/containerwalker"
2829
)
@@ -40,7 +41,7 @@ func Start(ctx context.Context, client *containerd.Client, reqs []string, option
4041
if found.MatchCount > 1 {
4142
return fmt.Errorf("multiple IDs found with provided prefix: %s", found.Req)
4243
}
43-
if err := containerutil.Start(ctx, found.Container, options.Attach, options.Interactive, client, options.DetachKeys); err != nil {
44+
if err := containerutil.Start(ctx, found.Container, options.Attach, options.Interactive, client, options.DetachKeys, (*config.Config)(&options.GOptions)); err != nil {
4445
return err
4546
}
4647
if !options.Attach {

pkg/cmd/container/unpause.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
containerd "github.com/containerd/containerd/v2/client"
2424

2525
"github.com/containerd/nerdctl/v2/pkg/api/types"
26+
"github.com/containerd/nerdctl/v2/pkg/config"
2627
"github.com/containerd/nerdctl/v2/pkg/containerutil"
2728
"github.com/containerd/nerdctl/v2/pkg/idutil/containerwalker"
2829
)
@@ -35,7 +36,7 @@ func Unpause(ctx context.Context, client *containerd.Client, reqs []string, opti
3536
if found.MatchCount > 1 {
3637
return fmt.Errorf("multiple IDs found with provided prefix: %s", found.Req)
3738
}
38-
if err := containerutil.Unpause(ctx, client, found.Container.ID()); err != nil {
39+
if err := containerutil.Unpause(ctx, client, found.Container.ID(), (*config.Config)(&options.GOptions)); err != nil {
3940
return err
4041
}
4142

pkg/composer/composer.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/containerd/log"
3131

3232
"github.com/containerd/nerdctl/v2/pkg/composer/serviceparser"
33+
"github.com/containerd/nerdctl/v2/pkg/config"
3334
"github.com/containerd/nerdctl/v2/pkg/identifiers"
3435
"github.com/containerd/nerdctl/v2/pkg/reflectutil"
3536
)
@@ -54,7 +55,7 @@ type Options struct {
5455
IPFSAddress string
5556
}
5657

57-
func New(o Options, client *containerd.Client) (*Composer, error) {
58+
func New(o Options, client *containerd.Client, cfg *config.Config) (*Composer, error) {
5859
if o.NerdctlCmd == "" {
5960
return nil, errors.New("got empty nerdctl cmd")
6061
}
@@ -119,6 +120,7 @@ func New(o Options, client *containerd.Client) (*Composer, error) {
119120
Options: o,
120121
project: project,
121122
client: client,
123+
config: cfg,
122124
}
123125

124126
return c, nil
@@ -128,6 +130,7 @@ type Composer struct {
128130
Options
129131
project *compose.Project
130132
client *containerd.Client
133+
config *config.Config
131134
}
132135

133136
func (c *Composer) createNerdctlCmd(ctx context.Context, args ...string) *exec.Cmd {

pkg/composer/pause.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (c *Composer) Unpause(ctx context.Context, services []string, writer io.Wri
8383
for _, container := range containers {
8484
container := container
8585
eg.Go(func() error {
86-
if err := containerutil.Unpause(ctx, c.client, container.ID()); err != nil {
86+
if err := containerutil.Unpause(ctx, c.client, container.ID(), c.config); err != nil {
8787
return err
8888
}
8989
info, err := container.Info(ctx, containerd.WithoutRefreshedMetadata)

pkg/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type Config struct {
4646
DNS []string `toml:"dns,omitempty"`
4747
DNSOpts []string `toml:"dns_opts,omitempty"`
4848
DNSSearch []string `toml:"dns_search,omitempty"`
49+
DisableHCSystemd bool `toml:"disable_hc_systemd"`
4950
}
5051

5152
// New creates a default Config object statically,
@@ -71,5 +72,6 @@ func New() *Config {
7172
DNS: []string{},
7273
DNSOpts: []string{},
7374
DNSSearch: []string{},
75+
DisableHCSystemd: false,
7476
}
7577
}

0 commit comments

Comments
 (0)