diff --git a/internal/cli/config.go b/internal/cli/config.go index 41fe3bb6..8c739554 100644 --- a/internal/cli/config.go +++ b/internal/cli/config.go @@ -7,7 +7,7 @@ import ( ) var name, bucket string -var dev bool +var dev, rootless bool var configCmd = &cobra.Command{ Use: "config", @@ -33,6 +33,8 @@ var configCmd = &cobra.Command{ cfg.Cli.Dev = false cfg.Container.Image = "controlplane/simulator:latest" } + + cfg.Container.Rootless = rootless }, } @@ -40,6 +42,7 @@ func init() { configCmd.PersistentFlags().StringVar(&name, "name", "simulator", "the name for the infrastructure") configCmd.PersistentFlags().StringVar(&bucket, "bucket", "", "the s3 bucket used for storage") configCmd.PersistentFlags().BoolVar(&dev, "dev", false, "developer mode") + configCmd.PersistentFlags().BoolVar(&rootless, "rootless", false, "docker running in rootless mode") simulatorCmd.AddCommand(configCmd) } diff --git a/internal/config/config.go b/internal/config/config.go index fcec4e90..33ce1edc 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -27,7 +27,8 @@ type Config struct { } `yaml:"cli,omitempty"` Container struct { - Image string `yaml:"image"` + Image string `yaml:"image"` + Rootless bool `yaml:"rootless,omitempty"` } `yaml:"container"` } diff --git a/internal/container/runner.go b/internal/container/runner.go index 6f2a9bed..5d54e974 100644 --- a/internal/container/runner.go +++ b/internal/container/runner.go @@ -92,15 +92,22 @@ func (r simulator) Run(ctx context.Context, command []string) error { }...) } + containerConfig := &container.Config{ + Image: r.Config.Container.Image, + Env: aws.Env, + Cmd: command, + Tty: true, + AttachStdout: true, + AttachStderr: true, + } + + if r.Config.Container.Rootless { + // map to host user for directory access + containerConfig.User = "0:0" + } + cont, err := cli.ContainerCreate(ctx, - &container.Config{ - Image: r.Config.Container.Image, - Env: aws.Env, - Cmd: command, - Tty: true, - AttachStdout: true, - AttachStderr: true, - }, + containerConfig, &container.HostConfig{ Mounts: mounts, }, @@ -137,7 +144,7 @@ func (r simulator) Run(ctx context.Context, command []string) error { err = cli.ContainerStart(ctx, cont.ID, types.ContainerStartOptions{}) if err != nil { - return StartFailed + return errors.Join(StartFailed, err) } var wg sync.WaitGroup