nolint:gocyclo
(ctx context.Context, path string)
| 115 | |
| 116 | //nolint:gocyclo |
| 117 | func (g *ociRemoteLoader) Load(ctx context.Context, path string) (string, error) { |
| 118 | enabled, err := ociRemoteLoaderEnabled() |
| 119 | if err != nil { |
| 120 | return "", err |
| 121 | } |
| 122 | if !enabled { |
| 123 | return "", fmt.Errorf("OCI remote resource is disabled by %q", OCI_REMOTE_ENABLED) |
| 124 | } |
| 125 | |
| 126 | if g.offline { |
| 127 | return "", nil |
| 128 | } |
| 129 | |
| 130 | local, ok := g.known[path] |
| 131 | if !ok { |
| 132 | ref, err := reference.ParseDockerRef(path[len(OciPrefix):]) |
| 133 | if err != nil { |
| 134 | return "", err |
| 135 | } |
| 136 | |
| 137 | resolver := oci.NewResolver(g.dockerCli.ConfigFile(), g.httpTransport(ctx), g.insecureRegistries...) |
| 138 | |
| 139 | descriptor, content, err := oci.Get(ctx, resolver, ref) |
| 140 | if err != nil { |
| 141 | return "", fmt.Errorf("failed to pull OCI resource %q: %w", ref, err) |
| 142 | } |
| 143 | |
| 144 | cache, err := cacheDir() |
| 145 | if err != nil { |
| 146 | return "", fmt.Errorf("initializing remote resource cache: %w", err) |
| 147 | } |
| 148 | |
| 149 | local = filepath.Join(cache, descriptor.Digest.Hex()) |
| 150 | if _, err = os.Stat(local); os.IsNotExist(err) { |
| 151 | |
| 152 | // a Compose application bundle is published as an image index |
| 153 | if images.IsIndexType(descriptor.MediaType) { |
| 154 | var index spec.Index |
| 155 | err = json.Unmarshal(content, &index) |
| 156 | if err != nil { |
| 157 | return "", err |
| 158 | } |
| 159 | found := false |
| 160 | for _, manifest := range index.Manifests { |
| 161 | if manifest.ArtifactType != oci.ComposeProjectArtifactType { |
| 162 | continue |
| 163 | } |
| 164 | found = true |
| 165 | digested, err := reference.WithDigest(ref, manifest.Digest) |
| 166 | if err != nil { |
| 167 | return "", err |
| 168 | } |
| 169 | descriptor, content, err = oci.Get(ctx, resolver, digested) |
| 170 | if err != nil { |
| 171 | return "", fmt.Errorf("failed to pull OCI resource %q: %w", ref, err) |
| 172 | } |
| 173 | } |
| 174 | if !found { |
nothing calls this directly
no test coverage detected