Chapter 5. Using Red Hat OpenShift Dev Spaces for application development


Red Hat OpenShift Dev Spaces is a web-based IDE that you can use to develop applications. It provides developers and other IT team members with a consistent, secure, and zero-configuration development environment. OpenShift Dev Spaces includes Microsoft Visual Studio Code, and JetBrains IntelliJ IDEA integrated development environments (IDE).

You can use devfile to define different aspects of your workspace , such as the following:

  • Resource allocation
  • Pre-defined commands to build, test, debug, and run applications
  • Containers with development tools
  • Containers or Kubernetes manifests for services required for testing
  • Workspace start and stop events
  • Source code repositories
Note

The following procedures demonstrate the minimum required OpenShift Dev Spaces configurations to build, run, and debug your application in OpenShift Dev Spaces and also describe how to deploy your application to OpenShift Container Platform. For a complete list of configuration options, see product documentation for Red Hat OpenShift Dev Spaces.

To get started with using OpenShift Dev Spaces for developing JBoss EAP applications, follow these procedures:

Create a devfile in your application to configure a Red Hat OpenShift Dev Spaces workspace for your application. The devfile defines different aspects of your workspace such as source code repositories, resource allocation, containers with development tools, and so on.

This procedure uses Visual Studio Code as the integrated development environment (IDE) and defines both innerloop and outerloop commands. Innerloop commands refer to the commands that run within the OpenShift Dev Spaces workspace and outerloop commands are those that deploy your application externally.

Note

The following procedure describes the minimum steps required to get started with developing JBoss EAP applications in OpenShift Dev Spaces. For more information, see product documentation for Red Hat OpenShift Dev Spaces.

Prerequisites

