Programming Languages on Power

 View Only

Developing .NET applications on IBM Power using Visual Studio code with Red Hat OpenShift Dev Spaces

By Sachin Itagi posted Tue March 07, 2023 02:01 PM

  

Have you ever been daunted by the idea of working with Red Hat OpenShift Dev Spaces? Or, is the thought of developing your own applications using this amazing functionality by Red Hat a bit too much for you? Well, this blog might help you overcome your fears! Follow along as I walk you through a step-by-step process for installing OpenShift Dev Spaces on the Red Hat OpenShift Container Platform on IBM Power. You will also learn how to install OpenShift Dev Spaces operator and start a .NET based workspace.

What is OpenShift Dev Spaces?

First things first! OpenShift Dev Spaces (Formerly known as Red Hat CodeReady Workspaces) uses Kubernetes and containers to provide any member of the development or IT team with a consistent, secure, and zero configuration development environment. It is often referred as, “The OpenShift native developer workspace server and Integrated Developer Environment (IDE)”. OpenShift Dev Spaces allows you to create workspaces that can be used to code, build, test, run and debug applications. Isn’t that wonderful? For more information, see Red Hat OpenShift Dev Spaces.

OpenShift Dev Spaces consists of the CheCluster custom resource and various components such as devworkspace, cheServer, pluginRegistry, devfileRegistry, database, dashboard, and imagePuller. If you want to check out more details about these components, see OpenShift Dev Spaces Components.

The CheCluster custom resource is a Kubernetes object that can be configured by editing the CheCluster Custom Resource YAML file. The YAML file contains sections to configure each component. The CheCluster custom resource is created during installation of OpenShift Dev Spaces and is used to setup the OpenShift Dev Spaces components. 

Each component of an OpenShift Dev Spaces workspace is managed by OpenShift pods. A pod can be defined as a collection of containers that are stored inside the node of an OpenShift cluster.  This implies that everything that is running on OpenShift Dev Spaces is running within a container making OpenShift Dev Spaces highly portable. For more details about OpenShift Pods, see Pods and Services.

Using OpenShift Dev Spaces, you can create developer workspaces with different language support. A workspace is a containerized instance of a development environment that you can use to write, build, run, or debug the code. The supported languages are C++, Python, Java, Gradle, Nodejs, PHP and C#. For additional details on workspaces, see The Inner Loop with OpenShift Dev Spaces.

Furthermore, developer workspace supports extensions to add languages, debuggers, and other tools. The Visual Studio Code binary that is included in the pluginRegistry component of OpenShift Dev Spaces is preconfigured to use the Open VSX Registry which contains thousands of extensions and is owned by Eclipse Foundation. We have explained this in detail in the “Starting Workspace on OpenShift Dev Spaces” section of this blog.

Some of the features that are provided by OpenShift Dev Spaces include:

OpenShift Native Development: OpenShift Dev Spaces is included in the OpenShift subscription and is available from version 4.10 onwards. The application and development environment are containerized and run on OpenShift. Thus, you can focus on coding without worrying about the intricate details of Kubernetes.

In-browser Integrated Developer Environment (IDE): OpenShift Dev Spaces allows you to develop code using multiple IDEs which includes Visual Studio Code and the deprecated (and soon to be removed) Theia-ide. You only need a system with a web browser to code, build, test, and run on OpenShift Dev Spaces.

Near-instant onboarding: Anyone with a browser can contribute to the project within 2 minutes!

What is Visual Studio code (VS code)?

Visual Studio code or VS code is a source code editor that includes built-in support for JavaScript, TypeScript, NodeJS, and extensions for other languages such as C/C++, Python, Java, and C#. OpenShift Dev spaces provides x86, IBM Power, and IBM Z users with workspaces that use VS code as the default IDE.

Install OpenShift Dev Spaces

Let’s get started! Check out the prerequisites to know what all you’ll need before you begin.

Prerequisites

  •  A fully functional Red Hat OpenShift cluster.
  • An OpenShift command-line interface (oc) installed.

Steps

The following steps guide you through installing OpenShift Dev Spaces on an OpenShift cluster.

Step 1: Install DevWorkspace operator on the OpenShift cluster

DevWorkspace operator functions as a standalone operator and is required as a dependency for OpenShift Dev Spaces. For more information, refer to  Devfile v2 and the DevWorkspace Operator.

Perform the following steps to install DevWorkspace operator:

  1. Create a Subscription object YAML file to subscribe a namespace to an operator.
    apiVersion: operators.coreos.com/v1alpha1
    kind: Subscription
    metadata:
      generateName: devworkspace-operator-subscription-
      namespace: openshift-operators
    spec:
      name: devworkspace-operator
      installPlanApproval: Automatic
      channel: fast
      source: redhat-operators
      sourceNamespace: openshift-marketplace
      startingCSV: devworkspace-operator.v0.18.1
    

  2. Create a Subscription object using Command Line Interface (CLI).
    oc create -f dwoSubscription.yaml
  3. Click Installed Operators and on the Installed Operators page, notice that DevWorkspace Operator is now displayed, as shown below. This means you installed it successfully!

