Skip to content
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

use new project and starterProject git specification #3867

Merged
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ require (
github.com/fatih/color v1.7.0
github.com/fsnotify/fsnotify v1.4.9
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/go-git/go-git/v5 v5.1.0
github.com/gobwas/glob v0.2.4-0.20181002190808-e7a84e9525fe
github.com/golang/mock v1.4.3
github.com/google/go-github/v32 v32.1.0
github.com/google/go-querystring v1.0.1-0.20190318165438-c8c88dbee036 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79
github.com/hinshun/vt10x v0.0.0-20180809195222-d55458df857c
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
Expand Down Expand Up @@ -62,7 +61,7 @@ replace (
github.com/apcera/gssapi => github.com/openshift/gssapi v0.0.0-20161010215902-5fb4217df13b
github.com/containers/image => github.com/openshift/containers-image v0.0.0-20190130162819-76de87591e9d
github.com/docker/docker => github.com/docker/docker v17.12.0-ce-rc1.0.20200309214505-aa6a9891b09c+incompatible
github.com/kr/pty => github.com/creack/pty v1.1.9
github.com/kr/pty => github.com/creack/pty v1.1.11
github.com/openshift/api => github.com/openshift/api v0.0.0-20200205133042-34f0ec8dab87
k8s.io/api => k8s.io/api v0.17.1
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.17.1
Expand Down
49 changes: 45 additions & 4 deletions go.sum

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions pkg/devfile/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ func ParseFromURLAndValidate(url string) (d parser.DevfileObj, err error) {
return d, nil
}

// ParseFromDataAndValidate func parses the devfile data
// and validates the devfile integrity with the schema
// and validates the devfile data.
// Creates devfile context and runtime objects.
func ParseFromDataAndValidate(data []byte) (d parser.DevfileObj, err error) {
// read and parse devfile from the given bytes
d, err = parser.ParseFromData(data)
if err != nil {
return d, err
}

// odo specific validation on devfile content
err = validate.ValidateDevfileData(d.Data)
if err != nil {
return d, err
}

// Successful
return d, nil
}

// ParseAndValidate func parses the devfile data
// and validates the devfile integrity with the schema
// and validates the devfile data.
Expand Down
5 changes: 3 additions & 2 deletions pkg/devfile/parser/context/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package parser

import (
"bytes"
"github.com/openshift/odo/pkg/util"
"unicode"

"github.com/openshift/odo/pkg/util"

"github.com/ghodss/yaml"
"github.com/pkg/errors"
"k8s.io/klog"
Expand Down Expand Up @@ -52,7 +53,7 @@ func (d *DevfileCtx) SetDevfileContent() error {
var err error
var data []byte
if d.url != "" {
data, err = util.DownloadFileInMemory(d.url)
data, err = util.DownloadFileInMemory(util.HTTPRequestParams{URL: d.url})
if err != nil {
return errors.Wrap(err, "error getting parent info from url")
}
Expand Down
12 changes: 8 additions & 4 deletions pkg/devfile/parser/context/content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import (
const (
TempJSONDevfilePrefix = "odo-devfile.*.json"
InvalidDevfileContent = ":: invalid :: content"
validJson200 = `{ "schemaVersion": "2.0.0", "metadata": { "name": "java-maven", "version": "1.0.0" }, "components": [ { "container": { "name": "tools", "image": "quay.io/eclipse/che-java11-maven:nightly", "memoryLimit": "512Mi", "mountSources": true, "endpoints": [ { "name": "http-8080", "targetPort": 8080 } ], "volumeMounts": [ { "name": "m2", "path": "/home/user/.m2" } ] } }, { "volume": { "name": "m2" } } ], "commands": [ { "exec": { "id": "mvn-package", "component": "tools", "commandLine": "mvn package", "group": { "kind": "build", "isDefault": true } } }, { "exec": { "id": "run", "component": "tools", "commandLine": "java -jar target/*.jar", "group": { "kind": "run", "isDefault": true } } }, { "exec": { "id": "debug", "component": "tools", "commandLine": "java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=${DEBUG_PORT},suspend=n -jar target/*.jar", "group": { "kind": "debug", "isDefault": true } } } ] }`
)

func validJsonRawContent200() []byte {
return []byte(validJson200)
}
func TestSetDevfileContent(t *testing.T) {

const (
Expand Down Expand Up @@ -44,7 +48,7 @@ func TestSetDevfileContent(t *testing.T) {

var (
fakeFs = filesystem.NewFakeFs()
tempDevfile = createTempDevfile(t, validJsonRawContent100(), fakeFs)
tempDevfile = createTempDevfile(t, validJsonRawContent200(), fakeFs)
d = DevfileCtx{
absPath: tempDevfile.Name(),
Fs: fakeFs,
Expand Down Expand Up @@ -132,7 +136,7 @@ func TestSetDevfileContentFromBytes(t *testing.T) {

var (
fakeFs = filesystem.NewFakeFs()
tempDevfile = createTempDevfile(t, validJsonRawContent100(), fakeFs)
tempDevfile = createTempDevfile(t, validJsonRawContent200(), fakeFs)
d = DevfileCtx{
absPath: tempDevfile.Name(),
Fs: fakeFs,
Expand All @@ -141,7 +145,7 @@ func TestSetDevfileContentFromBytes(t *testing.T) {

defer os.Remove(tempDevfile.Name())

err := d.SetDevfileContentFromBytes(validJsonRawContent100())
err := d.SetDevfileContentFromBytes(validJsonRawContent200())

if err != nil {
t.Errorf("unexpected error '%v'", err)
Expand All @@ -156,7 +160,7 @@ func TestSetDevfileContentFromBytes(t *testing.T) {

var (
fakeFs = filesystem.NewFakeFs()
tempDevfile = createTempDevfile(t, []byte(validJsonRawContent100()), fakeFs)
tempDevfile = createTempDevfile(t, []byte(validJsonRawContent200()), fakeFs)
d = DevfileCtx{
absPath: tempDevfile.Name(),
Fs: fakeFs,
Expand Down
5 changes: 5 additions & 0 deletions pkg/devfile/parser/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ func (d *DevfileCtx) PopulateFromURL() (err error) {
return d.populateDevfile()
}

// PopulateFromRaw fills the DevfileCtx struct with relevant context info
func (d *DevfileCtx) PopulateFromRaw() (err error) {
return d.populateDevfile()
}

// Validate func validates devfile JSON schema for the given apiVersion
func (d *DevfileCtx) Validate() error {

Expand Down
2 changes: 1 addition & 1 deletion pkg/devfile/parser/context/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestPopulateFromBytes(t *testing.T) {
t.Run("valid data passed", func(t *testing.T) {

testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write(validJsonRawContent100())
_, err := w.Write(validJsonRawContent200())
if err != nil {
t.Error(err)
}
Expand Down
16 changes: 4 additions & 12 deletions pkg/devfile/parser/context/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ package parser
import (
"testing"

v100 "github.com/openshift/odo/pkg/devfile/parser/data/1.0.0"
)

const (
validJson100 = `{"apiVersion":"1.0.0","metadata":{"name":"java-web-spring"},"projects":[{"name":"java-web-spring","source":{"type":"git","location":"https://github.com/spring-projects/spring-petclinic.git"}}],"components":[{"type":"chePlugin","id":"redhat/java/latest","memoryLimit":"1512Mi"},{"alias":"tools","type":"dockerimage","image":"quay.io/eclipse/che-java8-maven:nightly","memoryLimit":"768Mi"}],"commands":[{"actions":[{"command":"mvn clean install","component":"tools","type":"build","workdir":"${CHE_PROJECTS_ROOT}/java-web-spring"}],"name":"maven build"},{"actions":[{"command":"java -jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 \\\ntarget/*.jar\n","component":"tools","type":"run","workdir":"${CHE_PROJECTS_ROOT}/java-web-spring"}],"name":"run webapp"}]}`
v200 "github.com/openshift/odo/pkg/devfile/parser/data/2.0.0"
)

func TestValidateDevfileSchema(t *testing.T) {
Expand All @@ -16,8 +12,8 @@ func TestValidateDevfileSchema(t *testing.T) {

var (
d = DevfileCtx{
jsonSchema: v100.JsonSchema100,
rawContent: validJsonRawContent100(),
jsonSchema: v200.JsonSchema200,
rawContent: validJsonRawContent200(),
}
)

Expand All @@ -31,7 +27,7 @@ func TestValidateDevfileSchema(t *testing.T) {

var (
d = DevfileCtx{
jsonSchema: v100.JsonSchema100,
jsonSchema: v200.JsonSchema200,
rawContent: []byte("{}"),
}
)
Expand All @@ -42,7 +38,3 @@ func TestValidateDevfileSchema(t *testing.T) {
}
})
}

func validJsonRawContent100() []byte {
return []byte(validJson100)
}
Loading