Procedure

  1. Create a devfile, named devfile.yaml, at the root of the repository.
  2. Add schema and metadata information to the devfile.

    schemaVersion: 2.2.0               
    1
    
    metadata:                          
    2
    
      name: <workspace-name>           
    3
    
      version: <version>               
    4
    
      displayName: <display-name>      
    5
    1
    The schema version of the devfile.
    2
    Define metadata for your workspace.
    3
    Define a name for your workspace.
    4
    Define the version of the devfile.
    5
    Define the display name to use on a devfile registry.
  3. Define variables. You can use the value of the variable throughout the devfile by referencing the variable.

    variables:
      imageRegistry: 'image-registry.openshift-image-registry.svc:5000'       
    1
    
      imageName: 'helloworld'        
    2
    
      nodeName: 'helloworld'         
    3
    
      target-namespace: 'getting-started' 
    4
    1
    Define the registry to which you want to deploy your application image. The example uses the internal OpenShift registry.
    2
    Define a name for the image that will be built for the application.
    3
    Define a name for the node that will contain the application.
    4
    The namespace in which the application is to be deployed.
  4. Incorporate tools into the workspace for building your application within the workspace.

    Note

    When running OpenShift Dev Spaces in the developer sandbox, you can only use the predefined namespace. Therefore, you must comment out the following lines inside the env definition:

    - name: TARGET_NAMESPACE
     .value: '{{target-namespace}}'
    components:                       
    1
    
      - name: tools
        container:                    
    2
    
          image: registry.redhat.io/devspaces/udi-rhel8:3.11-14
          memoryLimit: 1512Mi
          mountSources: true
          volumeMounts:
            - name: m2
              path: /home/user/.m2
          env:                        
    3
    
            - name: JAVA_OPTS
              value: '-Djava.security.egd=file:/dev/urandom -Djboss.host.name=localhost'
            - name: DEBUG_PORT
              value: '5005'
            - name: NODE_NAME
              value: '{{nodeName}}'
            - name: IMAGE_REGISTRY
              value: '{{imageRegistry}}'
            - name: IMAGE
              value: '{{imageName}}'
            - name: TARGET_NAMESPACE
             .value: '{{target-namespace}}'
            - name: VSCODE_DEFAULT_WORKSPACE
              value: /projects/wildfly-devfile-examples/.code-workspace
            - name: USE_JAVA17
              value: 'true'
          endpoints:                  
    4
    
            - name: debug
              exposure: internal
              protocol: tcp
              targetPort: 5005
            - name: 'http'
              protocol: http
              targetPort: 8080
              exposure: public
            - name: 'management'
              targetPort: 9990
              protocol: http
              exposure: internal
            - name: 'transactions'
              targetPort: 4172
              protocol: tcp
              exposure: internal
      - name: m2                     
    5
    
        volume:
          size: 3Gi
    1
    Define a component named tools of the type container.
    2
    Use the udi-rhel8:3.11-14 UDI container from the registry.redhat.io/devspaces registry with the specified configuration.
    3
    Define environment variables.
    4
    Define the container endpoints as follows:
    • exposure: Define how the endpoint should be exposed on the network.
    • protocol: Define the application and transport protocols of the traffic that will go through this endpoint.
    • targetPort: The port number to be used within the container component. The same port cannot be used by two different container components.
    5
    Define a volume component. This is used in the tools component to mount the Maven repository.
  5. Add innerloop and outerloop commands.

    commands:
      - id: package            
    1
    
        exec:
          label: "InnerLoop 01 - Build the application"
          component: tools
          commandLine: mvn clean package -Popenshift -Dmaven.wagon.http.ssl.insecure=true
          workingDir: ${PROJECT_SOURCE}/helloworld
          group:
            kind: build
            isDefault: true
      - id: run                
    2
    
        exec:
          label: "InnerLoop 02 - Run the application in dev mode"
          component: tools
          commandLine: ./target/server/bin/standalone.sh -Djboss.host.name=${NODE_NAME}
          workingDir: ${PROJECT_SOURCE}/helloworld
          group:
            kind: run
            isDefault: true
      - id: debug              
    3
    
        exec:
          label: "InnerLoop 03 - Debug the application in dev mode"
          component: tools
          commandLine: ./target/server/bin/standalone.sh -Djboss.host.name=${NODE_NAME} --debug
          workingDir: ${PROJECT_SOURCE}/helloworld
          group:
            kind: debug
            isDefault: true
      - id: shutdown           
    4
    
        exec:
          label: "InnerLoop 04 - Shutdown the server"
          component: tools
          commandLine: ./target/server/bin/jboss-cli.sh -c --command=shutdown
          workingDir: ${PROJECT_SOURCE}/helloworld
          hotReloadCapable: false
          group:
            kind: run
            isDefault: false
      - id: deploy-image       
    5
    
        exec:
          label: "OuterLoop 01 - Deploy Image to OpenShift"
          component: tools
          workingDir: ${PROJECT_SOURCE}/helloworld
          # When using developer sandbox, prefix the following command with export "IMAGE_REGISTRY_NAMESPACE=$(oc project -q) &&" because you can only use the predefined namespace in the developer sandbox
          commandLine: "helm repo add jboss https://jbossas.github.io/eap-charts/ && helm install ${IMAGE} --namespace=${IMAGE_REGISTRY_NAMESPACE} -f ./charts/helm.yaml jboss/eap8"
          group:
            kind: run
            isDefault: false
      - id: undeploy-image     
    6
    
        exec:
          label: "OuterLoop 02 - Undeploy Image from OpenShift"
          component: tools
          workingDir: ${PROJECT_SOURCE}/helloworld
          commandLine: "helm uninstall ${IMAGE}"
          group:
            kind: run
            isDefault: false
    1
    Define a command to build the application. This executes mvn clean package -Popenshift -Dmaven.wagon.http.ssl.insecure=true in the workspace to provision a server with the application deployed to the server.
    2
    Define a command to run the application. This executes ./target/server/bin/standalone.sh -Djboss.host.name=${NODE_NAME} to start the provisioned server within the workspace.
    3
    Define a command to debug the application. This starts the server with the --debug option.
    4
    Define a command to shut down the running server.
    5
    Define a command to deploy the application to OpenShift Container Platform with helm.
    6
    Define a command to undeploy the application from OpenShift Container Platform with helm.
  6. Optionally, configure Visual Studio Code.

    1. Create a directory .vscode for Visual Studio Code configuration.
    2. Navigate to the .vscode directory.

      $ cd .vscode
    3. Create a file extensions.json to configure the extensions to be installed in Visual Studio Code.

      Note

      You might need to configure a registry to install the extensions. For more information, see Managing IDE extensions in the OpenShift Dev Spaces Administration guide guide.

      {
        // See https://go.microsoft.com/fwlink/?LinkId=827846
        // for the documentation about the extensions.json format
        "recommendations": [
          "redhat.java",
          "vscjava.vscode-java-debug",
          "vscjava.vscode-java-test",
          "redhat.fabric8-analytics",
          "cnshenj.vscode-task-manager" 
      1
      
        ]
      }
      1
      Task manager extension. Provides a custom activity view for the commands in the devfile.
    4. Create a file launch.json to configure a debug session in Visual Studio Code.

      {
        "version": "0.2.0",
        "configurations": [
          {
            "type": "java",
            "name": "Attach to running server",
            "request": "attach",
            "hostName": "localhost",
            "port": 5005
          }
        ]
      }
  7. Create a file settings.json.

    {
      "java.server.launchMode": "Standard",
      "editor.codeActionsOnSave": {
      }
    }
  8. Push the changes to your repository.

