Red Hat OpenShift - Group home

Using Red Hat odo dev command to deploy applications on IBM Z and IBM LinuxONE

  

Authors: Rishika Kedia, Harshitha M S, Surender Yadav

Odo dev command is helping to iterate through the development process for building an application and this process is called inner loop development, that’s where we code, build, run and test application in a continuous workflow on IBM® Z® and IBM® LinuxONE.

Odo dev is used when we are working with local development environment and want to debug and run tests, preview any changes. Refer below steps to develop an application using odo dev command.

Step 1: Connect to your cluster and create a new namespace or project

Before starting you should make sure that odo is connected to your cluster and that you have created a new namespace or project if you are using Red Hat OpenShift.

Login to Red Hat OpenShift Cluster:

The easiest way to connect odo to an Red Hat OpenShift cluster is use copy Copy login command function in Red Hat OpenShift Web Console.

  1. Login to Red Hat OpenShift Web Console.
  2. At the top right corner click on your username and then on Copy login command.
  3. You will be prompted to enter your login credentials again.
  4. After login, open "Display Token" link.
  5. Copy whole oc login --token ... command and paste it into the terminal, before executing the command replace oc with odo.

Create a new project:

If you are using Red Hat OpenShift, you can create a new namespace with the odo create project command.

$ odo create project odo-dev
 ✓  Project "odo-dev" is ready for useNew project created and now using project: odo-dev

Step 2. Initializing your application using odo init command

You must run odo init on an empty directory or in the directory where your project files are present. If you don’t have project ready, then odo init will give you starter project based on which language application you want to deploy just by running odo init on empty directory. For now, will consider sample NodeJS project as an example to deploy using odo. 

[odo@fe707f2075b8 test]$ odo init
  __
 /  \__     Initializing a new component
 \__/  \    Files: No source code detected, a starter project will be created in the current directory
 /  \__/    odo version: v3.7.0
 \__/

Interactive mode enabled, please answer the following questions:
? Select language: JavaScript
? Select project type: Node.js Runtime
 ✓  Downloading devfile "nodejs" from registry "DefaultDevfileRegistry" [17ms]

↪ Container Configuration "runtime":
  OPEN PORTS:
    - 3000
    - 5858
  ENVIRONMENT VARIABLES:
    - DEBUG_PORT = 5858

? Select container for which you want to change configuration? NONE - configuration is correct
? Which starter project do you want to use? nodejs-starter
? Enter component name: test
 ✓  Downloading starter project "nodejs-starter" [650ms]

You can automate this command by executing:
   odo init --name test --devfile nodejs --devfile-registry DefaultDevfileRegistry --starter nodejs-starter

Your new component 'test' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Changes will be directly reflected on the cluster.

If you have project ready, then odo handles this automatically with the odo init command by autodetecting your source code and downloading the appropriate Devfile. 

$ odo init
  __
 /  \__     Initializing a new component
 \__/  \    Files: Source code detected, a Devfile will be determined based upon source code autodetection
 /  \__/    odo version: v3.7.0
 \__/

Interactive mode enabled, please answer the following questions:
Based on the files in the current directory odo detected
Language: JavaScript
Project type: Node.js
The devfile "nodejs:2.1.1" from the registry "DefaultDevfileRegistry" will be downloaded.
? Is this correct? Yes
 ✓  Downloading devfile "nodejs:2.1.1" from registry "DefaultDevfileRegistry" [3s]

↪ Container Configuration "runtime":
  OPEN PORTS:
    - 3000
    - 5858
  ENVIRONMENT VARIABLES:
    - DEBUG_PORT = 5858

? Select container for which you want to change configuration? NONE - configuration is correct
? Enter component name: my-nodejs-app

You can automate this command by executing:
   odo init --name my-nodejs-app --devfile nodejs --devfile-registry DefaultDevfileRegistry --devfile-version 2.1.1

Your new component 'my-nodejs-app' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Changes will be directly reflected on the cluster.

A devfile.yaml has now been added to your directory and now you're ready to start development.

Step 3. Developing your application continuously using odo dev

Now that we've generated code as well as our Devfile, let's start on development.

Odo uses inner loop development and allows to code, build, run and test the application in a continuous workflow.

Once you run odo dev, you can freely edit code in your favourite IDE and watch as odo rebuilds and redeploys it.

Let's run odo dev to start development on Node.JS application:

$ odo dev
  __
 /  \__     Developing using the "my-nodejs-app" Devfile
 \__/  \    Namespace: odo-dev
 /  \__/    odo version: v3.7.0
 \__/

↪ Running on the cluster in Dev mode
 •  Waiting for Kubernetes resources  ...
 ⚠  Pod is Pending
 ✓  Pod is Running
 ✓  Syncing files into the container [193ms]
 ✓  Building your application in container (command: install) [5s]
 •  Executing the application (command: run)  ...
 -  Forwarding from 127.0.0.1:20001 -> 3000


↪ Dev mode
 Status:
 Watching for changes in the current directory /home/user/quickstart-demo

 Keyboard Commands:
[Ctrl+c] - Exit and delete resources from the cluster
     [p] - Manually apply local changes to the application on the cluster
You can now access the application at 127.0.0.1:40001 in your local browser and start your development loop. Odo will watch for changes and push the code for real-time updates.

Once you are done developing an application with odo dev, the next step is to deploy your application using odo deploy command. To deploy using odo deploy refer in this blog article: Using Red Hat odo deploy command to deploy applications on IBM Z and IBM® LinuxONE.