Skip to content

Commit

Permalink
Merge pull request #17457 from mjudeikis/bugzilla_1470374
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue (batch tested with PRs 17539, 17457).

bug 1470374 - oc new-app behaviour 

oc new-app

`oc import-image openshift/ruby-20-centos7:latest --confirm -n openshift`

### Syntax 1. Case 1. Git: True. URL: Remote.
RESULT: All components created. Source build type.
EXPECTATION: OK
`oc new-app openshift/ruby-20-centos7:latest~https://github.com/openshift/ruby-hello-world.git`

### Syntax 1. Case 2. Git: False. URL: Remote. 
RESULT: All components created. Source build type. 
EXPECTATION: OK
`oc new-app openshift/ruby-20-centos7:latest~https://github.com/openshift/ruby-hello-world.git`
```
-bash-4.4# oc new-app openshift/ruby-20-centos7:latest~https://github.com/openshift/ruby-hello-world.git
warning: Cannot find git. Ensure that it is installed and in your path. Git is required to work with git repositories.
....
```
### Syntax 1. Case 3. GIT: False. URL: HostPath.
RESULT: All components created. BINARY build type.
EXPECTATION: ok
`oc new-app openshift/ruby-20-centos7:latest~/root/app-examples/ruby`
```
warning: Cannot find git. Ensure that it is installed and in your path. Git is required to work with git repositories.
...
```

### Syntax 1. Case 4. Git: True. URL: HostDir.
RESULT:  (?TBC?)
EXPECTATION: Check if hostDir is valid git - Source. Else - Binary. 
`oc new-app openshift/ruby-20-centos7:latest~/root/app-examples/ruby`

### Syntax 2. Case 1. GIT: True. URL: Remote. 
RESULT: All components created. Source build type.
EXPECTATION: OK
`oc new-app -i ruby-20-centos7:latest https://github.com/openshift/ruby-hello-world.git`

### Syntax 2. Case 2. GIT: False. URL: Remote
RESULT: No components created. We cant investigate remote repo.
EXPECTATION: Create all components same as `Syntax 1. Case 2`
`oc new-app -i ruby-20-centos7:latest https://github.com/openshift/ruby-hello-world.git`
```
warning: Cannot find git. Ensure that it is installed and in your path. Git is required to work with git repositories.
error: git binary not available
```

### Syntax 2. Case 3. GIT: False. URL: HostPath. 
RESULT:  All components created. BINARY build type. 
EXPECTATION: ok
`oc new-app -i ruby-20-centos7:latest /root/app-examples/ruby`

### Syntax 2. Case 4. GIT: True. URL: HostPath. 
RESULT:  (?TBC?)
EXPECTATION: Check if hostDir is valid git - Source. Else - Binary. 
`oc new-app -i ruby-20-centos7:latest /root/app-examples/ruby`

### Sytnax 3. Case 1. GIT: True. URL: Remote. 
RESULT: All components created. Source build type.
EXPECTATION: ok
`oc new-app -i ruby-20-centos7:latest --code https://github.com/openshift/ruby-hello-world.git`

### Sytnax 3. Case 2. GIT: False. URL: Remote.
RESULT: All components created. Source build type.
EXPECTATION: ok
`oc new-app -i ruby-20-centos7:latest --code https://github.com/openshift/ruby-hello-world.git`

### Sytnax 3. Case 3. GIT: False. URL: HostPath.
RESULT: All components created. Binary build type. 
EXPECTATION: ok
`oc new-app -i ruby-20-centos7:latest --code /root/app-examples/ruby`

### Sytnax 3. Case 4. GIT: True. URL: HostPath. 
RESULT:  (?TBC?)
EXPECTATION: If hostDir - git repo - Source build. Else Binary build.
`oc new-app -i ruby-20-centos7:latest --code /root/app-examples/ruby`



TODO:
- add tests to cover this case


https://bugzilla.redhat.com/show_bug.cgi?id=1470374
  • Loading branch information
