Skip to content

--source-image should count as a source input #18631

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

Merged
merged 1 commit into from
Feb 18, 2018
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions pkg/oc/generate/cmd/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,38 @@ func Resolve(appConfig *AppConfig) (*ResolvedComponents, error) {
if err := AddComponentInputsToRefBuilder(b, r, c, g, s, i); err != nil {
return nil, err
}

components, repositories, errs := b.Result()
if len(errs) > 0 {
return nil, kutilerrors.NewAggregate(errs)
}

// Add source components if source-image points to another location
// TODO: image sources aren't really "source repositories" and we should probably find another way to
// represent them
imageComp, repositories, err := AddImageSourceRepository(repositories, r.ImageSourceResolver(), g)
if err != nil {
return nil, err
}

// TODO: the second half of this method is potentially splittable - each chunk below amends or qualifies
// the inputs provided by the user (mostly via flags). c is cleared to prevent it from being used accidentally.
c = nil

// set context dir on all repositories
for _, repo := range repositories {
repo.SetContextDir(g.ContextDir)
// if the --context-dir flag was passed, set the context directory on all repositories
if len(g.ContextDir) > 0 && len(repositories) > 0 {
glog.V(5).Infof("Setting contextDir on all repositories to %v", g.ContextDir)
for _, repo := range repositories {
repo.SetContextDir(g.ContextDir)
}
}

// if the --strategy flag was passed, set the build strategy on all repositories
if g.Strategy != generate.StrategyUnspecified && len(repositories) > 0 {
glog.V(5).Infof("Setting build strategy on all repositories to %v", g.Strategy)
for _, repo := range repositories {
repo.SetStrategy(g.Strategy)
}
}

if g.Strategy != generate.StrategyUnspecified && len(repositories) == 0 && !g.BinaryBuild {
Expand All @@ -129,15 +149,6 @@ func Resolve(appConfig *AppConfig) (*ResolvedComponents, error) {
return nil, errors.New("specifying binary builds and source repositories at the same time is not allowed")
}

// Add source components if source-image points to another location
// TODO: image sources aren't really "source repositories" and we should probably find another way to
// represent them
var err error
var imageComp app.ComponentReference
imageComp, repositories, err = AddImageSourceRepository(repositories, r.ImageSourceResolver(), g)
if err != nil {
return nil, err
}
componentsIncludingImageComps := components
if imageComp != nil {
componentsIncludingImageComps = append(components, imageComp)
Expand Down
13 changes: 13 additions & 0 deletions test/cmd/newapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,19 @@ 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'

# ensure that --strategy sets the build strategy
os::cmd::expect_success_and_text 'oc new-build --name sourcetest python~https://github.com/sclorg/django-ex --source-image centos:latest --source-image-path /tmp --strategy source --dry-run -o yaml' 'sourceStrategy'
os::cmd::expect_success_and_text 'oc new-build --name sourcetest python~https://github.com/sclorg/django-ex --source-image centos:latest --source-image-path /tmp --strategy pipeline --dry-run -o yaml' 'jenkinsPipelineStrategy'
os::cmd::expect_success_and_text 'oc new-build --name sourcetest python~https://github.com/sclorg/django-ex --source-image centos:latest --source-image-path /tmp --strategy docker --dry-run -o yaml' 'dockerStrategy'

os::cmd::expect_success 'oc create -f examples/image-streams/image-streams-centos7.json'
os::cmd::try_until_success 'oc get imagestreamtags nodejs:latest'
# ensure that a build can be created with just image inputs without the --binary flag
os::cmd::expect_success_and_text 'oc new-build --name sourcetest --source-image centos:latest --source-image-path /tmp --image-stream nodejs --dry-run -o yaml' 'sourceStrategy'
# ensure that using only image inputs and the --binary flag results in an error
os::cmd::expect_failure_and_text 'oc new-build --name sourcetest --source-image centos:latest --source-image-path /tmp --image-stream nodejs --binary --dry-run -o yaml' 'specifying binary builds and source repositories at the same time is not allowed'
os::cmd::expect_success 'oc delete imagestreams --all --ignore-not-found'

# 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'
Expand Down