Skip to content
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
1 change: 1 addition & 0 deletions examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func TestExampleObjectSchemas(t *testing.T) {
"test-route": &routeapi.Route{},
"test-service": &kapi.Service{},
"test-buildcli": &kapi.List{},
"test-buildcli-beta2": &kapi.List{},
},
"../test/templates/fixtures": {
"crunchydata-pod": nil, // Explicitly fails validation, but should pass transformation
Expand Down
35 changes: 21 additions & 14 deletions examples/sample-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,25 @@ This section covers how to perform all the steps of building, deploying, and upd

8. Confirm the registry is accessible (you may need to run this more than once):

$ curl `osc get service docker-registry --template="{{ .portalIP}}:{{ .port }}"`
$ export DOCKER_REGISTRY=`osc get service docker-registry --template="{{ .portalIP}}:{{ .port }}"`
$ curl $DOCKER_REGISTRY

You should see:

"docker-registry server (dev) (v0.9.0)"


9. Create a new project in OpenShift. This creates a namespace `test` to contain the builds and app that we will generate below.
9. Push builder image to private docker-registry:

$ docker pull openshift/ruby-20-centos7:latest
$ docker tag -f openshift/ruby-20-centos7:latest ${DOCKER_REGISTRY}/test/ruby-20-centos7:latest
$ docker push ${DOCKER_REGISTRY}/test/ruby-20-centos7:latest

10. Create a new project in OpenShift. This creates a namespace `test` to contain the builds and app that we will generate below.

$ openshift ex new-project test --display-name="OpenShift 3 Sample" --description="This is an example project to demonstrate OpenShift v3" --admin=anypassword:test-admin

10. *Optional:* View the OpenShift web console in your browser by browsing to `https://<host>:8444`. Login using the user `test-admin` and any password.
11. *Optional:* View the OpenShift web console in your browser by browsing to `https://<host>:8444`. Login using the user `test-admin` and any password.

* You will need to have the browser accept the certificate at
`https://<host>:8443` before the console can consult the OpenShift
Expand All @@ -199,7 +206,7 @@ This section covers how to perform all the steps of building, deploying, and upd
and run builds.


11. *Optional:* Fork the [ruby sample repository](https://github.com/openshift/ruby-hello-world)
12. *Optional:* Fork the [ruby sample repository](https://github.com/openshift/ruby-hello-world)
to an OpenShift-visible git account that you control, preferably
somewhere that can also reach your OpenShift server with a webhook.
A github.com account is an obvious place for this, but an in-house
Expand All @@ -212,7 +219,7 @@ This section covers how to perform all the steps of building, deploying, and upd
Without your own fork, you can still run the initial build from
OpenShift's public repository, just not a changed build.

12. *Optional:* Add the following webhook under the settings in your new GitHub repository:
13. *Optional:* Add the following webhook under the settings in your new GitHub repository:

$ https://<host>:8443/osapi/v1beta1/buildConfigHooks/ruby-sample-build/secret101/github?namespace=test

Expand All @@ -223,12 +230,12 @@ This section covers how to perform all the steps of building, deploying, and upd
instance as the certificate chain generated is not publicly verified.


13. Edit application-template-stibuild.json which will define the sample application
14. Edit application-template-stibuild.json which will define the sample application

* Update the BuildConfig's sourceURI (git://github.com/openshift/ruby-hello-world.git) to point to your forked repository.
*Note:* You can skip this step if you did not create a forked repository.

14. Submit the application template for processing (generating shared parameters requested in the template)
15. Submit the application template for processing (generating shared parameters requested in the template)
and then request creation of the processed template:

$ osc process -n test -f application-template-stibuild.json | osc create -n test -f -
Expand All @@ -247,13 +254,13 @@ This section covers how to perform all the steps of building, deploying, and upd
Note that no build has actually occurred yet, so at this time there
is no image to deploy and no application to visit.

15. Trigger an initial build of your application
16. Trigger an initial build of your application
* If you setup the GitHub webhook, push a change to app.rb in your ruby sample repository.
* Otherwise you can request a new build by running:

$ osc start-build -n test ruby-sample-build

16. Monitor the builds and wait for the status to go to "complete" (this can take a few minutes):
17. Monitor the builds and wait for the status to go to "complete" (this can take a few minutes):

$ osc get -n test builds

Expand Down Expand Up @@ -283,7 +290,7 @@ This section covers how to perform all the steps of building, deploying, and upd
automatically trigger a deployment of the application, creating a
pod each for the frontend (your Ruby code) and backend.

17. Wait for the application's frontend pod and database pods to be started (this can take a few minutes):
18. Wait for the application's frontend pod and database pods to be started (this can take a few minutes):

$ osc get -n test pods

Expand All @@ -294,7 +301,7 @@ This section covers how to perform all the steps of building, deploying, and upd
1b978f62-605f-11e4-b0db-3c970e3bf0b7 mysql localhost.localdomain/ deploymentConfig=,deploymentID=database,name=database,replicationController=1b960e56-605f-11e4-b0db-3c970e3bf0b7,template=ruby-helloworld-sample Running
4a792f55-605f-11e4-b0db-3c970e3bf0b7 172.30.17.3:5001/openshift/origin-ruby-sample:9477bdb99a409b9c747e699361ae7934fd83bb4092627e2ee35f9f0b0869885b localhost.localdomain/ deploymentConfig=frontend,deploymentID=frontend-1,name=frontend,replicationController=4a749831-605f-11e4-b0db-3c970e3bf0b7,template=ruby-helloworld-sample Running

18. Determine the IP for the frontend service:
19. Determine the IP for the frontend service:

$ osc get -n test services

Expand All @@ -310,7 +317,7 @@ This section covers how to perform all the steps of building, deploying, and upd

*Note:* you can also get this information from the web console.

19. Confirm the application is now accessible via the frontend service on port 5432. Go to http://172.30.17.4:5432 (or whatever IP address was reported above) in your browser if you're running this locally; otherwise you can use curl to see the HTML, or port forward the address to your local workstation to visit it.
20. Confirm the application is now accessible via the frontend service on port 5432. Go to http://172.30.17.4:5432 (or whatever IP address was reported above) in your browser if you're running this locally; otherwise you can use curl to see the HTML, or port forward the address to your local workstation to visit it.

- - -
**VAGRANT USERS:**
Expand All @@ -323,14 +330,14 @@ This section covers how to perform all the steps of building, deploying, and upd

You should see a welcome page and a form that allows you to query and update key/value pairs. The keys are stored in the database container running in the database pod.

20. Make a change to your ruby sample main.html file, commit, and push it via git.
21. Make a change to your ruby sample main.html file, commit, and push it via git.

* If you do not have the webhook enabled, you'll have to manually trigger another build:

$ osc start-build -n test ruby-sample-build


21. Repeat step 16 (waiting for the build to complete). Once the build is complete, refreshing your browser should show your changes.
22. Repeat step 17 (waiting for the build to complete). Once the build is complete, refreshing your browser should show your changes.

Congratulations, you've successfully deployed and updated an application on OpenShift.

Expand Down
2 changes: 2 additions & 0 deletions hack/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,14 @@ openshift ex new-project recreated-project --admin="anypassword:createuser2"
osc describe policybinding master -n recreated-project | grep anypassword:createuser2
echo "ex new-project: ok"

# Test running a router
[ ! "$(openshift ex router | grep 'does not exist')"]
[ "$(openshift ex router -o yaml --credentials="${OPENSHIFTCONFIG}" | grep 'openshift/origin-haproxy-')" ]
openshift ex router --create --credentials="${OPENSHIFTCONFIG}"
[ "$(openshift ex router | grep 'service exists')" ]
echo "ex router: ok"

# Test running a registry
[ ! "$(openshift ex registry | grep 'does not exist')"]
[ "$(openshift ex registry -o yaml --credentials="${OPENSHIFTCONFIG}" | grep 'openshift/origin-docker-registry')" ]
openshift ex registry --create --credentials="${OPENSHIFTCONFIG}"
Expand Down
12 changes: 6 additions & 6 deletions hack/test-end-to-end.sh
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ echo "[INFO] Installing the registry"
# TODO: add --images="${USE_IMAGES}" when the Docker registry is built alongside OpenShift
openshift ex registry --create --credentials="${CERT_DIR}/openshift-registry/.kubeconfig" --mount-host="/tmp/openshift.local.registry" --images='openshift/origin-${component}:latest'

echo "[INFO] Pre-pulling and pushing centos7"
docker pull centos:centos7
echo "[INFO] Pre-pulling and pushing ruby-20-centos7"
docker pull openshift/ruby-20-centos7:latest
# TODO: remove after this becomes part of the build
docker pull openshift/origin-docker-registry
echo "[INFO] Pulled centos7"
echo "[INFO] Pulled ruby-20-centos7"

echo "[INFO] Waiting for Docker registry pod to start"
# TODO: simplify when #4702 is fixed upstream
Expand All @@ -250,9 +250,9 @@ wait_for_url_timed "http://${DOCKER_REGISTRY}" "[INFO] Docker registry says: " $

[ "$(dig @${API_HOST} "docker-registry.default.local." A)" ]

docker tag -f centos:centos7 ${DOCKER_REGISTRY}/cached/centos:centos7
docker push ${DOCKER_REGISTRY}/cached/centos:centos7
echo "[INFO] Pushed centos7"
docker tag -f openshift/ruby-20-centos7:latest ${DOCKER_REGISTRY}/test/ruby-20-centos7:latest
docker push ${DOCKER_REGISTRY}/test/ruby-20-centos7:latest
echo "[INFO] Pushed ruby-20-centos7"

# Process template and create
echo "[INFO] Submitting application template json for processing..."
Expand Down
12 changes: 10 additions & 2 deletions pkg/build/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type BuildParameters struct {
Revision *SourceRevision `json:"revision,omitempty"`

// Strategy defines how to perform a build.
Strategy BuildStrategy `json:"strategy,omitempty"`
Strategy BuildStrategy `json:"strategy"`

// Output describes the Docker image the Strategy should produce.
Output BuildOutput `json:"output,omitempty"`
Expand Down Expand Up @@ -142,7 +142,7 @@ type SourceControlUser struct {
// BuildStrategy contains the details of how to perform a build.
type BuildStrategy struct {
// Type is the kind of build strategy.
Type BuildStrategyType `json:"type,omitempty"`
Type BuildStrategyType `json:"type"`

// DockerStrategy holds the parameters to the Docker build strategy.
DockerStrategy *DockerBuildStrategy `json:"dockerStrategy,omitempty"`
Expand Down Expand Up @@ -209,8 +209,16 @@ type DockerBuildStrategy struct {
// STIBuildStrategy defines input parameters specific to an STI build.
type STIBuildStrategy struct {
// Image is the image used to execute the build.
// Only valid if From is not present.
Image string `json:"image,omitempty"`

// From is reference to an image repository from where the docker image should be pulled
From *kapi.ObjectReference `json:"from,omitempty"`

// Tag is the name of image repository tag to be used as the build image, it only
// applies when From is specified.
Tag string `json:"tag,omitempty`

// Additional environment variables you want to pass into a builder container
Env []kapi.EnvVar `json:"env,omitempty"`

Expand Down
16 changes: 16 additions & 0 deletions pkg/build/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,27 @@ func init() {
func(in *newer.STIBuildStrategy, out *STIBuildStrategy, s conversion.Scope) error {
out.BuilderImage = in.Image
out.Image = in.Image
if in.From != nil {
out.From = &kapi.ObjectReference{
Name: in.From.Name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a ImageRepository reference, can you set the Kind as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set

Namespace: in.From.Namespace,
Kind: "ImageRepository",
}
}
out.Tag = in.Tag
out.Scripts = in.Scripts
out.Clean = !in.Incremental
return s.Convert(&in.Env, &out.Env, 0)
},
func(in *STIBuildStrategy, out *newer.STIBuildStrategy, s conversion.Scope) error {
if in.From != nil {
out.From = &api.ObjectReference{
Name: in.From.Name,
Namespace: in.From.Namespace,
Kind: "ImageRepository",
}
}
out.Tag = in.Tag
out.Scripts = in.Scripts
out.Incremental = !in.Clean
if len(in.Image) != 0 {
Expand Down
6 changes: 6 additions & 0 deletions pkg/build/api/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func TestSTIBuildStrategyConversion(t *testing.T) {
if actual.Image != oldVersion.BuilderImage {
t.Errorf("expected %v, actual %v", oldVersion.BuilderImage, actual.Image)
}
if actual.From != nil {
t.Errorf("expected %v, actual %v", nil, actual.From)
}
if actual.Tag != oldVersion.Tag {
t.Errorf("expected %v, actual %v", oldVersion.Tag, actual.Tag)
}
if actual.Incremental == oldVersion.Clean {
t.Errorf("expected %v, actual %v", oldVersion.Clean, actual.Incremental)
}
Expand Down
13 changes: 11 additions & 2 deletions pkg/build/api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type BuildParameters struct {
Revision *SourceRevision `json:"revision,omitempty"`

// Strategy defines how to perform a build.
Strategy BuildStrategy `json:"strategy,omitempty"`
Strategy BuildStrategy `json:"strategy"`

// Output describes the Docker image the Strategy should produce.
Output BuildOutput `json:"output,omitempty"`
Expand Down Expand Up @@ -142,7 +142,7 @@ type SourceControlUser struct {
// BuildStrategy contains the details of how to perform a build.
type BuildStrategy struct {
// Type is the kind of build strategy.
Type BuildStrategyType `json:"type,omitempty"`
Type BuildStrategyType `json:"type"`

// DockerStrategy holds the parameters to the Docker build strategy.
DockerStrategy *DockerBuildStrategy `json:"dockerStrategy,omitempty"`
Expand Down Expand Up @@ -214,8 +214,17 @@ type STIBuildStrategy struct {
BuilderImage string `json:"builderImage,omitempty"`

// Image is the image used to execute the build.
// For BuildConfigs, From takes precedence.
Image string `json:"image,omitempty"`

// Tag is the name of image repository tag to be used as the build image, it only
// applies when From is specified.
Tag string `json:"tag,omitempty"`

// From is reference to an image repository from where the docker image should be pulled
// Only allowed in BuildConfigs, Builds use the Image field exclusively.
From *kapi.ObjectReference `json:"from,omitempty"`

// Additional environment variables you want to pass into a builder container
Env []kapi.EnvVar `json:"env,omitempty"`

Expand Down
18 changes: 10 additions & 8 deletions pkg/build/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,22 @@ func validateBuildConfigOutput(output *buildapi.BuildOutput) errs.ValidationErro
func validateStrategy(strategy *buildapi.BuildStrategy) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{}

if len(strategy.Type) == 0 {
switch {
case len(strategy.Type) == 0:
allErrs = append(allErrs, errs.NewFieldRequired("type"))
}

switch strategy.Type {
case buildapi.STIBuildStrategyType:
case strategy.Type == buildapi.STIBuildStrategyType:
if strategy.STIStrategy == nil {
allErrs = append(allErrs, errs.NewFieldRequired("stiStrategy"))
} else {
allErrs = append(allErrs, validateSTIStrategy(strategy.STIStrategy).Prefix("stiStrategy")...)
}
case buildapi.DockerBuildStrategyType:
case strategy.Type == buildapi.DockerBuildStrategyType:
// DockerStrategy is currently optional, initialize it to a default state if it's not set.
if strategy.DockerStrategy == nil {
strategy.DockerStrategy = &buildapi.DockerBuildStrategy{}
}
case buildapi.CustomBuildStrategyType:
case strategy.Type == buildapi.CustomBuildStrategyType:
if strategy.CustomStrategy == nil {
allErrs = append(allErrs, errs.NewFieldRequired("customStrategy"))
} else {
Expand All @@ -178,8 +177,11 @@ func validateStrategy(strategy *buildapi.BuildStrategy) errs.ValidationErrorList

func validateSTIStrategy(strategy *buildapi.STIBuildStrategy) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{}
if len(strategy.Image) == 0 {
allErrs = append(allErrs, errs.NewFieldRequired("image"))
if (strategy.From == nil || len(strategy.From.Name) == 0) && len(strategy.Image) == 0 {
allErrs = append(allErrs, errs.NewFieldRequired("from"))
}
if (strategy.From != nil && len(strategy.From.Name) != 0) && len(strategy.Image) != 0 {
allErrs = append(allErrs, errs.NewFieldInvalid("image", strategy.Image, "only one of 'image' and 'from' may be set"))
}
return allErrs
}
Expand Down
Loading