Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Using a custom devfile registry and C++ with Red Hat CodeReady Workspaces

April 14, 2021
Mary Cochran
Related topics:
ContainersDevOpsKubernetes
Related products:
Developer Toolset

    Red Hat CodeReady Workspaces provides teams with predefined workspaces to streamline application development. Out of the box, CodeReady Workspaces supports numerous languages and plugins. However, many organizations want to customize a workspace and make it available to developers across the organization as a standard. In this article, I show you how to use a custom devfile registry to customize a workspace for C++ development. Once that's done, we will deploy an example application using Docker.

    Note: A devfile dictates which project is in the environment, which tools are available in the terminal, and more. For more information, please refer to the CodeReady Workspaces documentation.

    Setting up the workspace

    To get started with the example in this article, fork the following repository:

    https://github.com/redhat-developer/codeready-workspaces

    Enter the codeready-workspaces/dependencies/che-devfile-registry/devfiles directory, which holds the configuration files for each stack or plugin. There are two configuration files for each stack or plugin: devfile.yaml and meta.yaml. For the purposes of this example, simply copy the 05_cpp folder to a new folder named 05_custom_cpp. From there, you can edit the files to meet your needs:

    $ cd dependencies/che-devfile-registry/devfiles/
    $ cp -r 05_cpp 05_custom_cpp
    $ cd 05_custom_cpp/
    $ ls
    devfile.yaml meta.yaml

    The meta.yaml file stays largely the same, but you can edit the display name and description. Here is my meta.yaml:

    ---
    displayName: C/C++ Hello
    description: C and C++ Developer Tools stack with GCC 8.3.1, cmake 3.11.4 and make 4.2.1
    tags: ["UBI8", "C", "C++", "clang", "GCC", "g++", "make", "cmake"]
    icon: /images/type-cpp.svg
    globalMemoryLimit: 1686Mi
    

    You will make more updates in the devfile.yaml file. For this example, we'll simply update the project that gets imported to the workspace automatically, like so:

    ---
    apiVersion: 1.0.0
    metadata:
      generateName: cpp-custom-
    projects:
      -
        name: Hello
        source:
          type: git
          location: 'https://github.com/mmistretta/hello.git'
    components:
    

    If you want to change the stack even further, you can update things such as the Docker image, the plugins, and even the commands that developers can run with a click of a button. For example, to install Docker or Podman for use in the stack, edit the Docker image to be a custom one. The Dockerfile for the stacks-cpp-rhel8 used for this stack can be found at the Red Hat CodeReady Workspaces - C/C++ Stack web page and customized from there.

    Save your files before proceeding to the next task.

    Building your devfile registry image

    Next, you need to build the registry image. For this example, we will use Docker and the Red Hat Universal Base Image (UBI). From the codeready-workspaces/dependencies/che-devfile-registry directory, run the following commands to build an image and push it to your registry. Replace the italicized text below with the appropriate values for your environment:

    $ ./build --organization your-org --registry your_registry --tag version --rhel
    $ docker push your-image
    

    To ensure your image is valid, you can test it by running:

    $ docker run your-image
    

    Now, you can utilize your custom devfile registry.

    Creating your Che Cluster for CodeReady Workspaces

    Now, make sure the CodeReady Workspaces Operator is installed. As an admin user, search for the Operator in the Red Hat OpensShift OperatorHub, as shown in Figure 1.

    Find and select the CodeReady Workspaces Operator in the OperatorHub
    Figure 1: Find and select the CodeReady Workspaces Operator in the OperatorHub.

    Install the Operator as shown in Figure 2.

    Install the CodeReady Workspaces Operator
    Figure 2: Install the CodeReady Workspaces Operator.

    After installing the Operator, select it. Then, select  Provided APIs—>CodeReady Workspaces Cluster and click the Create Instance link, as shown in Figure 3.

    From Provided APIs->CodeReady Workspaces Cluster, click on the Create Instance link to start creating your instance.
    Figure 3: Start creating your instance with the Create Instance link.

    Select Yaml View as the "Configure via" option, as shown in Figure 4.

    Select the YAML view as the configuration option
    Figure 4: Select the YAML view as the configuration option.

    Now, edit the YAML file created by this process. Scroll down to the server section and replace the devfileRegistryImage entry with your image, as shown here:

    server:
      pluginRegistryImage: ''
      selfSignedCert: false
      devfileRegistryImage: 'quay.io/mcochran/che-devfile-registry:1.2'
      tlsSupport: true
      cheFlavor: codeready
      cheImageTag: ''
    

    Click Create and wait several minutes for the Che cluster to become available. Figure 5 shows the screen that CodeReady Workspaces displays upon successful creation.

    The displayed properties of a CodeReady Workspaces cluster
    Figure 5: The displayed properties of a CodeReady Workspaces cluster.

    Using the workspace

    Click on your CodeReady Workspaces URL and log in to the cluster. If you've left the default permissions in place during the cluster configuration, you can log in as any OpenShift user. If prompted, select "Allow the selected permissions." On the Getting Started landing page, you will then see the custom C++ stack you created (denoted by a red arrow in Figure 6).

    Available workspaces, including the one you've just created
    Figure 6: Available workspaces, including the one you've just created.

    Select the workspace and watch it spin up. When it opens, you should see the Hello project that you specified in the devfile. Here, you can inspect some of the files, such as hello-main.cpp:

    
    #include <iostream>
    
    int main(int argc, char const *argv[])
    {
       std::cout << "Hello Docker container!" << std::endl;
       return0;
    }
    

    Now, you can open a terminal to compile and run the code, as shown in the following example. You can also compile and run counter-main.cpp or any other C++ code:

    $ cd Hello/
    $ make hello-main
    $ ./hello-main
    

    You should see the program print a "Hello Docker container!" message and then terminate. At this point in development, you could make any changes you would like to see in the code, compile it, run it, and push your changes to Git, which could kick off a pipeline to deploy to OpenShift.

    Deploying the application as a Docker instance

    In this example, you do not have Docker tools installed in your CodeReady Workspaces stack, but Docker is installed using the Dockerfile in your Hello Git project. If you would like to test some C++ code in an environment with Docker tooling, enter commands like the following. In this example, rhsm.secret.yaml contains my credentials for my registry, and I am using quay.io with the organization mcochran as my registry. Be sure to replace these variables with the ones for your own environment:

    $ DOCKER_BUILDKIT=1 docker build --progress=plain --secret id=rhsm,src=rhsm.secret.yaml -t quay.io/mcochran/cpp-hello:latest -f Dockerfile .
    $ docker push quay.io/mcochran/cpp-hello:latest
    

    Then, create a pod.yaml file to deploy your code using the Docker image:

    apiVersion: v1
    kind: Pod
    metadata:
      labels:
        app: hello-cpp
      name: hello-cpp-exec
    spec:
      containers:
      - name: hello-cpp
        image: quay.io/mcochran/cpp-hello
        livenessProbe:
          exec:
            command:
            - cat
            - /tmp/healthy
          initialDelaySeconds: 5
          periodSeconds: 5
      restartPolicy: Never
    

    Save your file, then log in to OpenShift from the command line and deploy the pod:

    $ oc login
    $ oc create -f pod.yaml
    

    Because this code simply says "hello," the pod will run quickly. You can review the logs afterward for pods that have shut down in the workloads—>pods section of the admin console.

    Summary

    This article has demonstrated how to create a custom devfile registry to make dedicated workspaces available to your team. I showed you how to use a devfile to provide the code and tools appropriate to your environment, and you've seen how convenient it is to deploy an application in CodeReady Workspaces using Docker.

    Last updated: February 5, 2024

    Recent Posts

    • Protect data offloaded to GPU-accelerated environments with OpenShift sandboxed containers

    • Case study: Measuring energy efficiency on the x64 platform

    • How to prevent AI inference stack silent failures

    • Preventing GPU waste: A guide to JIT checkpointing with Kubeflow Trainer on OpenShift AI

    • How to manage TLS certificates used by OpenShift GitOps operator

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.