| ... | ... |
@@ -8,21 +8,22 @@ To do this, run: |
| 8 | 8 |
|
| 9 | 9 |
This will: |
| 10 | 10 |
|
| 11 |
-1. Launch the openshift server |
|
| 11 |
+1. Launch the OpenShift server |
|
| 12 | 12 |
* Logs are available in logs/openshift.log |
| 13 | 13 |
|
| 14 |
-2. Submit the template/template.json for parameterization |
|
| 14 |
+2. Create a private Docker registry running in OpenShift |
|
| 15 | 15 |
|
| 16 |
-3. Store the resulting config json in processed/template.processed.json |
|
| 16 |
+3. Define a build configuration for the application |
|
| 17 | 17 |
|
| 18 |
-4. Submit the config json to openshift for creation |
|
| 18 |
+4. Trigger a new build of the application |
|
| 19 | 19 |
|
| 20 |
-5. Confirm the application is created/accessible via curl |
|
| 20 |
+5. Submit the template/template.json for parameterization |
|
| 21 | 21 |
|
| 22 |
-6. Trigger a new build of the application |
|
| 22 |
+6. Store the resulting config json in processed/template.processed.json |
|
| 23 | 23 |
|
| 24 |
-7. Show the new docker image created on your local system as a result of the build |
|
| 25 |
- * Normally the next step would be to push this image to a docker registry and then create a new openshift application based on it, or cause the existing application to be redeployed with the new image. See the next section to exercise this flow. |
|
| 24 |
+7. Submit the config json to OpenShift for creation |
|
| 25 |
+ |
|
| 26 |
+8. Confirm the application is created/accessible via curl |
|
| 26 | 27 |
|
| 27 | 28 |
To reset your system after running this example, you can run: |
| 28 | 29 |
|
| ... | ... |
@@ -16,8 +16,23 @@ All commands assume the `openshift` binary is in your path: |
| 16 | 16 |
|
| 17 | 17 |
1. Launch `openshift` |
| 18 | 18 |
|
| 19 |
- $ USE_HOST_DOCKER_SOCKET=true openshift start --listenAddr="0.0.0.0:8080" |
|
| 19 |
+ $ DOCKER_REGISTRY=localhost:5000 openshift start --listenAddr="0.0.0.0:8080" |
|
| 20 | 20 |
|
| 21 |
+2. Deploy the private docker registry within OpenShift: |
|
| 22 |
+ |
|
| 23 |
+ $ openshift kube apply -c registry_config/registry_config.json |
|
| 24 |
+ |
|
| 25 |
+3. Confirm the registry is started: |
|
| 26 |
+ |
|
| 27 |
+ $ openshift kube list pods |
|
| 28 |
+ |
|
| 29 |
+ You should see: |
|
| 30 |
+ |
|
| 31 |
+ ID Image(s) Host Labels Status |
|
| 32 |
+ ---------- ---------- ---------- ---------- ---------- |
|
| 33 |
+ 05929ee5-3fb2-11e4-a043-3c970e3bf0b7 registry 127.0.0.1/ name=frontendPod,replicationController=frontendController Running |
|
| 34 |
+ |
|
| 35 |
+ |
|
| 21 | 36 |
2. Fork the [ruby sample repository](https://github.com/openshift/ruby-hello-world) |
| 22 | 37 |
|
| 23 | 38 |
3. *Optional:* Add the following webhook to your new github repository: |
| ... | ... |
@@ -27,8 +42,6 @@ All commands assume the `openshift` binary is in your path: |
| 27 | 27 |
|
| 28 | 28 |
4. Edit buildcfg/buildcfg.json |
| 29 | 29 |
* Update the sourceURI to point to your forked repository. |
| 30 |
- * Update the imageTag to reflect your Docker username (eg <docker_username>/origin-ruby-sample) |
|
| 31 |
- * The built image will be tagged with this id and pushed to Docker later. |
|
| 32 | 30 |
|
| 33 | 31 |
5. Create a build configuration for your application. This configuration is used by OpenShift to rebuild your application's Docker image (eg when you push changes to the application source). |
| 34 | 32 |
|
| ... | ... |
@@ -62,23 +75,19 @@ All commands assume the `openshift` binary is in your path: |
| 62 | 62 |
---------- ---------- ---------- |
| 63 | 63 |
20f54507-3dcd-11e4-984b-3c970e3bf0b7 complete build-docker-20f54507-3dcd-11e4-984b-3c970e3bf0b7 |
| 64 | 64 |
|
| 65 |
- |
|
| 66 |
-8. Once the build is complete, push the resulting image to your Docker repository: |
|
| 67 |
- |
|
| 68 |
- $ docker push <docker_username>/origin-ruby-sample |
|
| 69 |
- |
|
| 70 |
-9. Modify the application template to reference your Docker image: |
|
| 71 |
- * Change "image": "openshift/origin-ruby-sample", to "image": "<docker_username>/origin-ruby-sample", |
|
| 72 |
- |
|
| 73 |
-10. Submit the application template for processing: |
|
| 65 |
+ The build will be automatically pushed to the private docker registry running in OpenShift and tagged with the imageTag listed |
|
| 66 |
+ in the buildcfg.json. Note that the private docker registry is using ephemeral storage, so when it is stopped, the image will |
|
| 67 |
+ be lost. An external volume can be used for storage, but is beyond the scope of this tutorial. |
|
| 68 |
+ |
|
| 69 |
+9. Submit the application template for processing: |
|
| 74 | 70 |
|
| 75 |
- $ curl -sld @template/template.json http://localhost:8080/osapi/v1beta1/templateConfigs > processed/template.processed.json |
|
| 71 |
+ $ openshift kube process -c template/template.json > processed/template.processed.json |
|
| 76 | 72 |
|
| 77 |
-11. Create the application using the processed template: |
|
| 73 |
+10. Create the application using the processed template: |
|
| 78 | 74 |
|
| 79 | 75 |
$ openshift kube apply -c processed/template.processed.json |
| 80 | 76 |
|
| 81 |
-12. Wait for the application's frontend pod to be started: |
|
| 77 |
+11. Wait for the application's frontend pod to be started: |
|
| 82 | 78 |
|
| 83 | 79 |
$ openshift kube list pods |
| 84 | 80 |
|
| ... | ... |
@@ -88,7 +97,7 @@ All commands assume the `openshift` binary is in your path: |
| 88 | 88 |
---------- ---------- ---------- ---------- ---------- |
| 89 | 89 |
fc66bffd-3dcc-11e4-984b-3c970e3bf0b7 openshift/origin-ruby-sample 127.0.0.1/ name=frontend,replicationController=frontendController Running |
| 90 | 90 |
|
| 91 |
-13. Confirm the application is now accessible via the frontend service on port 5432: |
|
| 91 |
+12. Confirm the application is now accessible via the frontend service on port 5432: |
|
| 92 | 92 |
|
| 93 | 93 |
$ curl localhost:5432 |
| 94 | 94 |
|
| ... | ... |
@@ -100,18 +109,18 @@ All commands assume the `openshift` binary is in your path: |
| 100 | 100 |
DB password is dQfUlnTG |
| 101 | 101 |
|
| 102 | 102 |
|
| 103 |
-14. Make an additional change to your ruby sample app.rb file and push it. |
|
| 103 |
+13. Make an additional change to your ruby sample app.rb file and push it. |
|
| 104 | 104 |
* If you do not have the webhook enabled, you'll have to manually trigger another build: |
| 105 | 105 |
|
| 106 | 106 |
$ curl -s -A "GitHub-Hookshot/github" -H "Content-Type:application/json" -H "X-Github-Event:push" -d @buildinvoke/pushevent.json http://localhost:8080/osapi/v1beta1/buildConfigHooks/build100/secret101/github |
| 107 | 107 |
|
| 108 |
-15. Repeat steps 7-8 |
|
| 108 |
+14. Repeat steps 7-8 |
|
| 109 | 109 |
|
| 110 |
-16. Locate the container running the ruby application and kill it: |
|
| 110 |
+15. Locate the container running the ruby application and kill it: |
|
| 111 | 111 |
|
| 112 |
- $ docker kill `docker ps | grep origin-ruby-sample | awk '{print $1}'`
|
|
| 112 |
+ $ docker kill `docker ps | grep /usr/bin/ruby | awk '{print $1}'`
|
|
| 113 | 113 |
|
| 114 |
-17. Use 'docker ps' to watch as OpenShift automatically recreates the killed container using the latest version of your image. Once the container is recreated, curl the application to see the change you made in step 14. |
|
| 114 |
+16. Use 'docker ps' to watch as OpenShift automatically recreates the killed container using the latest version of your image. Once the container is recreated, curl the application to see the change you made in step 14. |
|
| 115 | 115 |
|
| 116 | 116 |
$ curl localhost:5432 |
| 117 | 117 |
|
| ... | ... |
@@ -119,5 +128,5 @@ Congratulations, you've successfully deployed and updated an application on Open |
| 119 | 119 |
|
| 120 | 120 |
$ ./cleanup.sh |
| 121 | 121 |
|
| 122 |
- This will stop the `openshift` process, remove the etcd storage, and kill all Docker containers running on your host system. (**Use with caution!** Docker containers unrelated to OpenShift will also be killed by this script) |
|
| 122 |
+This will stop the `openshift` process, remove the etcd storage, and kill all Docker containers running on your host system. (**Use with caution!** Docker containers unrelated to OpenShift will also be killed by this script) |
|
| 123 | 123 |
|
| 124 | 124 |
\ No newline at end of file |
| 125 | 125 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,61 @@ |
| 0 |
+{
|
|
| 1 |
+ "apiVersion": "v1beta1", |
|
| 2 |
+ "creationTimestamp": "2014-09-18T18:28:38-04:00", |
|
| 3 |
+ "description": "Creates a private docker registry", |
|
| 4 |
+ "id": "docker-registry-config", |
|
| 5 |
+ "items": [ |
|
| 6 |
+ {
|
|
| 7 |
+ "apiVersion": "v1beta1", |
|
| 8 |
+ "containerPort": 0, |
|
| 9 |
+ "creationTimestamp": null, |
|
| 10 |
+ "id": "registryservice", |
|
| 11 |
+ "kind": "Service", |
|
| 12 |
+ "port": 5000, |
|
| 13 |
+ "selector": {
|
|
| 14 |
+ "name": "registryPod" |
|
| 15 |
+ } |
|
| 16 |
+ }, |
|
| 17 |
+ {
|
|
| 18 |
+ "apiVersion": "v1beta1", |
|
| 19 |
+ "creationTimestamp": null, |
|
| 20 |
+ "desiredState": {
|
|
| 21 |
+ "podTemplate": {
|
|
| 22 |
+ "desiredState": {
|
|
| 23 |
+ "manifest": {
|
|
| 24 |
+ "containers": [ |
|
| 25 |
+ {
|
|
| 26 |
+ "image": "registry", |
|
| 27 |
+ "name": "registry-container", |
|
| 28 |
+ "ports": [ |
|
| 29 |
+ {
|
|
| 30 |
+ "containerPort": 5000, |
|
| 31 |
+ "protocol": "TCP" |
|
| 32 |
+ } |
|
| 33 |
+ ] |
|
| 34 |
+ } |
|
| 35 |
+ ], |
|
| 36 |
+ "id": "registryPod", |
|
| 37 |
+ "version": "v1beta1", |
|
| 38 |
+ "volumes": null |
|
| 39 |
+ }, |
|
| 40 |
+ "restartpolicy": {}
|
|
| 41 |
+ }, |
|
| 42 |
+ "labels": {
|
|
| 43 |
+ "name": "registryPod" |
|
| 44 |
+ } |
|
| 45 |
+ }, |
|
| 46 |
+ "replicaSelector": {
|
|
| 47 |
+ "name": "registryPod" |
|
| 48 |
+ }, |
|
| 49 |
+ "replicas": 1 |
|
| 50 |
+ }, |
|
| 51 |
+ "id": "registryController", |
|
| 52 |
+ "kind": "ReplicationController", |
|
| 53 |
+ "labels": {
|
|
| 54 |
+ "name": "registryController" |
|
| 55 |
+ } |
|
| 56 |
+ } |
|
| 57 |
+ ], |
|
| 58 |
+ "kind": "Config", |
|
| 59 |
+ "name": "docker-registry-config" |
|
| 60 |
+} |
| ... | ... |
@@ -1,47 +1,39 @@ |
| 1 | 1 |
#!/bin/bash |
| 2 | 2 |
|
| 3 |
-# openshift server host |
|
| 3 |
+# OpenShift server host |
|
| 4 | 4 |
OSHOST=localhost |
| 5 | 5 |
|
| 6 |
-# openshift binary |
|
| 6 |
+# OpenShift binary |
|
| 7 | 7 |
openshift="../../_output/go/bin/openshift" |
| 8 | 8 |
|
| 9 |
-# OPTIONAL: Wipe out previous openshift/k8s deployment information for a |
|
| 9 |
+# OPTIONAL: Wipe out previous OpenShift/k8s deployment information for a |
|
| 10 | 10 |
# clean start. |
| 11 | 11 |
rm -rf openshift.local.etcd |
| 12 | 12 |
|
| 13 |
-# OPTIONAL: kill all docker containers before starting |
|
| 13 |
+# OPTIONAL: kill all Docker containers before starting |
|
| 14 | 14 |
# docker kill `docker ps --no-trunc -q` |
| 15 | 15 |
|
| 16 | 16 |
|
| 17 |
-# Start the openshift all-in-one server |
|
| 17 |
+# Start the OpenShift all-in-one server |
|
| 18 | 18 |
# (starts a kubernetes master and minion as well as providing the |
| 19 | 19 |
# origin REST api) |
| 20 |
-# Uses Host docker socket so that the resulting docker images are |
|
| 21 |
-# available on the host. Otherwise the docker image lives only inside |
|
| 22 |
-# the docker build container, and goes away when the build container |
|
| 23 |
-# goes away. (Currently the resulting image from the build is not |
|
| 24 |
-# pushed to any registry). |
|
| 20 |
+# DOCKER_REGISTRY refers to the private Docker registry running inside a pod in OpenShift. |
|
| 25 | 21 |
echo "Launching openshift all-in-one server" |
| 26 |
-USE_HOST_DOCKER_SOCKET=true $openshift start --listenAddr="0.0.0.0:8080" &> logs/openshift.log & |
|
| 22 |
+DOCKER_REGISTRY=localhost:5000 $openshift start --listenAddr="0.0.0.0:8080" &> logs/openshift.log & |
|
| 27 | 23 |
|
| 28 | 24 |
sleep 5 |
| 29 | 25 |
|
| 30 |
-# Convert template to config |
|
| 31 |
-echo "Submitting template json for processing..." |
|
| 32 |
-curl -sld @template/template.json http://$OSHOST:8080/osapi/v1beta1/templateConfigs > processed/template.processed.json |
|
| 33 |
- |
|
| 34 |
-# Deploy the config |
|
| 35 |
-$openshift kube -h http://$OSHOST:8080 apply -c processed/template.processed.json |
|
| 26 |
+# Deploy the private Docker registry config |
|
| 27 |
+openshift kube apply -c registry_config/registry_config.json |
|
| 36 | 28 |
|
| 37 | 29 |
# Wait for the app container to start up |
| 38 | 30 |
rc=1 |
| 39 | 31 |
while [ ! $rc -eq 0 ] |
| 40 | 32 |
do |
| 41 |
- echo "Waiting for frontend pod to start..." |
|
| 33 |
+ echo "Waiting for Docker registry pod to start..." |
|
| 42 | 34 |
$openshift kube list pods |
| 43 | 35 |
sleep 5 |
| 44 |
- $openshift kube list pods | grep frontend | grep Running |
|
| 36 |
+ $openshift kube list pods | grep registryPod | grep Running |
|
| 45 | 37 |
rc=$? |
| 46 | 38 |
done |
| 47 | 39 |
|
| ... | ... |
@@ -49,21 +41,13 @@ $openshift kube list services | grep frontend |
| 49 | 49 |
rc=$? |
| 50 | 50 |
while [ ! $rc -eq 0 ] |
| 51 | 51 |
do |
| 52 |
- echo "Waiting for frontend service to start..." |
|
| 52 |
+ echo "Waiting for Docker registry service to start..." |
|
| 53 | 53 |
$openshift kube list services |
| 54 | 54 |
sleep 5 |
| 55 |
- $openshift kube list services | grep frontend |
|
| 55 |
+ $openshift kube list services | grep registryPod |
|
| 56 | 56 |
rc=$? |
| 57 | 57 |
done |
| 58 | 58 |
|
| 59 |
-# Sometimes the app isn't quite available even though the pod is running, |
|
| 60 |
-# wait a little longer. |
|
| 61 |
-sleep 5 |
|
| 62 |
- |
|
| 63 |
-# Confirm the app is running/responsive. |
|
| 64 |
-echo "Frontend is available, sending request. Frontend says:" |
|
| 65 |
-curl localhost:5432 |
|
| 66 |
- |
|
| 67 | 59 |
# show build cfgs |
| 68 | 60 |
echo "Initially no build configurations:" |
| 69 | 61 |
$openshift kube list buildConfigs |
| ... | ... |
@@ -86,12 +70,6 @@ $openshift kube list builds |
| 86 | 86 |
echo "Triggering new build" |
| 87 | 87 |
curl -s -A "GitHub-Hookshot/github" -H "Content-Type:application/json" -H "X-Github-Event:push" -d @buildinvoke/pushevent.json http://$OSHOST:8080/osapi/v1beta1/buildConfigHooks/build100/secret101/github |
| 88 | 88 |
|
| 89 |
-# webhook url |
|
| 90 |
-#http://$OSHOST:8080/osapi/v1beta1/buildConfigHooks/build100/secret101/github |
|
| 91 |
-#cd ~/demofiles/app |
|
| 92 |
-#edit app.rb |
|
| 93 |
-#git commit -am . ; git push origin master |
|
| 94 |
- |
|
| 95 | 89 |
#show build running |
| 96 | 90 |
echo "Build now running: " |
| 97 | 91 |
$openshift kube list builds |
| ... | ... |
@@ -108,6 +86,41 @@ do |
| 108 | 108 |
$openshift kube get builds/$id | grep complete |
| 109 | 109 |
rc=$? |
| 110 | 110 |
done |
| 111 |
- |
|
| 112 |
-echo "Your new application image is origin_ruby_sample: " |
|
| 113 |
-docker images | grep origin-ruby-sample |
|
| 111 |
+ |
|
| 112 |
+# Convert template to config |
|
| 113 |
+echo "Submitting application template json for processing..." |
|
| 114 |
+openshift kube process -c template/template.json > processed/template.processed.json |
|
| 115 |
+ |
|
| 116 |
+# Deploy the config |
|
| 117 |
+$openshift kube -h http://$OSHOST:8080 apply -c processed/template.processed.json |
|
| 118 |
+ |
|
| 119 |
+# Wait for the app container to start up |
|
| 120 |
+rc=1 |
|
| 121 |
+while [ ! $rc -eq 0 ] |
|
| 122 |
+do |
|
| 123 |
+ echo "Waiting for frontend pod to start..." |
|
| 124 |
+ $openshift kube list pods |
|
| 125 |
+ sleep 5 |
|
| 126 |
+ $openshift kube list pods | grep frontend | grep Running |
|
| 127 |
+ rc=$? |
|
| 128 |
+done |
|
| 129 |
+ |
|
| 130 |
+$openshift kube list services | grep frontend |
|
| 131 |
+rc=$? |
|
| 132 |
+while [ ! $rc -eq 0 ] |
|
| 133 |
+do |
|
| 134 |
+ echo "Waiting for frontend service to start..." |
|
| 135 |
+ $openshift kube list services |
|
| 136 |
+ sleep 5 |
|
| 137 |
+ $openshift kube list services | grep frontend |
|
| 138 |
+ rc=$? |
|
| 139 |
+done |
|
| 140 |
+ |
|
| 141 |
+# Sometimes the app isn't quite available even though the pod is running, |
|
| 142 |
+# wait a little longer. |
|
| 143 |
+sleep 15 |
|
| 144 |
+ |
|
| 145 |
+# Confirm the app is running/responsive. |
|
| 146 |
+echo "Frontend is available, sending request. Frontend says:" |
|
| 147 |
+curl localhost:5432 |
|
| 148 |
+ |
|
| 114 | 149 |
\ No newline at end of file |