Figure 1. Successful installation of DevWorkspace Operator

Step 2: Install OpenShift Dev Spaces operator on OpenShift cluster

  1. Login to the OpenShift console with administrator privileges. Click OperatorHub under the Operators menu and then click Red Hat OpenShift Dev Spaces catalog.

    Installing Dev Spaces operator on OpenShift cluster
    Figure. 2. Install OpenShift Dev Spaces from OperatorHub
  2. Click install.

    Installing Dev Spaces operator on OpenShift cluster
    Figure 3. Install OpenShift Dev Spaces operator

  3. After OpenShift Dev Spaces is installed, you will notice that Red Hat OpenShift Spaces is displayed under Installed Operators. To create a CheCluster instance, go to the Red Hat OpenShift Dev Spaces instance Specification tab and click Create CheCluster.

    Create a CheCluster instance
    Figure 4. Create CheCluster instance
     
  4. Retain default values for all fields and click create.

    Create CheCluster
    Figure 5. Create CheCluster instance

After the instance deploys successfully, you can view the OpenShift Dev Spaces URL in the CheCluster details page as shown in figure 6 in the next section.

Step 3. Start .NET workspace with OpenShift Dev Spaces

Follow these steps to start a .NET workspace with OpenShift Dev Spaces.

  1. Click the Red Hat OpenShift Dev Spaces URL that was generated in the overview section of CheCluster instance (shown in Figure 6). This will open the OpenShift Dev Spaces Dashboard as shown in Figure 7 below.

    Red Hat OpenShift Dev Spaces URL

    Figure. 6 Red Hat OpenShift Dev Spaces URL 

    The OpenShift Dev Spaces dashboard displays sample projects for various programming languages. When you click a sample project tile, a workspace will start. Another option to start a workspace is to use a git repository such as GitHub, Gitlab and Bitbucket, which we'll explain in the later sections of this blog. For private repositories, Oauth or Personal Access token needs to be setup before starting a workspace. For more information, see Oauth and Using a Git-provider access token.

    OpenShift Dev Spaces dashboard
    Figure 7. OpenShift Dev Spaces dashboard

  2. Click .NET to start the .NET workspace. 

    Start .Net workspace
    Figure 8. Start .Net workspace

    When you start a workspace, pods are created which contain the details of the workspace as shown below:

    Pod details for .NET workspace.
    Fig 9. Pod details for .NET workspace

    Your workspace is now started! You will see the IDE with the sample .NET project, as shown in Figure 10 below. The IDE consists of:

    •  The Explorer which lists the files from the sample project or a git repository.
    • The Search option that can be used to find a particular line of code from the sample project or a repository.
    • The Source control section that can be used to perform git operations (push, pull, commit etc)
    • The Run and Debug section that can be used for debugging the application.
    • Numerous extensions can be installed from the Extensions section. These extensions provide language, tools, and debugging support to the workspace.
      • Some of the language support features include code completion, error syntax highlighting and code navigation.
      • Tools such as ‘Dependency Analytics’ provides vulnerability detection capabilities to the workspace.
      • Extensions can also be used for debugging the projects added to the workspace.

    For more Information, see Extensions for Microsoft Visual Studio Code - Open Source.

    Note: For .NET, debugging and language support is currently not supported on IBM Power, since the extension is incompatible.

    Workspace IDE for .NET project
    Figure 10. Workspace IDE for .NET project
  3. You can run the dotnet commands from the workspace terminal. To create a new terminal in the workspace click, Menu>Terminal>New Terminal or use the keyboard shortcut Ctrl+Shift+'
    Open new terminal in .NET workspace
    Figure 11. Open new terminal in .NET workspace

    You can run the dotnet commands from the workspace terminal.

    Run .NET commands from terminal
    Figure 12. Run .NET commands from terminal

  4. Click Open in New Tab to open the .NET application after you enter the run command. 

    Output of the dotnet run command
    Figure 13. Output of the dotnet run command

     

Step 4. Start .NET workspace using Git repository

If you do not want to use a sample project, you can import your own project using a Git repository.

  1. Click Create Workspace to start a workspace, add your Git URL in the Git Repo URL section, and then click Create & Open.

    Import Git Repo URL
    Figure 14. Import Git Repo URL
  2. After the workspace starts, you can perform Git operations such as commit, pull, fetch, push, rebase and etc.

    .NET workspace using Git repo
    Figure 15. .NET workspace using Git repo

Summary

That brings us to the end of this blog! We hope you are feeling more confident now that you've learned how to install OpenShift Dev Spaces on Red Hat OpenShift Cluster Platform on Power. You can now try your hand at starting a sample workspace for .NET using the OpenShift Dev Spaces dashboard. You should also be able to start a workspace using a public repository from GitHub.

If you do start a workspace using one of the sample projects  on the dashboard or by using the Git URL from git providers like GitHub, Bitbucket, or Gitlab, do tell us about your experience!

Permalink