Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions build/testdata/bundles/mysql-interface/porter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
schemaVersion: 1.0.1
name: mysql-interface
version: 0.1.0
registry: "localhost:5000"

# This bundle is never installed -- it exists only to be published and
# referenced via interface.reference by a dependency elsewhere (see #2626),
# declaring the outputs a bundle must provide to satisfy the mysql
# interface.

mixins:
- exec

install:
- exec:
command: echo
arguments:
- "installed mysql-interface"

uninstall:
- exec:
command: echo
arguments:
- "uninstalled mysql-interface"

outputs:
- name: mysql-password
description: "The mysql database password"
type: string
14 changes: 14 additions & 0 deletions build/testdata/bundles/wordpressv2-interface-missing/helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail

install() {
mkdir -p /cnab/app/outputs
echo "topsecret-blog" >> /cnab/app/outputs/wordpress-password
}

ping() {
echo ping
}

# Call the requested function and pass the arguments as-is
"$@"
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
schemaVersion: 1.1.0
name: wordpress-interface-missing
version: 0.1.4
registry: "localhost:5000"

mixins:
- exec
- helm3:
repositories:
bitnami:
url: "https://charts.bitnami.com/bitnami"

dependencies:
requires:
- name: mysql
bundle:
reference: localhost:5000/mysql:v0.1.4
interface:
document:
outputs:
# mysql never produces this output -- any existing mysql
# installation fails to satisfy this interface, so the
# dependency must always be pulled instead of reused.
- name: mysql-connstr
sharing:
mode: true
group:
name: myapp
parameters:
database-name: wordpress
mysql-user: wordpress
namespace: wordpress

parameters:
- name: wordpress-name
type: string
default: porter-ci-wordpress
env: WORDPRESS_NAME
- name: wordpress-password
type: string
sensitive: true
applyTo:
- install
- upgrade
- name: namespace
type: string
default: 'wordpress'

install:
- exec:
command: ./helpers.sh
arguments:
- install

upgrade:
- exec:
command: ./helpers.sh
arguments:
- install

ping:
- exec:
description: "Ping"
command: ./helpers.sh
arguments:
- ping

uninstall:
- exec:
command: echo
arguments:
- uninstall wordpress

outputs:
- name: wordpress-password
description: "The Wordpress installation password"
type: string
default: "default-password"
applyTo:
- "install"
- "upgrade"
sensitive: true
path: /cnab/app/outputs/wordpress-password
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail

install() {
mkdir -p /cnab/app/outputs
echo "topsecret-blog" >> /cnab/app/outputs/wordpress-password
}

ping() {
echo ping
}

# Call the requested function and pass the arguments as-is
"$@"
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
schemaVersion: 1.1.0
name: wordpress-interface-reference
version: 0.1.4
registry: "localhost:5000"

mixins:
- exec
- helm3:
repositories:
bitnami:
url: "https://charts.bitnami.com/bitnami"

dependencies:
requires:
- name: mysql
bundle:
reference: localhost:5000/mysql:v0.1.4
interface:
reference: localhost:5000/mysql-interface:v0.1.0
sharing:
mode: true
group:
name: myapp
parameters:
database-name: wordpress
mysql-user: wordpress
namespace: wordpress

parameters:
- name: wordpress-name
type: string
default: porter-ci-wordpress
env: WORDPRESS_NAME
- name: wordpress-password
type: string
sensitive: true
applyTo:
- install
- upgrade
- name: namespace
type: string
default: 'wordpress'

install:
- exec:
command: ./helpers.sh
arguments:
- install

upgrade:
- exec:
command: ./helpers.sh
arguments:
- install

ping:
- exec:
description: "Ping"
command: ./helpers.sh
arguments:
- ping

uninstall:
- exec:
command: echo
arguments:
- uninstall wordpress

outputs:
- name: wordpress-password
description: "The Wordpress installation password"
type: string
default: "default-password"
applyTo:
- "install"
- "upgrade"
sensitive: true
path: /cnab/app/outputs/wordpress-password
14 changes: 14 additions & 0 deletions build/testdata/bundles/wordpressv2-interface/helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail

