MCPcopy Create free account
hub / github.com/containerd/nerdctl / Parse

Function Parse

pkg/composer/serviceparser/serviceparser.go:437–490  ·  view source on GitHub ↗
(project *types.Project, svc types.ServiceConfig)

Source from the content-addressed store, hash-verified

435}
436
437func Parse(project *types.Project, svc types.ServiceConfig) (*Service, error) {
438 warnUnknownFields(svc)
439
440 replicas, err := getReplicas(svc)
441 if err != nil {
442 return nil, err
443 }
444
445 parsed := &Service{
446 Image: svc.Image,
447 PullMode: "missing",
448 Containers: make([]Container, replicas),
449 Unparsed: &svc,
450 }
451
452 if svc.Build == nil {
453 if parsed.Image == "" {
454 return nil, fmt.Errorf("service %s: missing image", svc.Name)
455 }
456 } else {
457 if parsed.Image == "" {
458 parsed.Image = DefaultImageName(project.Name, svc.Name)
459 }
460 parsed.Build, err = parseBuildConfig(svc.Build, project, parsed.Image)
461 if err != nil {
462 return nil, fmt.Errorf("service %s: failed to parse build: %w", svc.Name, err)
463 }
464 }
465
466 switch svc.PullPolicy {
467 case "", types.PullPolicyMissing, types.PullPolicyIfNotPresent:
468 // NOP
469 case types.PullPolicyAlways, types.PullPolicyNever:
470 parsed.PullMode = svc.PullPolicy
471 case types.PullPolicyBuild:
472 if parsed.Build == nil {
473 return nil, fmt.Errorf("service %s: pull_policy \"build\" requires build config", svc.Name)
474 }
475 parsed.Build.Force = true
476 parsed.PullMode = "never"
477 default:
478 return nil, fmt.Errorf("invalid --pull option %q", svc.PullPolicy)
479 }
480
481 for i := 0; i < replicas; i++ {
482 container, err := newContainer(project, parsed, i)
483 if err != nil {
484 return nil, err
485 }
486 parsed.Containers[i] = *container
487 }
488
489 return parsed, nil
490}
491
492func newContainer(project *types.Project, parsed *Service, i int) (*Container, error) {
493 svc := *parsed.Unparsed

Callers 15

PushMethod · 0.92
UpMethod · 0.92
PullMethod · 0.92
BuildMethod · 0.92
RunMethod · 0.92
ServicesMethod · 0.92
getContainersFromServiceFunction · 0.70
TestParseFunction · 0.70
TestParseDeprecatedFunction · 0.70
TestParseDeployFunction · 0.70
TestParseDevicesFunction · 0.70
TestParseRelativeFunction · 0.70

Calls 5

warnUnknownFieldsFunction · 0.85
getReplicasFunction · 0.85
DefaultImageNameFunction · 0.85
parseBuildConfigFunction · 0.85
newContainerFunction · 0.85

Tested by 11

getContainersFromServiceFunction · 0.56
TestParseFunction · 0.56
TestParseDeprecatedFunction · 0.56
TestParseDeployFunction · 0.56
TestParseDevicesFunction · 0.56
TestParseRelativeFunction · 0.56
TestParseNetworkModeFunction · 0.56
TestParseConfigsFunction · 0.56
TestParseBuildFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…