Skip to content

Commit

Permalink
failed to solve process /bin/sh -c apt-get update && apt get install …
Browse files Browse the repository at this point in the history
…-y curl did not complete successfully

Signed-off-by: schristoff <[email protected]>
  • Loading branch information
schristoff committed Nov 10, 2023
1 parent e3dfbeb commit 14d3d3f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build/testdata/bundles/wordpress/porter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
requires:
- name: mysql
bundle:
reference: localhost:5000/mysql:0.1.0
reference: localhost:5000/mysql:v0.1.0
parameters:
database-name: wordpress
mysql-user: wordpress
Expand Down
65 changes: 61 additions & 4 deletions pkg/cnab/extended_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sort"

depsv1ext "get.porter.sh/porter/pkg/cnab/extensions/dependencies/v1"
v2 "get.porter.sh/porter/pkg/cnab/extensions/dependencies/v2"
"get.porter.sh/porter/pkg/portercontext"
"get.porter.sh/porter/pkg/schema"
"github.com/Masterminds/semver/v3"
Expand Down Expand Up @@ -269,18 +270,23 @@ func (b *ExtendedBundle) ResolveSharedDeps(bun ExtendedBundle) ([]DependencyLock
q := make([]DependencyLock, 0, len(v2.Requires))
for _, d := range v2.Requires {

//todo(schristoff): make this better?
//todo(schristoff): We should 100% move this logic into
// the bundle validator area
if d.Sharing.Mode && d.Sharing.Group.Name == "" {
return nil, fmt.Errorf("dont do this")
}
if !d.Sharing.Mode && d.Sharing.Group.Name != "" {
return nil, fmt.Errorf("dont do this either")
}

ref, err := b.ResolveVersionv2(d.Name, d)
if err != nil {
return nil, err
}

lock := DependencyLock{
Alias: d.Name,
//note (schristoff): version isnt right
Reference: d.Version,
Alias: d.Name,
Reference: ref.String(),
SharingMode: d.Sharing.Mode,
SharingGroup: d.Sharing.Group.Name,
}
Expand Down Expand Up @@ -359,3 +365,54 @@ func (b *ExtendedBundle) determineDefaultTag(dep depsv1ext.Dependency) (string,
func (b *ExtendedBundle) BuildPrerequisiteInstallationName(installation string, dependency string) string {
return fmt.Sprintf("%s-%s", installation, dependency)
}

// this is all copied v2 stuff
// ResolveVersion returns the bundle name, its version and any error.
func (b *ExtendedBundle) ResolveVersionv2(name string, dep v2.Dependency) (OCIReference, error) {
ref, err := ParseOCIReference(dep.Bundle)
if err != nil {
return OCIReference{}, fmt.Errorf("error parsing dependency (%s) bundle %q as OCI reference: %w", name, dep.Bundle, err)
}

if dep.Version == "" {
// Check if they specified an explicit tag in referenced bundle already
if ref.HasTag() {
return ref, nil
}

tag, err := b.determineDefaultTagv2(dep)
if err != nil {
return OCIReference{}, err
}

return ref.WithTag(tag)
}

return OCIReference{}, fmt.Errorf("not implemented: dependency version range specified for %s: %w", name, err)
}

func (b *ExtendedBundle) determineDefaultTagv2(dep v2.Dependency) (string, error) {
tags, err := crane.ListTags(dep.Bundle)
if err != nil {
return "", fmt.Errorf("error listing tags for %s: %w", dep.Bundle, err)
}

var hasLatest bool
versions := make(semver.Collection, 0, len(tags))
for _, tag := range tags {
if tag == "latest" {
hasLatest = true
continue
}

}
if len(versions) == 0 {
if hasLatest {
return "latest", nil
} else {
return "", fmt.Errorf("no tag was specified for %s and none of the tags defined in the registry meet the criteria: semver formatted or 'latest'", dep.Bundle)
}
}

return versions[0].Original(), nil
}
17 changes: 12 additions & 5 deletions tests/integration/dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestDependenciesLifecycle(t *testing.T) {
// Publish the mysql bundle that we depend upon
publishMySQLBundle(ctx, p)

installWordpressBundle(ctx, p, namespace)
installWordpressBundle(ctx, p, namespace, "wordpress-mysql")
defer cleanupWordpressBundle(ctx, p, namespace)

upgradeWordpressBundle(ctx, p, namespace)
Expand Down Expand Up @@ -61,7 +61,10 @@ func publishMySQLBundle(ctx context.Context, p *porter.TestPorter) {
require.NoError(p.T(), err, "publish of dependent bundle failed")
}

func installWordpressBundle(ctx context.Context, p *porter.TestPorter, namespace string) {
func installWordpressBundle(ctx context.Context, p *porter.TestPorter, namespace string, mysqlName string) {

_, err := p.Installations.GetInstallation(ctx, namespace, "mysql")
require.NoError(p.T(), err, "could not fetch installation mysql")

// Install the bundle that has dependencies
p.CopyDirectory(filepath.Join(p.RepoRoot, "build/testdata/bundles/wordpress"), ".", false)
Expand All @@ -88,14 +91,14 @@ func installWordpressBundle(ctx context.Context, p *porter.TestPorter, namespace

p.TestParameters.InsertParameterSet(ctx, testParamSets)

err := installOpts.Validate(ctx, []string{}, p.Porter)
err = installOpts.Validate(ctx, []string{}, p.Porter)
require.NoError(p.T(), err, "validation of install opts for root bundle failed")

err = p.InstallBundle(ctx, installOpts)
require.NoError(p.T(), err, "install of root bundle failed namespace %s", namespace)

// Verify that the dependency claim is present
i, err := p.Installations.GetInstallation(ctx, namespace, "wordpress-mysql")
i, err := p.Installations.GetInstallation(ctx, namespace, mysqlName)
require.NoError(p.T(), err, "could not fetch installation status for the dependency")
assert.Equal(p.T(), cnab.StatusSucceeded, i.Status.ResultStatus, "the dependency wasn't recorded as being installed successfully")
c, err := p.Installations.GetLastRun(ctx, namespace, i.Name)
Expand Down Expand Up @@ -275,7 +278,11 @@ func TestSharedDependencies(t *testing.T) {

p.CopyDirectory(filepath.Join(p.RepoRoot, "build/testdata/bundles/mysql"), ".", false)
installMySQLbundle(ctx, p, namespace)
installWordpressBundle(ctx, p, namespace)

//set up dependency?
p.CopyFile("/cnab/app/mysql/bundle.json", "/cnab/app/dependencies/mysql/bundle.json")

installWordpressBundle(ctx, p, namespace, "mysql")

}

Expand Down

0 comments on commit 14d3d3f

Please sign in to comment.