-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve bundle digests when DepV2 is enabled #3071
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -7,13 +7,15 @@ import ( | |||
"strings" | ||||
|
||||
cnabtooci "get.porter.sh/porter/pkg/cnab/cnab-to-oci" | ||||
"get.porter.sh/porter/pkg/experimental" | ||||
|
||||
"get.porter.sh/porter/pkg" | ||||
"get.porter.sh/porter/pkg/build" | ||||
"get.porter.sh/porter/pkg/cnab" | ||||
"get.porter.sh/porter/pkg/manifest" | ||||
"get.porter.sh/porter/pkg/tracing" | ||||
"get.porter.sh/porter/pkg/yaml" | ||||
"github.com/docker/distribution/reference" | ||||
"github.com/mikefarah/yq/v3/pkg/yqlib" | ||||
"github.com/opencontainers/go-digest" | ||||
"go.opentelemetry.io/otel/attribute" | ||||
|
@@ -111,15 +113,83 @@ func (p *Porter) generateInternalManifest(ctx context.Context, opts BuildOptions | |||
} | ||||
} | ||||
return e.SetValue(path+"digest", digest.String()) | ||||
|
||||
}) | ||||
if err != nil { | ||||
return err | ||||
} | ||||
|
||||
if p.IsFeatureEnabled(experimental.FlagDependenciesV2) { | ||||
if err = p.resolveDependencyDigest(ctx, e, regOpts); err != nil { | ||||
return err | ||||
} | ||||
} | ||||
|
||||
return e.WriteFile(build.LOCAL_MANIFEST) | ||||
} | ||||
|
||||
func (p *Porter) resolveDependencyDigest(ctx context.Context, e *yaml.Editor, opts cnabtooci.RegistryOptions) error { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be reworked to leverage existing dependency resolution logic? - moving this into "validate" logic may help us reduce LOC and improve efficiency :) |
||||
// find all referenced dependencies that does not have digest specified | ||||
// get the digest for all of them and update the manifest with the digest | ||||
return e.WalkNodes(ctx, "dependencies.requires.*", func(ctx context.Context, nc *yqlib.NodeContext) error { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My only concern is
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @schristoff Number 2 Should be covered by the existing integration for shared dependencies,
Do you agree? |
||||
ctx, span := tracing.StartSpanWithName(ctx, "updateDependencyTagToDigest") | ||||
defer span.EndSpan() | ||||
|
||||
dep := &manifest.Dependency{} | ||||
if err := nc.Node.Decode(dep); err != nil { | ||||
return span.Errorf("failed to deserialize dependency in manifest: %w", err) | ||||
} | ||||
|
||||
span.SetAttributes(attribute.String("dependency", dep.Name)) | ||||
|
||||
bundleOpts := BundleReferenceOptions{ | ||||
BundlePullOptions: BundlePullOptions{ | ||||
Reference: dep.Bundle.Reference, | ||||
InsecureRegistry: opts.InsecureRegistry, | ||||
}, | ||||
} | ||||
|
||||
ref, err := cnab.ParseOCIReference(dep.Bundle.Reference) | ||||
if err != nil { | ||||
return span.Errorf("failed to parse OCI reference for dependency %s: %w", dep.Name, err) | ||||
} | ||||
|
||||
if ref.Tag() == "" || ref.Tag() == "latest" { | ||||
return nil | ||||
} | ||||
|
||||
bundleRef, err := p.resolveBundleReference(ctx, &bundleOpts) | ||||
if err != nil { | ||||
return span.Errorf("failed to resolve dependency %s: %w", dep.Name, err) | ||||
} | ||||
|
||||
digest := bundleRef.Digest | ||||
span.SetAttributes(attribute.String("digest", digest.Encoded())) | ||||
|
||||
var path string | ||||
for _, p := range nc.PathStack { | ||||
switch t := p.(type) { | ||||
case string: | ||||
path += fmt.Sprintf("%s.", t) | ||||
case int: | ||||
path = strings.TrimSuffix(path, ".") | ||||
path += fmt.Sprintf("[%s].", strconv.Itoa(t)) | ||||
default: | ||||
continue | ||||
} | ||||
} | ||||
|
||||
newRef := cnab.OCIReference{ | ||||
Named: reference.TrimNamed(bundleRef.Reference.Named), | ||||
} | ||||
refWithDigest, err := newRef.WithDigest(digest) | ||||
if err != nil { | ||||
return span.Errorf("failed to set digest: %w", err) | ||||
} | ||||
|
||||
return e.SetValue(path+"bundle.reference", refWithDigest.String()) | ||||
}) | ||||
} | ||||
|
||||
// getImageDigest retrieves the repository digest associated with the specified image reference. | ||||
func (p *Porter) getImageDigest(ctx context.Context, img cnab.OCIReference, regOpts cnabtooci.RegistryOptions) (digest.Digest, error) { | ||||
ctx, span := tracing.StartSpan(ctx, attribute.String("image", img.String())) | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
schemaVersion: 1.0.0-alpha.1 | ||
name: porter-hello | ||
version: 0.1.0 | ||
description: "An example Porter configuration" | ||
registry: "localhost:5000" | ||
mixins: | ||
- exec | ||
dependencies: | ||
requires: | ||
- name: mysql | ||
bundle: | ||
reference: getporter/mysql | ||
- name: mysqlLatest | ||
bundle: | ||
reference: getporter/mysql:latest | ||
install: | ||
- exec: | ||
description: "Install Hello World" | ||
command: ./helpers.sh | ||
arguments: | ||
- install | ||
status: | ||
- exec: | ||
description: "World Status" | ||
command: ./helpers.sh | ||
arguments: | ||
- status | ||
uninstall: | ||
- exec: | ||
description: "Uninstall Hello World" | ||
command: ./helpers.sh | ||
arguments: | ||
- uninstall |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
schemaVersion: 1.0.0-alpha.1 | ||
name: porter-hello | ||
version: 0.1.0 | ||
description: "An example Porter configuration" | ||
registry: "localhost:5000" | ||
mixins: | ||
- exec | ||
dependencies: | ||
requires: | ||
- name: mysql | ||
bundle: | ||
reference: getporter/mysql@sha256:3abc67269f59e3ed824e811a1ff1ee64f0d44c0218efefada57a4bebc2d7ef6f | ||
install: | ||
- exec: | ||
description: "Install Hello World" | ||
command: ./helpers.sh | ||
arguments: | ||
- install | ||
status: | ||
- exec: | ||
description: "World Status" | ||
command: ./helpers.sh | ||
arguments: | ||
- status | ||
uninstall: | ||
- exec: | ||
description: "Uninstall Hello World" | ||
command: ./helpers.sh | ||
arguments: | ||
- uninstall |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
schemaVersion: 1.0.0-alpha.1 | ||
name: porter-hello | ||
version: 0.1.0 | ||
description: "An example Porter configuration" | ||
registry: "localhost:5000" | ||
mixins: | ||
- exec | ||
dependencies: | ||
requires: | ||
- name: mysql | ||
bundle: | ||
reference: getporter/mysql | ||
- name: mysqlLatest | ||
bundle: | ||
reference: getporter/mysql:latest | ||
install: | ||
- exec: | ||
description: "Install Hello World" | ||
command: ./helpers.sh | ||
arguments: | ||
- install | ||
status: | ||
- exec: | ||
description: "World Status" | ||
command: ./helpers.sh | ||
arguments: | ||
- status | ||
uninstall: | ||
- exec: | ||
description: "Uninstall Hello World" | ||
command: ./helpers.sh | ||
arguments: | ||
- uninstall |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
schemaVersion: 1.0.0-alpha.1 | ||
name: porter-hello | ||
version: 0.1.0 | ||
description: "An example Porter configuration" | ||
registry: "localhost:5000" | ||
mixins: | ||
- exec | ||
dependencies: | ||
requires: | ||
- name: mysql | ||
bundle: | ||
reference: getporter/mysql:v0.1.4 | ||
install: | ||
- exec: | ||
description: "Install Hello World" | ||
command: ./helpers.sh | ||
arguments: | ||
- install | ||
status: | ||
- exec: | ||
description: "World Status" | ||
command: ./helpers.sh | ||
arguments: | ||
- status | ||
uninstall: | ||
- exec: | ||
description: "Uninstall Hello World" | ||
command: ./helpers.sh | ||
arguments: | ||
- uninstall |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as below (?) - I would love to see this moved into here - we can use this too :)