Skip to content

Commit

Permalink
oc new-build --push-secret option
Browse files Browse the repository at this point in the history
  • Loading branch information
damemi committed Feb 6, 2018
1 parent 8ca3f60 commit 47b8fa7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/oc/cli/cmd/newbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func NewCmdNewBuild(name, baseName string, f *clientcmd.Factory, in io.Reader, o
cmd.Flags().StringSliceVar(&config.DockerImages, "docker-image", config.DockerImages, "Name of a Docker image to use as a builder.")
cmd.Flags().StringSliceVar(&config.Secrets, "build-secret", config.Secrets, "Secret and destination to use as an input for the build.")
cmd.Flags().StringVar(&config.SourceSecret, "source-secret", "", "The name of an existing secret that should be used for cloning a private git repository.")
cmd.Flags().StringVar(&config.PushSecret, "push-secret", "", "The name of an existing secret that should be used for pushing to a Docker repository if --to-docker and --to are set.")
cmd.Flags().StringVar(&config.Name, "name", "", "Set name to use for generated build artifacts.")
cmd.Flags().StringVar(&config.To, "to", "", "Push built images to this image stream tag (or Docker image repository if --to-docker is set).")
cmd.Flags().BoolVar(&config.OutputDocker, "to-docker", false, "If true, have the build output push to a Docker repository.")
Expand Down
10 changes: 10 additions & 0 deletions pkg/oc/generate/cmd/newapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type AppConfig struct {

AllowSecretUse bool
SourceSecret string
PushSecret string
AllowNonNumericExposedPorts bool
SecretAccessor app.SecretAccessor

Expand Down Expand Up @@ -906,6 +907,15 @@ func (c *AppConfig) Run() (*AppResult, error) {
}
}
}
if len(c.PushSecret) > 0 {
for _, obj := range objects {
if bc, ok := obj.(*buildapi.BuildConfig); ok {
glog.V(4).Infof("Setting push secret for build config to: %v", c.SourceSecret)
bc.Spec.Output.PushSecret = &kapi.LocalObjectReference{Name: c.PushSecret}
break
}
}
}

return &AppResult{
List: &kapi.List{Items: objects},
Expand Down
2 changes: 2 additions & 0 deletions test/cmd/newapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ os::cmd::expect_success_and_text 'oc new-build https://github.com/openshift/cake
os::cmd::expect_success_and_text 'oc new-app -f examples/quickstarts/cakephp-mysql.json --source-secret=mysecret -o yaml' 'name: mysecret'
os::cmd::expect_success 'oc new-app https://github.com/openshift/cakephp-ex --source-secret=mysecret'
os::cmd::expect_success 'oc delete all --selector="label=cakephp-ex"'
# setting push secret via the --push-secret flag
os::cmd::expect_success_and_text 'oc new-build https://github.com/openshift/cakephp-ex --push-secret=mynewsecret -o yaml' 'name: mynewsecret'


# check label creation
Expand Down

0 comments on commit 47b8fa7

Please sign in to comment.