diff --git a/examples/examples_test.go b/examples/examples_test.go index 0bb6c15b84bc..e77ee1f10213 100644 --- a/examples/examples_test.go +++ b/examples/examples_test.go @@ -73,9 +73,8 @@ func TestExampleObjectSchemas(t *testing.T) { "application-template-custombuild": &templateapi.Template{}, }, "../examples/jenkins": { - "jenkins-config": &configapi.Config{}, - "docker-registry-config": &configapi.Config{}, - "application-template": &templateapi.Template{}, + "jenkins-config": &configapi.Config{}, + "application-template": &templateapi.Template{}, }, "../examples/image-repositories": { "image-repositories": &imageapi.ImageRepositoryList{}, diff --git a/examples/jenkins/README.md b/examples/jenkins/README.md index d79c26ccbc13..dd919b8b841b 100755 --- a/examples/jenkins/README.md +++ b/examples/jenkins/README.md @@ -10,51 +10,39 @@ the deployment works, and then tag the test version into production. Steps ----- -1. Start OpenShift - - $ sudo openshift start &> logs/openshift.log & - -2. Start the docker registry services - - $ osc create -f docker-registry-config.json +1. Follow steps 1-10 from the [sample-app](https://github.com/openshift/origin/blob/master/examples/sample-app/README.md) -3. Start the Jenkins services +2. Start the Jenkins services - $ osc create -f jenkins-config.json - -4. Determine the IP address of the docker-registry service: - - $ osc get services docker-registry -o template --template="{{ .portalIP }}" + $ osc create -n test -f jenkins-config.json -5. Edit the application-template.json file by replacing all occurences of `172.30.17.3` with the IP address from the previous step. - -5. Create the application configuration +3. Create the application configuration - $ osc process -f application-template.json | osc create -f - + $ osc process -n test -f application-template.json | osc create -n test -f - -6. Locate the Jenkins service endpoint and go to it in your browser: +4. Locate the Jenkins service endpoint and go to it in your browser: - $ osc get services | grep jenkins | awk '{print $4":"$5}' + $ osc get services -n test | grep jenkins | awk '{print $4":"$5}' Once it is available, proceed to the next step. -7. Create the Jenkins job named rubyJob: +5. Create the Jenkins job named rubyJob: - $ JENKINS_ENDPOINT=`osc get services | grep jenkins | awk '{print $4":"$5}'` + $ JENKINS_ENDPOINT=`osc get services -n test | grep jenkins | awk '{print $4":"$5}'` $ cat job.xml | curl -X POST -H "Content-Type: application/xml" -H "Expect: " --data-binary @- http://$JENKINS_ENDPOINT/createItem?name=rubyJob -8. Run the Jenkins build +6. Run the Jenkins build Go back to your browser, refresh and select the rubyJob build job and choose `Build with parameters`. You should not need to modify the `OPENSHIFT_HOST`. -9. Watch the job output +7. Watch the job output It will trigger an OpenShift build of the application, wait for the build to result in a deployment, confirm the new deployment works, and re-tag the image for production. This re-tagging will trigger another deployment, this time creating/updated the production service. -10. Confirm both the test and production services are available by browsing to both services: +8. Confirm both the test and production services are available by browsing to both services: - $ osc get services | grep frontend + $ osc get services -n test | grep frontend diff --git a/examples/jenkins/application-template.json b/examples/jenkins/application-template.json index a171a30be64e..ceadd23ec8d9 100644 --- a/examples/jenkins/application-template.json +++ b/examples/jenkins/application-template.json @@ -1,394 +1,397 @@ { - "annotations": { - "description": "This example shows how to create a simple ruby application in openshift origin v3" - }, - "apiVersion": "v1beta1", - "items": [ - { - "apiVersion": "v1beta1", - "kind": "BuildConfig", - "metadata": { - "labels": { - "name": "ruby-test-build" - }, - "name": "ruby-test-build" - }, - "parameters": { - "output": { - "imageTag": "openshift/origin-ruby-sample:test", - "registry": "172.30.17.3:5001" - }, - "source": { - "git": { - "uri": "git://github.com/openshift/ruby-hello-world.git" - }, - "type": "Git" + "annotations": { + "description": "This example shows how to create a simple ruby application in openshift origin v3" + }, + "apiVersion": "v1beta1", + "items": [ + { + "apiVersion": "v1beta1", + "kind": "ImageRepository", + "metadata": { + "name": "origin-ruby-sample" + } }, - "strategy": { - "stiStrategy": { - "image": "openshift/ruby-20-centos" - }, - "type": "STI" - } - }, - "triggers": [ { - "github": { - "secret": "secret101" - }, - "type": "github" + "apiVersion": "v1beta1", + "kind": "BuildConfig", + "metadata": { + "labels": { + "name": "ruby-test-build" + }, + "name": "ruby-test-build" + }, + "parameters": { + "output": { + "tag": "test", + "to": { + "name": "origin-ruby-sample" + } + }, + "source": { + "git": { + "uri": "git://github.com/openshift/ruby-hello-world.git" + }, + "type": "Git" + }, + "strategy": { + "stiStrategy": { + "image": "openshift/ruby-20-centos" + }, + "type": "STI" + } + }, + "triggers": [ + { + "github": { + "secret": "secret101" + }, + "type": "github" + }, + { + "generic": { + "secret": "secret101" + }, + "type": "generic" + } + ] }, { - "generic": { - "secret": "secret101" - }, - "type": "generic" - } - ] - }, - { - "apiVersion": "v1beta1", - "dockerImageRepository": "172.30.17.3:5001/openshift/origin-ruby-sample", - "kind": "ImageRepository", - "metadata": { - "labels": { - "name": "origin-ruby-sample" + "apiVersion": "v1beta2", + "containerPort": 8080, + "id": "frontend-prod", + "kind": "Service", + "name": "origin-ruby-sample", + "port": 5432, + "selector": { + "name": "frontend-prod" + } }, - "name": "origin-ruby-sample" - } - }, - { - "apiVersion": "v1beta2", - "containerPort": 8080, - "id": "frontend-prod", - "kind": "Service", - "port": 5432, - "selector": { - "name": "frontend-prod" - } - }, - { - "apiVersion": "v1beta1", - "kind": "DeploymentConfig", - "metadata": { - "name": "frontend-prod" - }, - "template": { - "controllerTemplate": { - "podTemplate": { - "desiredState": { - "manifest": { - "containers": [ - { - "env": [ - { - "name": "ADMIN_USERNAME", - "value": "${ADMIN_USERNAME}" - }, - { - "name": "ADMIN_PASSWORD", - "value": "${ADMIN_PASSWORD}" - }, - { - "name": "MYSQL_ROOT_PASSWORD", - "value": "${MYSQL_ROOT_PASSWORD}" - }, - { - "name": "MYSQL_DATABASE", - "value": "${MYSQL_DATABASE}" - }, - { - "name": "RACK_ENV", - "value": "production" - }, - { - "name": "RAILS_ENV", - "value": "production" - } - ], - "image": "172.30.17.3:5001/openshift/origin-ruby-sample:prod", - "name": "ruby-helloworld-prod", - "ports": [ - { - "containerPort": 8080 - } - ] - } - ], - "version": "v1beta1" - } + { + "apiVersion": "v1beta1", + "kind": "DeploymentConfig", + "metadata": { + "name": "frontend-prod" + }, + "template": { + "controllerTemplate": { + "podTemplate": { + "desiredState": { + "manifest": { + "containers": [ + { + "env": [ + { + "name": "ADMIN_USERNAME", + "value": "${ADMIN_USERNAME}" + }, + { + "name": "ADMIN_PASSWORD", + "value": "${ADMIN_PASSWORD}" + }, + { + "name": "MYSQL_ROOT_PASSWORD", + "value": "${MYSQL_ROOT_PASSWORD}" + }, + { + "name": "MYSQL_DATABASE", + "value": "${MYSQL_DATABASE}" + }, + { + "name": "RACK_ENV", + "value": "production" + }, + { + "name": "RAILS_ENV", + "value": "production" + } + ], + "image": "origin-ruby-sample", + "name": "ruby-helloworld-prod", + "ports": [ + { + "containerPort": 8080 + } + ] + } + ], + "version": "v1beta1" + } + }, + "labels": { + "name": "frontend-prod" + } + }, + "replicaSelector": { + "name": "frontend-prod" + }, + "replicas": 1 + }, + "strategy": { + "type": "Recreate" + } }, - "labels": { - "name": "frontend-prod" + "triggers": [ + { + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "ruby-helloworld-prod" + ], + "from": { + "name": "origin-ruby-sample" + }, + "tag": "prod" + }, + "type": "ImageChange" + } + ] + }, + { + "apiVersion": "v1beta2", + "containerPort": 3306, + "id": "database", + "kind": "Service", + "port": 5434, + "selector": { + "name": "database-prod" } - }, - "replicaSelector": { - "name": "frontend-prod" - }, - "replicas": 1 }, - "strategy": { - "type": "Recreate" - } - }, - "triggers": [ { - "imageChangeParams": { - "automatic": true, - "containerNames": [ - "ruby-helloworld-prod" - ], - "repositoryName": "172.30.17.3:5001/openshift/origin-ruby-sample", - "tag": "prod" - }, - "type": "ImageChange" - } - ] - }, - { - "apiVersion": "v1beta2", - "containerPort": 3306, - "id": "database", - "kind": "Service", - "port": 5434, - "selector": { - "name": "database-prod" - } - }, - { - "apiVersion": "v1beta1", - "kind": "DeploymentConfig", - "metadata": { - "name": "database-prod" - }, - "template": { - "controllerTemplate": { - "podTemplate": { - "desiredState": { - "manifest": { - "containers": [ - { - "env": [ - { - "name": "MYSQL_ROOT_PASSWORD", - "value": "${MYSQL_ROOT_PASSWORD}" - }, - { - "name": "MYSQL_DATABASE", - "value": "${MYSQL_DATABASE}" - } - ], - "image": "mysql", - "name": "ruby-helloworld-database", - "ports": [ - { - "containerPort": 3306 - } - ] - } - ], - "version": "v1beta1" - } + "apiVersion": "v1beta1", + "kind": "DeploymentConfig", + "metadata": { + "name": "database-prod" }, - "labels": { - "name": "database-prod" + "template": { + "controllerTemplate": { + "podTemplate": { + "desiredState": { + "manifest": { + "containers": [ + { + "env": [ + { + "name": "MYSQL_ROOT_PASSWORD", + "value": "${MYSQL_ROOT_PASSWORD}" + }, + { + "name": "MYSQL_DATABASE", + "value": "${MYSQL_DATABASE}" + } + ], + "image": "mysql", + "name": "ruby-helloworld-database", + "ports": [ + { + "containerPort": 3306 + } + ] + } + ], + "version": "v1beta1" + } + }, + "labels": { + "name": "database-prod" + } + }, + "replicaSelector": { + "name": "database-prod" + }, + "replicas": 1 + }, + "strategy": { + "type": "Recreate" + } + }, + "triggers": [ + { + "type": "ConfigChange" + } + ] + }, + { + "apiVersion": "v1beta2", + "containerPort": 8080, + "id": "frontend-test", + "kind": "Service", + "port": 5432, + "selector": { + "name": "frontend-test" } - }, - "replicaSelector": { - "name": "database-prod" - }, - "replicas": 1 }, - "strategy": { - "type": "Recreate" - } - }, - "triggers": [ { - "type": "ConfigChange" - } - ] - }, - { - "apiVersion": "v1beta2", - "containerPort": 8080, - "id": "frontend-test", - "kind": "Service", - "port": 5432, - "selector": { - "name": "frontend-test" - } - }, - { - "apiVersion": "v1beta1", - "kind": "DeploymentConfig", - "metadata": { - "name": "frontend-test" - }, - "template": { - "controllerTemplate": { - "podTemplate": { - "desiredState": { - "manifest": { - "containers": [ - { - "env": [ - { - "name": "ADMIN_USERNAME", - "value": "${ADMIN_USERNAME}" - }, - { - "name": "ADMIN_PASSWORD", - "value": "${ADMIN_PASSWORD}" - }, - { - "name": "MYSQL_ROOT_PASSWORD", - "value": "${MYSQL_ROOT_PASSWORD}" - }, - { - "name": "MYSQL_DATABASE", - "value": "${MYSQL_DATABASE}" - }, - { - "name": "RACK_ENV", - "value": "test" - }, - { - "name": "RAILS_ENV", - "value": "test" - } - ], - "image": "172.30.17.3:5001/openshift/origin-ruby-sample:test", - "name": "ruby-helloworld-test", - "ports": [ - { - "containerPort": 8080 - } - ] - } - ], - "version": "v1beta1" - } + "apiVersion": "v1beta1", + "kind": "DeploymentConfig", + "metadata": { + "name": "frontend-test" + }, + "template": { + "controllerTemplate": { + "podTemplate": { + "desiredState": { + "manifest": { + "containers": [ + { + "env": [ + { + "name": "ADMIN_USERNAME", + "value": "${ADMIN_USERNAME}" + }, + { + "name": "ADMIN_PASSWORD", + "value": "${ADMIN_PASSWORD}" + }, + { + "name": "MYSQL_ROOT_PASSWORD", + "value": "${MYSQL_ROOT_PASSWORD}" + }, + { + "name": "MYSQL_DATABASE", + "value": "${MYSQL_DATABASE}" + }, + { + "name": "RACK_ENV", + "value": "test" + }, + { + "name": "RAILS_ENV", + "value": "test" + } + ], + "image": "origin-ruby-sample", + "name": "ruby-helloworld-test", + "ports": [ + { + "containerPort": 8080 + } + ] + } + ], + "version": "v1beta1" + } + }, + "labels": { + "name": "frontend-test" + } + }, + "replicaSelector": { + "name": "frontend-test" + }, + "replicas": 1 + }, + "strategy": { + "type": "Recreate" + } }, - "labels": { - "name": "frontend-test" + "triggers": [ + { + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "ruby-helloworld-test" + ], + "from": { + "name": "origin-ruby-sample" + }, + "tag": "test" + }, + "type": "ImageChange" + } + ] + }, + { + "apiVersion": "v1beta2", + "containerPort": 3306, + "id": "database-test", + "kind": "Service", + "port": 6434, + "selector": { + "name": "database-test" } - }, - "replicaSelector": { - "name": "frontend-test" - }, - "replicas": 1 }, - "strategy": { - "type": "Recreate" - } - }, - "triggers": [ { - "imageChangeParams": { - "automatic": true, - "containerNames": [ - "ruby-helloworld-test" - ], - "repositoryName": "172.30.17.3:5001/openshift/origin-ruby-sample", - "tag": "test" - }, - "type": "ImageChange" + "apiVersion": "v1beta1", + "kind": "DeploymentConfig", + "metadata": { + "name": "database-test" + }, + "template": { + "controllerTemplate": { + "podTemplate": { + "desiredState": { + "manifest": { + "containers": [ + { + "env": [ + { + "name": "MYSQL_ROOT_PASSWORD", + "value": "${MYSQL_ROOT_PASSWORD}" + }, + { + "name": "MYSQL_DATABASE", + "value": "${MYSQL_DATABASE}" + } + ], + "image": "mysql", + "name": "ruby-helloworld-database", + "ports": [ + { + "containerPort": 3306 + } + ] + } + ], + "version": "v1beta1" + } + }, + "labels": { + "name": "database-test" + } + }, + "replicaSelector": { + "name": "database-test" + }, + "replicas": 1 + }, + "strategy": { + "type": "Recreate" + } + }, + "triggers": [ + { + "type": "ConfigChange" + } + ] } - ] - }, - { - "apiVersion": "v1beta2", - "containerPort": 3306, - "id": "database-test", - "kind": "Service", - "port": 6434, - "selector": { - "name": "database-test" - } + ], + "kind": "Template", + "metadata": { + "name": "ruby-helloworld-sample" }, - { - "apiVersion": "v1beta1", - "kind": "DeploymentConfig", - "metadata": { - "name": "database-test" - }, - "template": { - "controllerTemplate": { - "podTemplate": { - "desiredState": { - "manifest": { - "containers": [ - { - "env": [ - { - "name": "MYSQL_ROOT_PASSWORD", - "value": "${MYSQL_ROOT_PASSWORD}" - }, - { - "name": "MYSQL_DATABASE", - "value": "${MYSQL_DATABASE}" - } - ], - "image": "mysql", - "name": "ruby-helloworld-database", - "ports": [ - { - "containerPort": 3306 - } - ] - } - ], - "version": "v1beta1" - } - }, - "labels": { - "name": "database-test" - } - }, - "replicaSelector": { - "name": "database-test" - }, - "replicas": 1 + "parameters": [ + { + "description": "administrator username", + "from": "admin[A-Z0-9]{3}", + "generate": "expression", + "name": "ADMIN_USERNAME" + }, + { + "description": "administrator password", + "from": "[a-zA-Z0-9]{8}", + "generate": "expression", + "name": "ADMIN_PASSWORD" }, - "strategy": { - "type": "Recreate" - } - }, - "triggers": [ { - "type": "ConfigChange" + "description": "database password", + "from": "[a-zA-Z0-9]{8}", + "generate": "expression", + "name": "MYSQL_ROOT_PASSWORD" + }, + { + "description": "database name", + "name": "MYSQL_DATABASE", + "value": "root" } - ] - } - ], - "kind": "Template", - "metadata": { - "name": "ruby-helloworld-sample" - }, - "parameters": [ - { - "description": "administrator username", - "from": "admin[A-Z0-9]{3}", - "generate": "expression", - "name": "ADMIN_USERNAME" - }, - { - "description": "administrator password", - "from": "[a-zA-Z0-9]{8}", - "generate": "expression", - "name": "ADMIN_PASSWORD" - }, - { - "description": "database password", - "from": "[a-zA-Z0-9]{8}", - "generate": "expression", - "name": "MYSQL_ROOT_PASSWORD" - }, - { - "description": "database name", - "name": "MYSQL_DATABASE", - "value": "root" - } - ] + ] } diff --git a/examples/jenkins/docker-registry-config.json b/examples/jenkins/docker-registry-config.json deleted file mode 100644 index 3cd851c821fe..000000000000 --- a/examples/jenkins/docker-registry-config.json +++ /dev/null @@ -1,96 +0,0 @@ -{ - "apiVersion": "v1beta1", - "creationTimestamp": "2014-09-18T18:28:38-04:00", - "items": [ - { - "apiVersion": "v1beta2", - "containerPort": 5000, - "creationTimestamp": null, - "id": "docker-registry", - "kind": "Service", - "port": 5001, - "selector": { - "name": "registrypod" - } - }, - { - "apiVersion": "v1beta1", - "kind": "DeploymentConfig", - "metadata": { - "name": "docker-registry" - }, - "template": { - "controllerTemplate": { - "podTemplate": { - "desiredState": { - "manifest": { - "containers": [ - { - "command": [ - "sh", - "-c", - "REGISTRY_URL=${DOCKER_REGISTRY_SERVICE_HOST}:${DOCKER_REGISTRY_SERVICE_PORT} OPENSHIFT_URL=https://${KUBERNETES_SERVICE_HOST}:443/osapi/v1beta1 OPENSHIFT_INSECURE=true exec docker-registry" - ], - "env": [ - { - "name": "STORAGE_PATH", - "value": "/tmp/openshift.local.registry" - } - ], - "image": "openshift/docker-registry", - "imagePullPolicy": "PullIfNotPresent", - "name": "registry-container", - "ports": [ - { - "containerPort": 5000, - "protocol": "TCP" - } - ], - "volumeMounts": [ - { - "mountPath": "/tmp/openshift.local.registry", - "name": "registry-storage", - "readOnly": false - } - ] - } - ], - "version": "v1beta1", - "volumes": [ - { - "name": "registry-storage", - "source": { - "hostDir": { - "path": "/tmp/openshift.local.registry" - } - } - } - ] - }, - "restartpolicy": {} - }, - "labels": { - "name": "registrypod" - } - }, - "replicaSelector": { - "name": "registrypod" - }, - "replicas": 1 - }, - "strategy": { - "type": "Recreate" - } - }, - "triggers": [ - { - "type": "ConfigChange" - } - ] - } - ], - "kind": "Config", - "metadata": { - "name": "docker-registry" - } -} diff --git a/examples/jenkins/job.xml b/examples/jenkins/job.xml index 98fff1e000c7..78bc693505ec 100644 --- a/examples/jenkins/job.xml +++ b/examples/jenkins/job.xml @@ -24,25 +24,32 @@ -TEST_ENDPOINT=`openshift kubectl get services -s $OPENSHIFT_HOST| grep frontend-test | awk '{print $4":"$5}'` +osc="osc --insecure-skip-tls-verify=true --server=$OPENSHIFT_HOST" -REGISTRY_ENDPOINT=`openshift kubectl get services -s $OPENSHIFT_HOST| grep docker-registry | awk '{print $3":"$4}'` +TEST_ENDPOINT=`$osc get services -n test | grep frontend-test | awk '{print $4":"$5}'` + +REGISTRY_ENDPOINT=`$osc get services | grep docker-registry | awk '{print $4":"$5}'` # clean up existing test deployment set +e -echo "Removing old test deployment" -TEST_RC_ID=`openshift kubectl get replicationController -s $OPENSHIFT_HOST | grep frontend-test | awk '{print $1}'` -openshift kubectl delete replicationController $TEST_RC_ID -s $OPENSHIFT_HOST -TEST_POD_ID=`openshift kubectl get pod -s $OPENSHIFT_HOST | grep frontend-test | awk '{print $1}'` -openshift kubectl delete pod $TEST_POD_ID -s $OPENSHIFT_HOST +echo "Removing old test deployment" +TEST_RC_ID=`$osc get -n test replicationController | grep frontend-test | awk '{print $1}'` +if [ ! -z $TEST_RC_ID ]; then + $osc delete -n test replicationController $TEST_RC_ID +fi + +TEST_POD_ID=`$osc get pod -n test | grep frontend-test | awk '{print $1}'` +if [ ! -z $TEST_POD_ID ]; then + $osc delete pod -n test $TEST_POD_ID +fi set -e # wait for old pod to be torn down sleep 5 # trigger a build -echo "Triggering new application build and deployment" -openshift kubectl start-build ruby-test-build -s $OPENSHIFT_HOST +echo "Triggering new application build and deployment" +$osc start-build -n test ruby-test-build # check that the build test image deployed successfully set +e @@ -50,29 +57,29 @@ rc=1 count=0 attempts=100 -echo "Checking test deployment at $TEST_ENDPOINT" +echo "Checking test deployment at $TEST_ENDPOINT" while [ $rc -ne 0 -a $count -lt $attempts ]; do curl -s --connect-timeout 2 $TEST_ENDPOINT rc=$? if [ $rc -ne 0 ]; then count=$(($count+1)) - echo "Attempt $count/$attempts" + echo "Attempt $count/$attempts" sleep 5 fi done set -e if [ $count -eq $attempts ]; then - echo "Failed to reach test deployment" + echo "Failed to reach test deployment" exit 1 fi # Tag the image into production -echo "Test deployment succeeded, rolling out to production..." +echo "Test deployment succeeded, rolling out to production..." -COMMIT=`curl -s http://$REGISTRY_ENDPOINT/v1/repositories/openshift/origin-ruby-sample/tags/test` -curl -s -X PUT http://$REGISTRY_ENDPOINT/v1/repositories/openshift/origin-ruby-sample/tags/prod -d "$COMMIT" +COMMIT=`curl -s http://$REGISTRY_ENDPOINT/v1/repositories/test/origin-ruby-sample/tags/test` +curl -s -X PUT http://$REGISTRY_ENDPOINT/v1/repositories/test/origin-ruby-sample/tags/prod -d "$COMMIT" diff --git a/pkg/build/controller/controller.go b/pkg/build/controller/controller.go index a3ce54a97961..6e69a1bd68e6 100644 --- a/pkg/build/controller/controller.go +++ b/pkg/build/controller/controller.go @@ -96,7 +96,11 @@ func (bc *BuildController) nextBuildStatus(build *buildapi.Build) error { } return fmt.Errorf("the referenced output repo %s/%s could not be found by %s/%s: %v", namespace, ref.Name, build.Namespace, build.Name, err) } - spec = repo.Status.DockerImageRepository + if len(build.Parameters.Output.Tag) == 0 { + spec = repo.Status.DockerImageRepository + } else { + spec = fmt.Sprintf("%s:%s", repo.Status.DockerImageRepository, build.Parameters.Output.Tag) + } } // set the expected build parameters, which will be saved if no error occurs @@ -104,12 +108,13 @@ func (bc *BuildController) nextBuildStatus(build *buildapi.Build) error { build.PodName = fmt.Sprintf("build-%s", build.Name) // override DockerImageReference in the strategy for the copy we send to the server + build.Parameters.Output.DockerImageReference = spec + copy, err := kapi.Scheme.Copy(build) if err != nil { return fmt.Errorf("unable to copy build: %v", err) } buildCopy := copy.(*buildapi.Build) - buildCopy.Parameters.Output.DockerImageReference = spec // invoke the strategy to get a build pod podSpec, err := bc.BuildStrategy.CreateBuildPod(buildCopy) diff --git a/test/integration/deploy_trigger_test.go b/test/integration/deploy_trigger_test.go index 2b442b40f230..23942fb80893 100644 --- a/test/integration/deploy_trigger_test.go +++ b/test/integration/deploy_trigger_test.go @@ -23,6 +23,7 @@ import ( "github.com/openshift/origin/pkg/api/v1beta1" buildclient "github.com/openshift/origin/pkg/build/client" buildcontrollerfactory "github.com/openshift/origin/pkg/build/controller/factory" + buildstrategy "github.com/openshift/origin/pkg/build/controller/strategy" buildregistry "github.com/openshift/origin/pkg/build/registry/build" buildconfigregistry "github.com/openshift/origin/pkg/build/registry/buildconfig" buildetcd "github.com/openshift/origin/pkg/build/registry/etcd" @@ -403,9 +404,26 @@ func NewTestOpenshift(t *testing.T) *testOpenshift { BuildCreator: buildclient.NewOSClientBuildClient(osClient), Stop: openshift.stop, } - biccFactory.Create().Run() + bcFactory := buildcontrollerfactory.BuildControllerFactory{ + OSClient: osClient, + KubeClient: kubeClient, + BuildUpdater: buildclient.NewOSClientBuildClient(osClient), + DockerBuildStrategy: &buildstrategy.DockerBuildStrategy{ + Image: "test-docker-builder", + Codec: latest.Codec, + }, + STIBuildStrategy: &buildstrategy.STIBuildStrategy{ + Image: "test-sti-builder", + TempDirectoryCreator: buildstrategy.STITempDirectoryCreator, + Codec: latest.Codec, + }, + Stop: openshift.stop, + } + + bcFactory.Create().Run() + return openshift } diff --git a/test/integration/imagechange_buildtrigger_test.go b/test/integration/imagechange_buildtrigger_test.go index d94a972b386a..fcaa37cea92e 100644 --- a/test/integration/imagechange_buildtrigger_test.go +++ b/test/integration/imagechange_buildtrigger_test.go @@ -69,6 +69,18 @@ func TestSimpleImageChangeBuildTrigger(t *testing.T) { t.Fatalf("Expected build with base image %s, got %s", "registry:8080/openshift/test-image-trigger:ref-2", newBuild.Parameters.Strategy.DockerStrategy.Image) } + event = <-watch.ResultChan() + if e, a := watchapi.Modified, event.Type; e != a { + t.Fatalf("expected watch event type %s, got %s", e, a) + } + newBuild = event.Object.(*buildapi.Build) + if newBuild.Parameters.Output.DockerImageReference != "registry:8080/openshift/test-image-trigger:outputtag" { + t.Fatalf("Expected build with output image %s, got %s", "registry:8080/openshift/test-image-trigger:outputtag", newBuild.Parameters.Output.DockerImageReference) + } + if newBuild.Labels["testlabel"] != "testvalue" { + t.Fatalf("Expected build with label %s=%s from build config got %s=%s", "testlabel", "testvalue", "testlabel", newBuild.Labels["testlabel"]) + } + event = <-watch2.ResultChan() event = <-watch2.ResultChan() @@ -84,7 +96,8 @@ func TestSimpleImageChangeBuildTrigger(t *testing.T) { func imageChangeBuildConfig() *buildapi.BuildConfig { buildcfg := &buildapi.BuildConfig{ ObjectMeta: kapi.ObjectMeta{ - Name: "test-build-cfg", + Name: "test-build-cfg", + Labels: map[string]string{"testlabel": "testvalue"}, }, Parameters: buildapi.BuildParameters{ Source: buildapi.BuildSource{ @@ -101,7 +114,10 @@ func imageChangeBuildConfig() *buildapi.BuildConfig { }, }, Output: buildapi.BuildOutput{ - DockerImageReference: "foo:tag", + To: &kapi.ObjectReference{ + Name: "test-image-trigger-repo", + }, + Tag: "outputtag", }, }, Triggers: []buildapi.BuildTriggerPolicy{