Using devfiles in odo

    With the devfile, you can describe your development environment, such as the source code, IDE tools, application runtimes, and predefined commands. To learn more about the devfile, see the devfile documentation.

    With , you can create components from the devfiles. When creating a component by using a devfile, odo transforms the devfile into a workspace consisting of multiple containers that run on OKD, Kubernetes, or Docker. odo automatically uses the default devfile registry but users can add their own registries.

    Prerequisites

    • You have installed odo.

    • You must know your ingress domain cluster name. Contact your cluster administrator if you do not know it. For example, apps-crc.testing is the cluster domain name for .

    Create a project to keep your source code, tests, and libraries organized in a separate single unit.

    Procedure

    1. Log in to an OKD cluster:

    2. Create a project:

      1. $ odo project create myproject

      Example output

      1. Project 'myproject' is ready for use
      2. New project created and now using project : myproject

    With odo, you can display all the components that are available for you on the cluster. Components that are available depend on the configuration of your cluster.

    1. To list available devfile components on your cluster, run:

      1. $ odo catalog list components

      The output lists the available odo components:

      1. Odo Devfile Components:
      2. NAME DESCRIPTION REGISTRY
      3. java-maven Upstream Maven and OpenJDK 11 DefaultDevfileRegistry
      4. java-openliberty Open Liberty microservice in Java DefaultDevfileRegistry
      5. java-quarkus Upstream Quarkus with Java+GraalVM DefaultDevfileRegistry
      6. java-springboot Spring Boot® using Java DefaultDevfileRegistry
      7. nodejs Stack with NodeJS 12 DefaultDevfileRegistry
      8. Odo OpenShift Components:
      9. NAME PROJECT TAGS SUPPORTED
      10. java openshift 11,8,latest YES
      11. dotnet openshift 2.1,3.1,latest NO
      12. nginx openshift 1.14-el7,1.14-el8,1.16-el7,1.16-el8,latest NO
      13. nodejs openshift 10-ubi7,10-ubi8,12-ubi7,12-ubi8,latest NO
      14. perl openshift 5.26-el7,5.26-ubi8,5.30-el7,latest NO
      15. php openshift 7.2-ubi7,7.2-ubi8,7.3-ubi7,7.3-ubi8,latest NO
      16. python openshift 2.7-ubi7,2.7-ubi8,3.6-ubi7,3.6-ubi8,3.8-ubi7,3.8-ubi8,latest NO
      17. ruby openshift 2.5-ubi7,2.5-ubi8,2.6-ubi7,2.6-ubi8,2.7-ubi7,latest NO
      18. wildfly openshift 10.0,10.1,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,8.1,9.0,latest NO

    In this section, you will learn how to deploy a sample Java project that uses Maven and Java 8 JDK using a devfile.

    Procedure

    1. Create a directory to store the source code of your component:

      1. $ mkdir <directory-name>
    2. Create a component configuration of Spring Boot component type named myspring and download its sample project:

      1. $ odo create java-springboot myspring --starter

      The previous command produces the following output:

      The odo create command downloads the associated devfile.yaml file from the recorded devfile registries.

    3. List the contents of the directory to confirm that the devfile and the sample Java application were downloaded:

      1. $ ls

      The previous command produces the following output:

      1. README.md devfile.yaml pom.xml src
    4. Create a URL to access the deployed component:

      1. $ odo url create --host apps-crc.testing

      The previous command produces the following output:

      1. URL myspring-8080.apps-crc.testing created for component: myspring
      2. To apply the URL configuration changes, please use odo push
      1. $ odo push

      The previous command produces the following output:

      1. Validation
      2. Validating the devfile [81808ns]
      3. Creating Kubernetes resources for component myspring
      4. Waiting for component to start [5s]
      5. URL myspring-8080: http://myspring-8080.apps-crc.testing created
      6. Syncing to component myspring
      7. Checking files for pushing [2ms]
      8. Syncing files to the component [1s]
      9. Executing devfile commands for component myspring
      10. Executing devbuild command "/artifacts/bin/build-container-full.sh" [1m]
      11. Executing devrun command "/artifacts/bin/start-server.sh" [2s]
      12. Pushing devfile component myspring
      13. Changes successfully pushed to component
    5. List the URLs of the component to verify that the component was pushed successfully:

      The previous command produces the following output:

      1. Found the following URLs for component myspring
      2. NAME URL PORT SECURE
      3. myspring-8080 http://myspring-8080.apps-crc.testing 8080 false
    6. View your deployed application by using the generated URL:

      1. $ curl http://myspring-8080.apps-crc.testing

    With odo, you can create both Source-to-Image (S2I) and devfile components. If you have an existing S2I component, you can convert it into a devfile component using the odo utils command.

    Procedure

    Run all the commands from the S2I component directory.

    1. Run the odo utils convert-to-devfile command, which creates devfile.yaml and env.yaml based on your component:

      1. $ odo utils convert-to-devfile
    2. Push the component to your cluster:

      1. $ odo push
    3. Verify that the devfile component deployed successfully:

      1. $ odo list
    4. Delete the S2I component: