Repository navigation
Starting Point: Basic App Setup
This is the first part of a three part overview of setting up a basic application. Here we will step through the process of setting up a simple python/flask app in an empty OpenShift Namespace.
- Basic knowledge of
python,wsgi,bash,OpenShift,oc - You have a project/namespace to work in and you have editor privs.
You'll need a namespace in either:
- OpenShift Pathfinder,
- https://learn.openshift.com, or
- You've setup your own OpenShift environment locally with
minishift(see Setup Red Hat Container Development Kit) oroc cluster up.
- You have a GitHub repo containing your python/wsgi application - I've simply cloned OpenShiftDemos/os-sample-python
I used OpenShiftDemos/os-sample-python as a starting point.
You may use any initial app you wish.
My fork dkelsey/os-sample-python will include everything already added in this tutorial (I tagged the repo after completing the end of each section).
Fork the repo.
Clone your fork of the repository:
git clone https://github.com/dkelsey/os-sample-python.gitNote: Use your own name not mine (dkelsey).
I'm using minishift, logged in as a developer to myproject
Perform a dry run first:
oc new-app https://github.com/OpenShiftDemos/os-sample-python.git \
--name=demo-app \
-l app=demo-app \
--dry-run
--> Found image b402d05 (5 months old) in image stream "openshift/python" under tag "3.6" for "python"
Python 3.6
----------
Python 3.6 available as container is a base platform for building and running various Python 3.6 applications and frameworks. Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python's elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.
Tags: builder, python, python36, rh-python36
* The source repository appears to match: python
* A source build using source code from https://github.com/OpenShiftDemos/os-sample-python.git will be created
* The resulting image will be pushed to image stream tag "demo-app:latest"
* Use 'start-build' to trigger a new build
* This image will be deployed in deployment config "demo-app"
* Port 8080/tcp will be load balanced by service "demo-app"
* Other containers can access this service through the hostname "demo-app"
--> Creating resources with label app=demo-app ...
imagestream.image.openshift.io "demo-app" created (dry run)
buildconfig.build.openshift.io "demo-app" created (dry run)
deploymentconfig.apps.openshift.io "demo-app" created (dry run)
service "demo-app" created (dry run)- Read the README.md for os-sample-python
- This is a sample application that is build using
S2I - I suggest you have a base understanding of
S2I- enough so you can use it and know what it gives you. - There are other ways to launch and app in OpenShift.
- This shows you that it will create the following resources in your project:
- a BuildConfig
- an ImageStream
- a DeploymentConfig
- a Service
Now do it for real:
oc new-app https://github.com/OpenShiftDemos/os-sample-python.git --name=demo-app -l app=demo-app
--> Found image b402d05 (5 months old) in image stream "openshift/python" under tag "3.6" for "python"
Python 3.6
----------
Python 3.6 available as container is a base platform for building and running various Python 3.6 applications and frameworks. Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python's elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.
Tags: builder, python, python36, rh-python36
* The source repository appears to match: python
* A source build using source code from https://github.com/OpenShiftDemos/os-sample-python.git will be created
* The resulting image will be pushed to image stream tag "demo-app:latest"
* Use 'start-build' to trigger a new build
* This image will be deployed in deployment config "demo-app"
* Port 8080/tcp will be load balanced by service "demo-app"
* Other containers can access this service through the hostname "demo-app"
--> Creating resources with label app=demo-app ...
imagestream.image.openshift.io "demo-app" created
buildconfig.build.openshift.io "demo-app" created
deploymentconfig.apps.openshift.io "demo-app" created
service "demo-app" created
--> Success
Build scheduled, use 'oc logs -f bc/demo-app' to track its progress.
Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
'oc expose svc/demo-app'
Run 'oc status' to view your app.-
Again, you must be authenticated with OpenShift and using the
projectyou want the app created in-
You could specify the project with:
oc-n devops-demo-devnew-app https://github.com/dkelsey/os-sample-python.git ...
-
You could specify the project with:
- It is not necessary to clone the repo locally in order to create a new app on OpenShift. The command above will grab the code directly from GitHub, however you will want a local copy to demonstrate triggering a build through pushed code changes.
oc get all -l app=demo-app
NAME READY STATUS RESTARTS AGE
pod/demo-app-1-6hgrb 1/1 Running 0 3m
NAME DESIRED CURRENT READY AGE
replicationcontroller/demo-app-1 1 1 1 3m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/demo-app ClusterIP 172.30.156.56 <none> 8080/TCP 3m
NAME REVISION DESIRED CURRENT TRIGGERED BY
deploymentconfig.apps.openshift.io/demo-app 1 1 1 config,image(demo-app:latest)
NAME TYPE FROM LATEST
buildconfig.build.openshift.io/demo-app Source Git 1
NAME TYPE FROM STATUS STARTED DURATION
build.build.openshift.io/demo-app-1 Source Git@da9328c Complete 3 minutes ago 12s
NAME DOCKER REPO TAGS UPDATED
imagestream.image.openshift.io/demo-app 172.30.1.1:5000/myproject/demo-app latest 3 minutes ago
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
route.route.openshift.io/demo-app demo-app-myproject.192.168.64.4.nip.io demo-app 8080-tcp NoneLaunching the app will succeed. You will need to add a route in order to brows to the app-when you run new-app the output gives you a hint that you need to do so.
oc expose svc/demo-app
route.route.openshift.io/demo-app exposed
oc get route -l app=demo-app
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
demo-app demo-app-ikpp1u-dev.pathfinder.gov.bc.ca demo-app 8080-tcp NoneQuery the app with curl:
curl os-sample-python-devops-demo-dev.192.168.64.4.nip.io
Hello World!Note: Your URL will be different than mine. FYI: i'm working in my local minishift
| tag | comment |
|---|---|
| v1.0.0 | Step 1.0 - get the app runing with new-app |
Note: I had to setup https://github.com/probot/smee-client in order to get webhooks to work in minishift.
Builds->demo-app->Configuration
Under Triggers: copy the GitHub Webhook URL to your paste buffer.
Settings->WebHooks add the web hook.
- Be sure to set
Content typetoapplication/json - You may need to disable SSL verification
Note: You must have working git tools; You may need to setup authentication (I use the cli)
edit wsgi.py, change 'World' to Bubba
git add wsgi.py
git commit -m "change to Bubba"
git push
Give it a little time before querying
curl os-sample-python-devops-demo-dev.192.168.64.4.nip.io
Hello Bubba!| tag | comment |
|---|---|
| v1.0.1 | Get webhook working with push |
You've got an app runing in OpenShift that get's redeployed when you push to it's Github repo. You should be more familiar with the objects in Openshift and how they can be configured.
This is just the start.
Continue to the next part: Transformation to Templates
Because i'm using minishift webhooks would not work without smee and some additional configuration.
This was what was occuring without the additional coniguration:
smee -u https://smee.io/Hy4ZQaeKsyO1sw2z -t https://192.168.64.4:8443/apis/build.openshift.io/v1/namespaces/myproject/buildconfigs/demo-app/webhooks/AUHLc9xpxZbdLSPiiAU1/github
Forwarding https://smee.io/Hy4ZQaeKsyO1sw2z to https://192.168.64.4:8443/apis/build.openshift.io/v1/namespaces/myproject/buildconfigs/demo-app/webhooks/AUHLc9xpxZbdLSPiiAU1/github
Connected https://smee.io/Hy4ZQaeKsyO1sw2z
{ Error: self signed certificate in certificate chain
at TLSSocket.onConnectSecure (_tls_wrap.js:1051:34)
at TLSSocket.emit (events.js:189:13)
at TLSSocket._finishInit (_tls_wrap.js:633:8) code: 'SELF_SIGNED_CERT_IN_CHAIN', response: undefined }To get over the TLS error add NODE_TLS_REJECT_UNAUTHORIZED=0
NODE_TLS_REJECT_UNAUTHORIZED=0 smee -u https://smee.io/Hy4ZQaeKsyO1sw2z -t https://192.168.64.4:8
443/apis/build.openshift.io/v1/namespaces/myproject/buildconfigs/demo-app/webhooks/AUHLc9xpxZbdLSPiiAU1/github
Forwarding https://smee.io/Hy4ZQaeKsyO1sw2z to https://192.168.64.4:8443/apis/build.openshift.io/v1/namespaces/myproject/buildconfigs/demo-app/webhooks/AUHLc9xpxZbdLSPiiAU1/github
Connected https://smee.io/Hy4ZQaeKsyO1sw2z
POST https://192.168.64.4:8443/apis/build.openshift.io/v1/namespaces/myproject/buildconfigs/demo-app/webhooks/AUHLc9xpxZbdLSPiiAU1/github - 200Further, later in my effoert, for some reason the webhook ceased to work so we added a port-forward to the pod and adjusted the target--This may not be necessary at first:
you have to find the correct pod in your environment
oc port-forward jenkins-build-0-1-rbdrq 8888:8080
Forwarding from 127.0.0.1:8888 -> 8080
Forwarding from [::1]:8888 -> 8080
Handling connection for 8888
NODE_TLS_REJECT_UNAUTHORIZED=0 smee -u \
https://smee.io/F0r7leEl73KndWMa \
-t http://127.0.0.1:8888/github-webhook/
Forwarding https://smee.io/F0r7leEl73KndWMa to http://127.0.0.1:8888/github-webhook/
Connected https://smee.io/F0r7leEl73KndWMa
POST http://127.0.0.1:8888/github-webhook/ - 200