BoostrapContainer runs a script inside the container as the provided user. If conf.Script is empty then it is a noop.
(ctx context.Context, client Client, conf BootstrapConfig)
| 100 | // BoostrapContainer runs a script inside the container as the provided user. |
| 101 | // If conf.Script is empty then it is a noop. |
| 102 | func BootstrapContainer(ctx context.Context, client Client, conf BootstrapConfig) error { |
| 103 | if conf.Script == "" { |
| 104 | return nil |
| 105 | } |
| 106 | |
| 107 | var err error |
| 108 | for r, n := retry.New(time.Second, time.Second*2), 0; r.Wait(ctx) && n < 10; n++ { |
| 109 | var out []byte |
| 110 | out, err = ExecContainer(ctx, client, ExecConfig{ |
| 111 | ContainerID: conf.ContainerID, |
| 112 | User: conf.User, |
| 113 | Cmd: "/bin/sh", |
| 114 | Args: []string{"-s"}, |
| 115 | Stdin: strings.NewReader(conf.Script), |
| 116 | Env: conf.Env, |
| 117 | StdOutErr: conf.StdOutErr, |
| 118 | Detach: conf.Detach, |
| 119 | }) |
| 120 | if err != nil { |
| 121 | err = xerrors.Errorf("boostrap container (%s): %w", out, err) |
| 122 | continue |
| 123 | } |
| 124 | break |
| 125 | } |
| 126 | |
| 127 | if err != nil { |
| 128 | return xerrors.Errorf("timed out boostrapping container: %w", err) |
| 129 | } |
| 130 | |
| 131 | return nil |
| 132 | } |
| 133 | |
| 134 | // SetContainerQuota writes a quota to its correct location for the inner container. |
| 135 | // HACK: until https://github.com/nestybox/sysbox/issues/582 is resolved, we need to copy |
nothing calls this directly
no test coverage detected