OpenShift - Deploy an application from GitHub

If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.

The oc new-app or oc create command can be used to deploy an application from GitHub to OpenShift. There are various ways to deploy an app.


Install git

If git is not installed on your OpenShift server, the dnf install or yum install command can be used to install git.

dnf install git

 


In this example, cakephp (which is an HTTPD web server with PHP support) from GitHub (cakephp-ex.git) will be deployed using the oc new-new command. If the --name option is not used, the name of the pod would be cakephp-ex. The --name option cab be used to give the pod a specific name, such as just "php".

oc new-app https://github.com/sclorg/cakephp-ex --name php

 

Or, you could create a JSON file such as cakephp.json that contains the JSON needed to deploy the app and then use the oc create command with the -f or --filename option to deploy the app.

oc create --filename cakephp.json

 

If something like this is returned . . .

error: unable to load template file "https://github.com/sclorg/nodejs-ex": error parsing https://github.com/sclorg/nodejs-ex: error converting YAML to JSON: yaml: line 28: mapping values are not allowed in this context
error:  local file access failed with: stat https://github.com/sclorg/nodejs-ex: no such file or directory
error: unable to locate any images in image streams, templates loaded in accessible projects, template files, local docker images with name "https://github.com/sclorg/nodejs-ex"

Argument 'https://github.com/sclorg/nodejs-ex' was classified as an image, image~source, or loaded template reference.

The 'oc new-app' command will match arguments to the following types:

  1. Images tagged into image streams in the current project or the 'openshift' project
     - if you don't specify a tag, we'll add ':latest'
  2. Images in the container storage, on remote registries, or on the local container engine
  3. Templates in the current project or the 'openshift' project
  4. Git repository URLs or local paths that point to Git repositories

--allow-missing-images can be used to point to an image that does not exist yet.

 

you can try including the --image-steam and --allow-missing-imagestream-tags options.

oc new-app https://github.com/sclorg/nodejs-ex --name nodejs --image-stream="openshift/nodejs" --allow-missing-imagestream-tags

 


If the deployment was successful, the oc get deployments command should return something like this.

~]# oc get deployments
NAME      READY   UP-TO-DATE   AVAILABLE   AGE
php       1            1           8d

 

While the pod is being built, the oc get pods command should display something like this. Notice "-build" in name.

NAME               READY     STATUS              RESTARTS   AGE
php-ex-1-build   0/1       ContainerCreating   0          5s

 

Once the build has completed successfully, the following should be displayed.

NAME               READY     STATUS     RESTARTS   AGE
php-ex-1-build   1/1       Running    0          1m

 

Next, the deploy pod should be create. One the deploy has completed successfully, the following should be displayed.

NAME               READY     STATUS     RESTARTS   AGE
php-ex-1-deploy  1/1       Running    0          2m

 

If there is some issue with the build or deploy, something like this should be displayed.

NAME               READY     STATUS     RESTARTS   AGE
php-ex-1-build   0/1       Init:0/2   0          15s

 

If the build pod fails to initialize, something like this should be displayed.

NAME               READY     STATUS     RESTARTS   AGE
php-ex-1-build   0/1       Init:Error 0          4m

 

In this scenario, the oc describe pod command can be used to display the pod events.

oc describe pod/php-ex-1-build

 

Here is a sample of what could possibly be included in the output.

Status:  Failed
State:   Terminated
Reason:  Error
Message: Cloning "https://github.com/sclorg/cakephp-ex" ...
WARNING: timed out waiting for git server, will wait 1m4s
WARNING: timed out waiting for git server, will wait 4m16s
error:   fatal: unable to access 'https://github.com/sclorg/cakephp-ex/': Failed connect to github.com:443; Connection timed out

 

In this scenario, if you are behind a proxy server, you could use the git config command to instruct git to use your proxy server.

git config --global http.proxy http://username:password@proxy.example.com:80

 


oc status

Once the status of the pod is Running, the oc status command can be used.

oc status

 

Something like this should be displayed.

svc/php - 10.15.152.137 ports 8080, 8443
  dc/httpd deploys openshift/php:7.1 
    deployment #1 running for about a minute - 0/1 pods


3 infos identified, use 'oc status --suggest' to see details.

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter 6c2ec in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |