Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Developing your own custom devfiles for odo 2.0

February 12, 2021
Gorkem Ercan
Related topics:
JavaContainersDeveloper ToolsKubernetesEvent-Driven

Share:

    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

    • Migrating Ansible Automation Platform 2.4 to 2.5

    • Multicluster resiliency with global load balancing and mesh federation

    • Simplify local prototyping with Camel JBang infrastructure

    • Smart deployments at scale: Leveraging ApplicationSets and Helm with cluster labels in Red Hat Advanced Cluster Management for Kubernetes

    • How to verify container signatures in disconnected OpenShift

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    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
    © 2025 Red Hat

    Red Hat legal and privacy links

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

    Report a website issue