Builder ensure that a builder container exists or return an error. Process: 1. Get an appropriate docker context. 2. Using the appropriate context, try to find a docker container named `linuxkit-builder` in that context. 3. Return a reference to that container. To get the appropriate docker conte
(ctx context.Context, dockerContext, builderImage, builderConfigPath, platform string, restart bool)
| 220 | // 2. try to find an existing named runner with the pattern; if it succeeds, we are done; if not, try next. |
| 221 | // 3. try to create a generic builder using the default context named "linuxkit". |
| 222 | func (dr *dockerRunnerImpl) Builder(ctx context.Context, dockerContext, builderImage, builderConfigPath, platform string, restart bool) (*buildkitClient.Client, error) { |
| 223 | // if we were given a context, we must find a builder and use it, or create one and use it |
| 224 | if dockerContext != "" { |
| 225 | // does the context exist? |
| 226 | if err := dr.command(nil, io.Discard, io.Discard, "context", "inspect", dockerContext); err != nil { |
| 227 | return nil, fmt.Errorf("provided docker context '%s' not found", dockerContext) |
| 228 | } |
| 229 | client, err := dr.builderEnsureContainer(ctx, buildkitBuilderName, builderImage, builderConfigPath, platform, dockerContext, restart) |
| 230 | if err != nil { |
| 231 | return nil, fmt.Errorf("error preparing builder based on context '%s': %v", dockerContext, err) |
| 232 | } |
| 233 | return client, nil |
| 234 | } |
| 235 | |
| 236 | // no provided dockerContext, so look for one based on platform-specific name |
| 237 | dockerContext = fmt.Sprintf("%s-%s", "linuxkit", strings.ReplaceAll(platform, "/", "-")) |
| 238 | if err := dr.command(nil, io.Discard, io.Discard, "context", "inspect", dockerContext); err == nil { |
| 239 | // we found an appropriately named context, so let us try to use it or error out |
| 240 | if client, err := dr.builderEnsureContainer(ctx, buildkitBuilderName, builderImage, builderConfigPath, platform, dockerContext, restart); err == nil { |
| 241 | return client, nil |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | // create a generic builder |
| 246 | client, err := dr.builderEnsureContainer(ctx, buildkitBuilderName, builderImage, builderConfigPath, "", "default", restart) |
| 247 | if err != nil { |
| 248 | return nil, fmt.Errorf("error ensuring builder container in default context: %v", err) |
| 249 | } |
| 250 | return client, nil |
| 251 | } |
| 252 | |
| 253 | // builderEnsureContainer provided a name of a docker context, ensure that the builder container exists and |
| 254 | // is running the appropriate version of buildkit. If it does not exist, create it; if it is running |
no test coverage detected