Skip to content

Commit

Permalink
Merge branch 'release/v1' into advanced-docker-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
richbai90 authored Jun 16, 2022
2 parents 9c1f3e1 + f8cb06c commit 3bd1596
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 37 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/prow-commands.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# https://github.com/jpmcb/prow-github-actions

# This reacts to issue comments and checks for prow slash comments, and runs the command if found.
name: "React to Prow Commands"
on: [issue_comment]
permissions:
issues: write # give permission to apply the lgtm label
pull-requests: write # give permission to approve the PR

jobs:
execute:
runs-on: ubuntu-latest
steps:
- uses: jpmcb/prow-github-actions@2ac4434b3ce3d523fc3e28a879ec671c4a7750fa # main
with:
prow-commands: |
/approve
/lgtm
github-token: "${{ secrets.GITHUB_TOKEN }}"
17 changes: 17 additions & 0 deletions .github/workflows/prow-merge-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# https://github.com/jpmcb/prow-github-actions

# This will check all pull requests that have the lgtm label, and if GitHub thinks it is mergeable, then the PR is merged.
name: "Merge Ready PRs"
on: [pull_request]
permissions:
issues: write # give permission to apply the lgtm label
pull-requests: write # give permission to approve the PR

jobs:
execute:
runs-on: ubuntu-latest
steps:
- uses: jpmcb/prow-github-actions@2ac4434b3ce3d523fc3e28a879ec671c4a7750fa # main
with:
jobs: "lgtm"
github-token: "${{ secrets.GITHUB_TOKEN }}"
3 changes: 2 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ and we will add you. **All** contributors belong here. 💯
* [Chioma Onyekpere](https://github.com/Simpcyclassy)
* [Hrittik Roy](https://github.com/hrittikhere)
* [Tanmay Chaudhry](https://github.com/tchaudhry91)
* [Rich Baird](https://github.com/richbai90)
* [Rich Baird](https://github.com/richbai90)
* [Kevin Barbour](https://github.com/kevinbarbour)
9 changes: 9 additions & 0 deletions OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# reviewers can comment with /lgtm, a label "lgtm" is put on the issue
reviewers:
- vinozzz

# approvers can comment with /approve, the bot leaves an approve code review, allowing it to be merged
approvers:
- carolynvs

# Once a PR has the lgtm label, and a "green" code review (from /approve), a cron job will notice the PR and merge it
2 changes: 1 addition & 1 deletion pkg/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ func ReadManifest(cxt *portercontext.Context, path string) (*Manifest, error) {

m, err := UnmarshalManifest(cxt, data)
if err != nil {
return nil, err
return nil, fmt.Errorf("unsupported property set or a custom action is defined incorrectly: %w", err)
}

m.ManifestPath = path
Expand Down
13 changes: 13 additions & 0 deletions pkg/manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,19 @@ func TestManifest_Validate_Dockerfile(t *testing.T) {
assert.EqualError(t, err, "Dockerfile template cannot be named 'Dockerfile' because that is the filename generated during porter build")
}

func TestManifest_Validate_WrongSchema(t *testing.T) {
c := config.NewTestConfig(t)

c.TestContext.AddTestFile("testdata/porter-with-badschema.yaml", config.Name)
_, err := LoadManifestFrom(context.Background(), c.Config, config.Name)

require.Error(t, err)
assert.Regexp(t,
"unsupported property set or a custom action is defined incorrectly: error unmarshaling custom action baddata",
err,
)
}

func TestReadManifest_URL(t *testing.T) {
cxt := portercontext.NewTestContext(t)
url := "https://raw.githubusercontent.com/getporter/porter/v0.27.1/pkg/manifest/testdata/simple.porter.yaml"
Expand Down
42 changes: 42 additions & 0 deletions pkg/manifest/testdata/porter-with-badschema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
schemaVersion: 1.0.0-alpha.1
name: hello
description: "An example Porter configuration"
version: v0.1.0
registry: "localhost:5000"

mixins:
- exec

maintainers:
- name: "John Doe"
email: "[email protected]"
url: "https://example.com/a"
- name: "Jane Doe"
url: "https://example.com/b"
- name: "Janine Doe"
email: "[email protected]"
- email: "[email protected]"
url: "https://example.com/c"

install:
- exec:
description: "Say Hello"
command: bash
flags:
c: echo Hello World

status:
- exec:
description: "Get World Status"
command: bash
flags:
c: echo The world is on fire

uninstall:
- exec:
description: "Say Goodbye"
command: bash
flags:
c: echo Goodbye World

baddata: true
63 changes: 35 additions & 28 deletions pkg/porter/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package porter

import (
"context"
"fmt"
"io/ioutil"
"testing"

Expand All @@ -23,33 +24,39 @@ func TestPorter_PrintManifestSchema(t *testing.T) {
}

func TestPorter_ValidateManifestSchema(t *testing.T) {
ctx := context.Background()
p := NewTestPorter(t)
defer p.Close()

// Load the default Porter manifest
b, err := ioutil.ReadFile("testdata/porter.yaml")
require.NoError(t, err)

// Load the manifest as a go dump
m := make(map[string]interface{})
err = yaml.Unmarshal(b, &m)
require.NoError(t, err)
manifestLoader := gojsonschema.NewGoLoader(m)

// Load the manifest schema
err = p.PrintManifestSchema(ctx)
require.NoError(t, err, "could not generate schema")
schema := p.TestConfig.TestContext.GetOutput()
schemaLoader := gojsonschema.NewStringLoader(schema)

// Validate the manifest against the schema
fails, err := gojsonschema.Validate(schemaLoader, manifestLoader)
require.NoError(t, err)

assert.Empty(t, fails.Errors(), "expected testdata/porter.yaml to validate against the porter schema")
// Print it pretty like
for _, err := range fails.Errors() {
t.Logf("%s", err)
manifests := []string{"testdata/porter.yaml", "testdata/porter-with-dependencies.yaml"}
for _, m := range manifests {
t.Run(fmt.Sprintf("Manifest %s", m), func(t *testing.T) {

ctx := context.Background()
p := NewTestPorter(t)
defer p.Close()

// Load the default Porter manifest
b, err := ioutil.ReadFile(m)
require.NoError(t, err)

// Load the manifest as a go dump
m := make(map[string]interface{})
err = yaml.Unmarshal(b, &m)
require.NoError(t, err)
manifestLoader := gojsonschema.NewGoLoader(m)

// Load the manifest schema
err = p.PrintManifestSchema(ctx)
require.NoError(t, err, "could not generate schema")
schema := p.TestConfig.TestContext.GetOutput()
schemaLoader := gojsonschema.NewStringLoader(schema)

// Validate the manifest against the schema
fails, err := gojsonschema.Validate(schemaLoader, manifestLoader)
require.NoError(t, err)

assert.Empty(t, fails.Errors(), "expected testdata/porter.yaml to validate against the porter schema")
// Print it pretty like
for _, err := range fails.Errors() {
t.Logf("%s", err)
}
})
}
}
90 changes: 90 additions & 0 deletions pkg/porter/testdata/porter-with-dependencies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
schemaVersion: 1.0.0-alpha.1
name: porter-hello
version: 0.1.0
description: "A bundle with dependencies"
registry: "localhost:5000"

custom:
customKey1: "customValue1"

credentials:
- name: my-first-cred
env: MY_FIRST_CRED
- name: my-second-cred
description: "My second cred"
path: /path/to/my-second-cred

images:
something:
description: "an image"
imageType: "docker"
repository: "getporter/boo"

dependencies:
requires:
- name: some-dep
bundle:
reference: some-repo
version: ">1.0"
parameters:
param1: first-param

parameters:
- name: my-first-param
type: integer
default: 9
env: MY_FIRST_PARAM
applyTo:
- "install"
- name: my-second-param
description: "My second parameter"
type: string
default: spring-music-demo
path: /path/to/my-second-param
sensitive: true

outputs:
- name: my-first-output
type: string
applyTo:
- "install"
- "upgrade"
sensitive: true
- name: my-second-output
description: "My second output"
type: boolean
sensitive: false
- name: kubeconfig
type: file
path: /home/nonroot/.kube/config

mixins:
- exec

install:
- exec:
description: "Install Hello World with custom arguments"
command: echo
arguments:
- "{{ bundle.custom.customKey1 }}"

upgrade:
- exec:
description: "World 2.0"
command: bash
flags:
c: echo World 2.0

zombies:
- exec:
description: "Trigger zombie apocalypse"
command: bash
flags:
c: echo oh noes my brains

uninstall:
- exec:
description: "Uninstall Hello World"
command: bash
flags:
c: echo Goodbye World
25 changes: 21 additions & 4 deletions pkg/porter/testdata/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@
},
"type": "array"
},
"bundle": {
"description": "The defintion of a bundle reference",
"properties": {
"reference": {
"description": "The full bundle reference for the dependency in the format REGISTRY/NAME:TAG",
"type": "string"
},
"version": {
"description": "Bundle version contstraint for version matching, see https://github.com/Masterminds/semver/blob/master/README.md#checking-version-constraints",
"type": "string"
}
},
"required": [
"reference"
],
"type": "object"
},
"credential": {
"description": "Credential defines a particular credential, and where it should be placed in the invocation image",
"properties": {
Expand Down Expand Up @@ -72,19 +89,19 @@
"dependency": {
"additionalProperties": false,
"properties": {
"bundle": {
"$ref": "#/definitions/bundle"
},
"name": {
"type": "string"
},
"parameters": {
"type": "object"
},
"reference": {
"type": "string"
}
},
"required": [
"name",
"reference"
"bundle"
],
"type": "object"
},
Expand Down
23 changes: 20 additions & 3 deletions pkg/schema/manifest.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,32 @@
"name": {
"type": "string"
},
"reference": {
"type": "string"
"bundle": {
"$ref": "#/definitions/bundle"
},
"parameters": {
"type": "object"
}
},
"required": [
"name",
"bundle"
],
"type": "object"
},
"bundle": {
"description": "The defintion of a bundle reference",
"properties": {
"reference": {
"description": "The full bundle reference for the dependency in the format REGISTRY/NAME:TAG",
"type": "string"
},
"version": {
"description": "Bundle version contstraint for version matching, see https://github.com/Masterminds/semver/blob/master/README.md#checking-version-constraints",
"type": "string"
}
},
"required": [
"reference"
],
"type": "object"
Expand Down Expand Up @@ -436,4 +453,4 @@
"upgrade",
"uninstall"
]
}
}

0 comments on commit 3bd1596

Please sign in to comment.