After you create a workspace in OpenShift Dev Spaces, ensure that your application builds correctly. The InnerLoop 01 - Build the application command defined in the devfile runs the Maven package goal to provision a server with the application deployed.

Prerequisites

Procedure

  • To build the application, use the InnerLoop 01 - Build the application command.

    • If you have installed the optional task manager Visual Studio Code extension:

      1. On the Activity Bar, click the Task Manager icon. The list of commands you defined in the devfile are displayed.
      2. Select InnerLoop 01 - Build the application and click the Run Task icon that is displayed.
    • Otherwise:

      1. Press the F1 key.
      2. In the search field that is displayed, enter "run task".
      3. From the results, select Tasks: Run task.
      4. In the search field, enter "devfile".
      5. From the results, select InnerLoop 01 - Build the application.

        The application will start building and the progress will be displayed in the Visual Studio Code terminal.

Verification

  • Inspect the Visual Studio Code terminal output. You should see a build success message like the following:

    [INFO] Copy deployment /projects/test/helloworld/target/helloworld.war to /projects/test/helloworld/target/server/standalone/deployments/ROOT.war
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  27.889 s
    [INFO] Finished at: 2024-04-29T10:31:45Z
    [INFO] ------------------------------------------------------------------------

Ensure that your application runs properly in OpenShift Dev Spaces before you deploy it to OpenShift Container Platform. The InnerLoop 02 - Run the application in dev mode command defined in the devfile starts the provisioned server.

Prerequisites

Procedure

  1. To run the application, use the InnerLoop 02 - Run the application in dev mode command .

    • If you have installed the optional task manager Visual Studio Code extension:

      1. On the Activity Bar, click the Task Manager icon. The list of commands you defined in the devfile are displayed.
      2. Select InnerLoop 02 - Run the application in dev mode and click the Run Task icon that is displayed.
    • Otherwise:

      1. Press the F1 key.
      2. In the search field that is displayed, enter "run task".
      3. From the results, select Tasks: Run task.
      4. In the search field, enter "devfile".
      5. From the results, select InnerLoop 02 - Run the application in dev mode.
  2. In the pop-up window that is displayed with the following message, click no:

    A new process is now listening on port 4712 but is listening on interface ::ffff:7f00:1 which is internal. You should change to be remotely available. Would you want to add a redirect for this port so it becomes available ?

  3. In the pop-up window that is displayed with the following message, click Open In New Tab:

    Process http is now listening on port 8080. Open it ?

Verification

  • You will see "Hello World!" in the new tab.

Being able to set breakpoints in the source when debugging is necessary to pause the debugger and examine the call stack or values of variables. You can also add breakpoints to specific lines of the application source code in OpenShift Dev Spaces when debugging. The InnerLoop 03 - Debug the application in dev mode command defined in the devfile starts the provisioned server in debug mode.