openshift-merge-robot committed Jan 12, 2018
2 parents 781b665 + 4113dc5 commit 0b8095d
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 11 deletions.
1 change: 1 addition & 0 deletions pkg/generate/app/sourcelookup.go
Expand Up @@ -314,6 +314,7 @@ func (r *SourceRepository) DetectAuth() error {
_, _, err = gitRepo.TimedListRemote(10*time.Second, url.StringNoFragment(), "--heads")
if err != nil {
r.requiresAuth = true
fmt.Print("warning: Cannot check if git requires authentication.\n")
}
return nil
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/oc/generate/app/cmd/newapp.go
Expand Up @@ -649,7 +649,9 @@ func (c *AppConfig) RunQuery() (*QueryResult, error) {
}

b := &app.ReferenceBuilder{}
if err := AddComponentInputsToRefBuilder(b, &c.Resolvers, &c.ComponentInputs, &c.GenerationInputs); err != nil {
s := &c.SourceRepositories
i := &c.ImageStreams
if err := AddComponentInputsToRefBuilder(b, &c.Resolvers, &c.ComponentInputs, &c.GenerationInputs, s, i); err != nil {
return nil, err
}
components, repositories, errs := b.Result()
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/generate/app/cmd/newapp_test.go
Expand Up @@ -124,7 +124,7 @@ func TestValidate(t *testing.T) {
continue
}

if err := AddComponentInputsToRefBuilder(b, &c.cfg.Resolvers, &c.cfg.ComponentInputs, &c.cfg.GenerationInputs); err != nil {
if err := AddComponentInputsToRefBuilder(b, &c.cfg.Resolvers, &c.cfg.ComponentInputs, &c.cfg.GenerationInputs, &c.cfg.SourceRepositories, &c.cfg.ImageStreams); err != nil {
t.Errorf("%s: Unexpected error: %v", n, err)
continue
}
Expand Down
30 changes: 21 additions & 9 deletions pkg/oc/generate/app/cmd/resolve.go
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/openshift/origin/pkg/generate"
"github.com/openshift/origin/pkg/generate/app"
"github.com/openshift/origin/pkg/generate/git"
dockerfileutil "github.com/openshift/origin/pkg/util/docker/dockerfile"
)

Expand Down Expand Up @@ -99,9 +100,11 @@ func Resolve(appConfig *AppConfig) (*ResolvedComponents, error) {
r := &appConfig.Resolvers
c := &appConfig.ComponentInputs
g := &appConfig.GenerationInputs
s := &appConfig.SourceRepositories
i := &appConfig.ImageStreams
b := &app.ReferenceBuilder{}

if err := AddComponentInputsToRefBuilder(b, r, c, g); err != nil {
if err := AddComponentInputsToRefBuilder(b, r, c, g, s, i); err != nil {
return nil, err
}
components, repositories, errs := b.Result()
Expand Down Expand Up @@ -184,14 +187,25 @@ func Resolve(appConfig *AppConfig) (*ResolvedComponents, error) {

// AddSourceRepositoriesToRefBuilder adds the provided repositories to the reference builder, identifies which
// should be built using Docker, and then returns the full list of source repositories.
func AddSourceRepositoriesToRefBuilder(b *app.ReferenceBuilder, repos []string, g *GenerationInputs) (app.SourceRepositories, error) {
func AddSourceRepositoriesToRefBuilder(b *app.ReferenceBuilder, c *ComponentInputs, g *GenerationInputs, s, i *[]string) (app.SourceRepositories, error) {
strategy := g.Strategy
if strategy == generate.StrategyUnspecified {
strategy = generate.StrategySource
}
for _, s := range repos {
if repo, ok := b.AddSourceRepository(s, strategy); ok {
repo.SetContextDir(g.ContextDir)
// when git is installed we keep default logic. sourcelookup.go will do sorting of images, repos
if git.IsGitInstalled() || len(c.SourceRepositories) > 0 {
for _, s := range c.SourceRepositories {
if repo, ok := b.AddSourceRepository(s, strategy); ok {
repo.SetContextDir(g.ContextDir)
}
}
// when git is not installed we need to parse some logic to decide if we got 'new-app -i image code' or 'image -c code' syntax
} else if len(c.Components) > 0 && len(*i) > 0 && len(*s) == 0 || len(c.Components) > 0 && len(*i) == 0 && len(*s) > 0 {
for _, s := range c.Components {
if repo, ok := b.AddSourceRepository(s, strategy); ok {
repo.SetContextDir(g.ContextDir)
c.Components = []string{}
}
}
}
if len(g.Dockerfile) > 0 {
Expand Down Expand Up @@ -263,18 +277,16 @@ func DetectSource(repositories []*app.SourceRepository, d app.Detector, g *Gener
}

// AddComponentInputsToRefBuilder set up the components to be used by the reference builder.
func AddComponentInputsToRefBuilder(b *app.ReferenceBuilder, r *Resolvers, c *ComponentInputs, g *GenerationInputs) error {
func AddComponentInputsToRefBuilder(b *app.ReferenceBuilder, r *Resolvers, c *ComponentInputs, g *GenerationInputs, s, i *[]string) error {
// lookup source repositories first (before processing the component inputs)
repositories, err := AddSourceRepositoriesToRefBuilder(b, c.SourceRepositories, g)
repositories, err := AddSourceRepositoriesToRefBuilder(b, c, g, s, i)
if err != nil {
return err
}

// identify the types of the provided source locations
if err := DetectSource(repositories, r.Detector, g); err != nil {
return err
}

b.AddComponents(c.DockerImages, func(input *app.ComponentInput) app.ComponentReference {
input.Argument = fmt.Sprintf("--docker-image=%q", input.From)
input.Searcher = r.DockerSearcher
Expand Down
40 changes: 40 additions & 0 deletions test/cmd/newapp.sh
Expand Up @@ -471,5 +471,45 @@ os::cmd::expect_success_and_not_text 'oc new-app https://github.com/openshift/ru
# We permit running new-app against a remote URL which returns a template
os::cmd::expect_success 'oc new-app https://raw.githubusercontent.com/openshift/origin/master/examples/wordpress/template/wordpress-mysql.json --dry-run'

# new-app different syntax for new-app functionality
os::cmd::expect_success 'oc new-project new-app-syntax'
os::cmd::expect_success 'oc import-image openshift/ruby-20-centos7:latest --confirm'
os::cmd::expect_success 'oc import-image openshift/php-55-centos7:latest --confirm'
rm -rf ./test/testdata/testapp
git clone https://github.com/openshift/ruby-hello-world.git ./test/testdata/testapp
os::cmd::expect_success 'oc new-app ruby-20-centos7:latest~https://github.com/openshift/ruby-hello-world.git --dry-run'
os::cmd::expect_success 'oc new-app ruby-20-centos7:latest~./test/testdata/testapp --dry-run'
os::cmd::expect_success 'oc new-app -i ruby-20-centos7:latest https://github.com/openshift/ruby-hello-world.git --dry-run'
os::cmd::expect_success 'oc new-app -i ruby-20-centos7:latest ./test/testdata/testapp --dry-run'
os::cmd::expect_success 'oc new-app ruby-20-centos7:latest --code https://github.com/openshift/ruby-hello-world.git --dry-run'
os::cmd::expect_success 'oc new-app ruby-20-centos7:latest --code ./test/testdata/testapp --dry-run'
os::cmd::expect_success 'oc new-app -i ruby-20-centos7:latest --code https://github.com/openshift/ruby-hello-world.git --dry-run'
os::cmd::expect_success 'oc new-app -i ruby-20-centos7:latest --code ./test/testdata/testapp --dry-run'

os::cmd::expect_success 'oc new-app --code ./test/testdata/testapp --name test'
os::cmd::expect_success_and_text 'oc get bc test --template={{.spec.strategy.dockerStrategy.from.name}}' 'ruby-22-centos7:latest'

os::cmd::expect_success 'oc new-app -i php-55-centos7:latest --code ./test/testdata/testapp --name test2'
os::cmd::expect_success_and_text 'oc get bc test2 --template={{.spec.strategy.sourceStrategy.from.name}}' 'php-55-centos7:latest'

os::cmd::expect_success 'oc new-app -i php-55-centos7:latest~https://github.com/openshift/ruby-hello-world.git --name test3'
os::cmd::expect_success_and_text 'oc get bc test3 --template={{.spec.strategy.sourceStrategy.from.name}}' 'php-55-centos7:latest'

os::cmd::expect_success 'oc new-app php-55-centos7:latest~https://github.com/openshift/ruby-hello-world.git --name test4'
os::cmd::expect_success_and_text 'oc get bc test4 --template={{.spec.strategy.sourceStrategy.from.name}}' 'php-55-centos7:latest'

os::cmd::expect_success 'oc new-app -i php-55-centos7:latest https://github.com/openshift/ruby-hello-world.git --name test5'
os::cmd::expect_success_and_text 'oc get bc test5 --template={{.spec.strategy.sourceStrategy.from.name}}' 'php-55-centos7:latest'

os::cmd::expect_success 'oc new-app php-55-centos7:latest --code https://github.com/openshift/ruby-hello-world.git --name test6'
os::cmd::expect_success_and_text 'oc get bc test6 --template={{.spec.strategy.sourceStrategy.from.name}}' 'php-55-centos7:latest'

os::cmd::expect_success 'oc new-app https://github.com/openshift/ruby-hello-world.git --name test7'
os::cmd::expect_success_and_text 'oc get bc test7 --template={{.spec.strategy.dockerStrategy.from.name}}' 'ruby-22-centos7:latest'

os::cmd::expect_success 'oc new-app php-55-centos7:latest https://github.com/openshift/ruby-hello-world.git --name test8'
os::cmd::expect_success_and_text 'oc get bc test8 --template={{.spec.strategy.sourceStrategy.from.name}}' 'php-55-centos7:latest'
os::cmd::expect_success 'oc delete project new-app-syntax'

echo "new-app: ok"
os::test::junit::declare_suite_end

0 comments on commit 0b8095d

Please sign in to comment.