This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.2.8. Using devfiles in odo
Creating applications by using devfiles with `odo` is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
For more information about the support scope of Red Hat Technology Preview features, see https://access.redhat.com/support/offerings/techpreview/.
2.8.1. About the devfile in odo 复制链接链接已复制到粘贴板!
The devfile is a portable file that describes your development environment. With the devfile, you can define a portable developmental environment without the need for reconfiguration.
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 odo, 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 OpenShift Container Platform, Kubernetes, or Docker. odo automatically uses the default devfile registry but users can add their own registries.
2.8.2. Creating a Java application by using a devfile 复制链接链接已复制到粘贴板!
2.8.3. 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.testingis the cluster domain name for Red Hat CodeReady Containers. You have enabled Experimental Mode in
odo.-
To enable Experimental Mode in
odopreferences, runodo preference set Experimental trueor use the environment variableodo config set --env ODO_EXPERIMENTAL=true
-
To enable Experimental Mode in
2.8.3.1. Creating a project 复制链接链接已复制到粘贴板!
Create a project to keep your source code, tests, and libraries organized in a separate single unit.
Procedure
Log in to an OpenShift Container Platform cluster:
odo login -u developer -p developer
$ odo login -u developer -p developerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a project:
odo project create myproject
$ odo project create myprojectCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
✓ Project 'myproject' is ready for use ✓ New project created and now using project : myproject
✓ Project 'myproject' is ready for use ✓ New project created and now using project : myprojectCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.8.3.2. Listing available devfile components 复制链接链接已复制到粘贴板!
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.
Procedure
To list available devfile components on your cluster, run:
odo catalog list components
$ odo catalog list componentsCopy to Clipboard Copied! Toggle word wrap Toggle overflow The output lists the available
odocomponents:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.8.3.3. Deploying a Java application using a devfile 复制链接链接已复制到粘贴板!
In this section, you will learn how to deploy a sample Java project that uses Maven and Java 8 JDK using a devfile.
Procedure
Create a directory to store the source code of your component:
mkdir <directory-name>
$ mkdir <directory-name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a component configuration of Spring Boot component type named
myspringand download its sample project:odo create java-spring-boot myspring --starter
$ odo create java-spring-boot myspring --starterCopy to Clipboard Copied! Toggle word wrap Toggle overflow The previous command produces the following output:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
odo createcommand downloads the associateddevfile.yamlfile from the recorded devfile registries.List the contents of the directory to confirm that the devfile and the sample Java application were downloaded:
ls
$ lsCopy to Clipboard Copied! Toggle word wrap Toggle overflow The previous command produces the following output:
README.md devfile.yaml pom.xml src
README.md devfile.yaml pom.xml srcCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a URL to access the deployed component:
odo url create --host apps-crc.testing
$ odo url create --host apps-crc.testingCopy to Clipboard Copied! Toggle word wrap Toggle overflow The previous command produces the following output:
✓ URL myspring-8080.apps-crc.testing created for component: myspring To apply the URL configuration changes, please use odo push
✓ URL myspring-8080.apps-crc.testing created for component: myspring To apply the URL configuration changes, please use odo pushCopy to Clipboard Copied! Toggle word wrap Toggle overflow 注意You must use your cluster host domain name when creating the URL.
Push the component to the cluster:
odo push
$ odo pushCopy to Clipboard Copied! Toggle word wrap Toggle overflow The previous command produces the following output:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow List the URLs of the component to verify that the component was pushed successfully:
odo url list
$ odo url listCopy to Clipboard Copied! Toggle word wrap Toggle overflow The previous command produces the following output:
Found the following URLs for component myspring NAME URL PORT SECURE myspring-8080 http://myspring-8080.apps-crc.testing 8080 false
Found the following URLs for component myspring NAME URL PORT SECURE myspring-8080 http://myspring-8080.apps-crc.testing 8080 falseCopy to Clipboard Copied! Toggle word wrap Toggle overflow View your deployed application by using the generated URL:
curl http://myspring-8080.apps-crc.testing
$ curl http://myspring-8080.apps-crc.testingCopy to Clipboard Copied! Toggle word wrap Toggle overflow
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.
Run the
odo utils convert-to-devfilecommand, which createsdevfile.yamlandenv.yamlbased on your component:odo utils convert-to-devfile
$ odo utils convert-to-devfileCopy to Clipboard Copied! Toggle word wrap Toggle overflow Push the component to your cluster:
odo push
$ odo pushCopy to Clipboard Copied! Toggle word wrap Toggle overflow 注意If the devfile component deployment failed, delete it by running:
odo delete -aVerify that the devfile component deployed successfully:
odo list
$ odo listCopy to Clipboard Copied! Toggle word wrap Toggle overflow Delete the S2I component:
odo delete --s2i
$ odo delete --s2iCopy to Clipboard Copied! Toggle word wrap Toggle overflow