Prerequisites

Procedure

  1. To add a breakpoint, click in the left margin of the editor, next to the required line of code. A red dot is displayed in the margin to mark the breakpoint you added.
  2. To debug the application, use the InnerLoop 03 - InnerLoop 03 - Debug the application in dev mode command .

    • If you have installed the optional task manager Visual Studio Code extension:

      1. On the Activity Bar, click the Task Manager icon. The list of commands you defined in the devfile are displayed.
      2. Select InnerLoop 03 - InnerLoop 03 - Debug the application in dev mode and click the Run Task icon that is displayed.
    • Otherwise:

      1. Press the F1 key.
      2. In the search field that is displayed, enter "run task".
      3. From the results, select Tasks: Run task.
      4. In the search field, enter "devfile".
      5. From the results, select InnerLoop 03 - Debug the application in dev mode .

To free up resources, stop the application running in OpenShift Dev Spaces.

Prerequisites

Procedure

  • To stop the server, use the InnerLoop 04 - Shutdown the server command.

    • If you have installed the optional task manager Visual Studio Code extension:

      1. On the Activity Bar, click the Task Manager icon. The list of commands you defined in the devfile are displayed.
      2. Select InnerLoop 04 - Shutdown the server and click the Run Task icon that is displayed.
    • Otherwise:

      1. Press the F1 key.
      2. In the search field that is displayed, enter "run task".
      3. From the results, select Tasks: Run task.
      4. In the search field, enter "devfile".
      5. From the results, select InnerLoop 04 - Shutdown the server.

Deploy your application to OpenShift Container Platform by using helm. The OuterLoop 01 - Deploy Image to OpenShift command defined in the devfile uses helm to deploy the application to OpenShift Container Platform. The helm chart, helm.yaml, defined in your application is used for the deployment.

Prerequisites

Procedure

  • To deploy your application to OpenShift Container Platform, use the OuterLoop 01 - Deploy Image to OpenShift command .

    • If you have installed the optional task manager Visual Studio Code extension:

      1. On the Activity Bar, click the Task Manager icon. The list of commands you defined in the devfile are displayed.
      2. Select OuterLoop 01 - Deploy Image to OpenShift and click the Run Task icon that is displayed.
    • Otherwise:

      1. Press the F1 key.
      2. In the search field that is displayed, enter "run task".
      3. From the results, select Tasks: Run task.
      4. In the search field, enter "devfile".
      5. From the results, select OuterLoop 01 - Deploy Image to OpenShift.

        You get the following output:

        Your application is building! To follow the build, run:
        
        $ oc get build -w
        
        Note that your Deployment will report "ErrImagePull" and "ImagePullBackOff" until the build is complete. Once the build is complete, your image will be automatically rolled out.
        
        To follow the deployment of your application, run:
        
        $ oc get deployment helloworld -w
         *  Terminal will be reused by tasks, press any key to close it.

Verification

  1. Obtain the application URL.

    $ oc get route helloworld
  2. Navigate to the URL.

    You get the following output:

    Hello World!

You can undeploy your application from OpenShift Container Platform in OpenShift Dev Spaces.

Prerequisites

Procedure

  • To undeploy your application from OpenShift Container Platform, use the OuterLoop 02 - Undeploy Image from OpenShift command.

    • If you have installed the optional task manager Visual Studio Code extension:

      1. On the Activity Bar, click the Task Manager icon. The list of commands you defined in the devfile are displayed.
      2. Select OuterLoop 02 - Undeploy Image from OpenShift and click the Run Task icon that is displayed.
    • Otherwise:

      1. Press the F1 key.
      2. In the search field that is displayed, enter "run task".
      3. From the results, select Tasks: Run task.
      4. In the search field, enter "devfile".
      5. From the results, select OuterLoop 02 - Undeploy Image from OpenShift.

After you undeploy the application, it is no longer available for clients.





Revised on 2025-05-08 10:45:47 UTC

Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat Documentation

Legal Notice

Theme

© 2026 Red Hat
Back to top