install() {
mkdir -p /cnab/app/outputs
echo "topsecret-blog" >> /cnab/app/outputs/wordpress-password
}

ping() {
echo ping
}

# Call the requested function and pass the arguments as-is
"$@"
80 changes: 80 additions & 0 deletions build/testdata/bundles/wordpressv2-interface/porter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
schemaVersion: 1.1.0
name: wordpress-interface
version: 0.1.4
registry: "localhost:5000"

mixins:
- exec
- helm3:
repositories:
bitnami:
url: "https://charts.bitnami.com/bitnami"

dependencies:
requires:
- name: mysql
bundle:
reference: localhost:5000/mysql:v0.1.4
interface:
document:
outputs:
- name: mysql-password
sharing:
mode: true
group:
name: myapp
parameters:
database-name: wordpress
mysql-user: wordpress
namespace: wordpress

parameters:
- name: wordpress-name
type: string
default: porter-ci-wordpress
env: WORDPRESS_NAME
- name: wordpress-password
type: string
sensitive: true
applyTo:
- install
- upgrade
- name: namespace
type: string
default: 'wordpress'

install:
- exec:
command: ./helpers.sh
arguments:
- install

upgrade:
- exec:
command: ./helpers.sh
arguments:
- install

ping:
- exec:
description: "Ping"
command: ./helpers.sh
arguments:
- ping

uninstall:
- exec:
command: echo
arguments:
- uninstall wordpress

outputs:
- name: wordpress-password
description: "The Wordpress installation password"
type: string
default: "default-password"
applyTo:
- "install"
- "upgrade"
sensitive: true
path: /cnab/app/outputs/wordpress-password
3 changes: 1 addition & 2 deletions pkg/cnab/config-adapter/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,7 @@ func TestManifestConverter_generateDependenciesv2(t *testing.T) {
Bundle: "getporter/azure-mysql:5.7",
Version: "5.7.x",
Interface: &depsv2ext.DependencyInterface{
ID: "https://porter.sh/interfaces/#mysql",
Reference: "getporter/mysql-spec:5.7",
ID: "https://porter.sh/interfaces/#mysql",
Document: depsv2ext.DependencyInterfaceDocument{
Outputs: map[string]bundle.Output{
"myoutput": {
Expand Down
1 change: 0 additions & 1 deletion pkg/cnab/config-adapter/testdata/porter-with-depsv2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dependencies:
version: 5.7.x
interface:
id: "https://porter.sh/interfaces/#mysql"
reference: "getporter/mysql-spec:5.7"
document:
outputs:
- name: myoutput
Expand Down
25 changes: 25 additions & 0 deletions pkg/cnab/extensions/dependencies/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"regexp"
"sort"

"github.com/cnabio/cnab-go/bundle"
)
Expand Down Expand Up @@ -251,3 +252,27 @@ type DependencyInterfaceDocument struct {
// Credentials defined on the bundle interface
Credentials map[string]bundle.Credential `json:"credentials,omitempty" mapstructure:"credentials,omitempty"`
}

// IsEmpty reports whether the document defines no outputs, parameters, or
// credentials.
func (d DependencyInterfaceDocument) IsEmpty() bool {
return len(d.Outputs) == 0 && len(d.Parameters) == 0 && len(d.Credentials) == 0
}

// Names returns the sorted names of the outputs, parameters, and
// credentials defined on this document.
func (d DependencyInterfaceDocument) Names() (outputs, parameters, credentials []string) {
outputs = mapKeys(d.Outputs)
parameters = mapKeys(d.Parameters)
credentials = mapKeys(d.Credentials)
return outputs, parameters, credentials
}

func mapKeys[V any](m map[string]V) []string {
names := make([]string, 0, len(m))
for name := range m {
names = append(names, name)
}
sort.Strings(names)
return names
}
Loading