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.
    • 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

Developing your own custom devfiles for odo 2.0

February 12, 2021
Gorkem Ercan
Related topics:
JavaContainersDeveloper toolsKubernetesEvent-driven

    Odo 2.0 introduces a configuration file named devfile.yaml. Odo uses this configuration file to set up cloud-native projects and determine the actions required for events such as building, running, and debugging a project. If you are an Eclipse Che user, devfile.yaml should sound familiar: Eclipse Che uses devfiles to express developer workspaces, and they have proven to be flexible to accommodate a variety of needs.

    Odo 2.0 comes with a built-in catalog of devfiles for various project types, so you do not necessarily need to write or modify a devfile to start a new project. You can also create custom devfiles and contribute them to odo's devfile catalog. This article explores how to create a devfile to adopt an existing development flow to run on a Kubernetes cluster. Our example project is based on Gatsby, a framework for generating websites. Gatsby comes with its own developer tools and recommended development flow, so it presents a good example for adopting existing flows for Kubernetes.

    Note: See Kubernetes integration and more in odo 2.0 for more about devfiles and other new features in this latest release.

    Anatomy of a devfile

    Before we begin working with the example, let’s take a quick look at the anatomy of a devfile.

    Other than the schemaVersion, no other properties are mandatory on a devfile. This flexibility lets developers use devfiles for multiple purposes. A devfile can be generic for a technology base or specific to a project, and projects can inherit and override parts of other devfiles.

    Components, commands, and events are the most commonly used devfile properties:

    • Components describe the parts of the development environment that need to be created. Examples include runtime containers and Kubernetes resources.
    • Commands describe the predefined commands to be used to achieve specific development goals with the provided tools.
    • Events bind commands to the lifecycle of the developer environment. Currently, there are four events: postStart, postStop, preStart, and preStop.

    Implement a devfile

    You've had a quick introduction to devfiles and their three most commonly used properties. Now, let's apply what you've learned. For this example, we will project instructions from the Gatsby documentation into a devfile, which we'll use to develop a website on Kubernetes.

    Select a base image

    Because the application runs as a container, we'll start by selecting a base image and defining it as a component:

    schemaVersion: 2.0.0
    
    components:
    
      - name: gatsby
    
    container:
    
       image: quay.io/eclipse/che-nodejs10-ubi:nightly
    
       mountSources: true
    
       memoryLimit: 700Mi
    
       endpoints:
    
         - name: web
    
           targetPort: 8000
    

    It’s worth mentioning the container's mountSources property. Odo uses this value as a hint for synchronizing your local files to the container running on your Kubernetes cluster.

    Define the commands

    Next, let’s define the commands that we'll use to build and run the application. The two commands that we need to define will run on the application's gatsby component. The gatsby-develop command starts the application in development mode. The setup-gatsby-cli command sets up Gatsby's development tools on the gatsby component:

    commands:
    
      - id: gatsby-develop
    
    exec:
    
       commandLine: "gatsby develop -H 0.0.0.0"
    
       component: gatsby
    
       group:
    
         kind: run
    
       attributes:
    
         restart: "false"
    
      - id: setup-gatsby-cli
    
    exec:
    
       commandLine: "npm install -g gatsby-cli && npm install"
    
       component: gatsby
    

    Define the events

    Finally, we define a postStart event to optimize the setup once a component has started:

    events:
    
      postStart:
    
    - setup-gatsby-cli
    

    Create and push the example application

    Assuming you have odo and the Gatsby CLI installed locally, you can put your newly acquired devfile to work. Here are the commands to create and push a simple Gatsby site using odo:

    gatsby new hello-world https://github.com/gatsbyjs/gatsby-starter-hello-world
    
    cd hello-world
    
    ## create or copy devfile.yaml
    
    ## from https://gist.github.com/gorkem/78fd17864218a125b2bd9146728a1af8
    
    odo push
    

    Conclusion

    While odo comes with a built-in catalog of devfiles, you can also develop your own. Creating custom devfiles lets you integrate the technologies that you work with into the Kubernetes environment. Once you've created a devfile, you can contribute it to the devfile catalog for wider community reach.

    Last updated: February 9, 2021

    Recent Posts

    • Confidential virtual machine storage attack scenarios

    • Introducing virtualization platform autopilot

    • Integrate zero trust workload identity manager with Red Hat OpenShift GitOps

    • Best Practice Configuration and Tuning for Linux and Windows VMs

    • Red Hat UBI 8 builders have been promoted to the Paketo Buildpacks organization

    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