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

Function New

pkg/cmd/compose/compose.go:50–161  ·  view source on GitHub ↗

New returns a new *composer.Composer.

(client *containerd.Client, globalOptions types.GlobalCommandOptions, options composer.Options, stdout, stderr io.Writer)

Source from the content-addressed store, hash-verified

48
49// New returns a new *composer.Composer.
50func New(client *containerd.Client, globalOptions types.GlobalCommandOptions, options composer.Options, stdout, stderr io.Writer) (*composer.Composer, error) {
51 if err := composer.Lock(globalOptions.DataRoot, globalOptions.Address); err != nil {
52 return nil, err
53 }
54
55 cniEnv, err := netutil.NewCNIEnv(globalOptions.CNIPath, globalOptions.CNINetConfPath, netutil.WithNamespace(globalOptions.Namespace), netutil.WithDefaultNetwork(globalOptions.BridgeIP))
56 if err != nil {
57 return nil, err
58 }
59 networkConfigs, err := cniEnv.NetworkList()
60 if err != nil {
61 return nil, err
62 }
63 options.NetworkExists = func(netName string) (bool, error) {
64 for _, f := range networkConfigs {
65 if f.Name == netName {
66 return true, nil
67 }
68 }
69 return false, nil
70 }
71
72 options.NetworkInUse = func(ctx context.Context, netName string) (bool, error) {
73 networkUsedByNsMap, err := netutil.UsedNetworks(ctx, client)
74 if err != nil {
75 return false, err
76 }
77 for _, v := range networkUsedByNsMap {
78 if strutil.InStringSlice(v, netName) {
79 return true, nil
80 }
81 }
82 return false, nil
83 }
84
85 volStore, err := volume.Store(globalOptions.Namespace, globalOptions.DataRoot, globalOptions.Address)
86 if err != nil {
87 return nil, err
88 }
89 // FIXME: this is racy. See note in up_volume.go
90 options.VolumeExists = volStore.Exists
91
92 options.ImageExists = func(ctx context.Context, rawRef string) (bool, error) {
93 parsedReference, err := referenceutil.Parse(rawRef)
94 if err != nil {
95 return false, err
96 }
97 ref := parsedReference.String()
98 if _, err := client.ImageService().Get(ctx, ref); err != nil {
99 if errors.Is(err, errdefs.ErrNotFound) {
100 return false, nil
101 }
102 return false, err
103 }
104 return true, nil
105 }
106
107 options.EnsureImage = func(ctx context.Context, imageName, pullMode, platform string, ps *serviceparser.Service, quiet bool) error {

Callers 15

logsActionFunction · 0.92
upActionFunction · 0.92
psActionFunction · 0.92
imagesActionFunction · 0.92
configActionFunction · 0.92
pullActionFunction · 0.92
pushActionFunction · 0.92
runActionFunction · 0.92
stopActionFunction · 0.92
downActionFunction · 0.92
execActionFunction · 0.92
copyActionFunction · 0.92

Calls 15

NetworkListMethod · 0.95
LockFunction · 0.92
NewCNIEnvFunction · 0.92
WithNamespaceFunction · 0.92
WithDefaultNetworkFunction · 0.92
UsedNetworksFunction · 0.92
InStringSliceFunction · 0.92
StoreFunction · 0.92
ParseFunction · 0.92
WriteFileFunction · 0.92
EnsureImageFunction · 0.92
VerifyFunction · 0.92

Tested by

no test coverage detected