1

How to create a Rust application on OpenShift

 1 year ago
source link: https://www.redhat.com/sysadmin/create-rust-application-openshift
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to create a Rust application on OpenShift

With the help of a container and OpenShift's "import from Git" functionality, you can onboard a Rust application onto OpenShift quickly.

Posted: June 22, 2022 | by Nicole Lama (Red Hat)

Image
Rusty chain and padlock

In my previous article, I introduced Rust, explained how to install it, and created a simple Rust project. With the help of a container and OpenShift's "import from Git" functionality, you can onboard a Rust application onto OpenShift quickly.

[ Keep Rust syntax and tips on hand with this free Rust cheat sheet. ]

You can find the Rust project used in this example in my GitHub repository. The code is based on a repo created by the development team at Actix, a web framework for Rust. The most important files inside the repo include the dockerfile, Cargo.toml, and src/main.rs:

  1. The dockerfile pulls the latest Rust image and runs the cargo build command.
  2. The Cargo.toml file includes the Actix web dependency and package information.
  3. The main.rs script contains the web server code, which displays "Hello, Openshift!" on port 8080.

Onboard Rust using OpenShift Web Console

Image
Rust on OpenShift

(Nicole Lama, CC BY-SA 4.0)

Cargo builds the project in five to 10 minutes. You must have these OpenShift resources:

  • One pod in the completed stage to build the Rust application
  • One pod in the running stage to run the Rust web server
  • One service
  • One route to expose the Rust application

Access the route to the application under the Networking tab on the OpenShift Web Console. Copy and paste the URL into your local browser to see a "Hello OpenShift!" message.

Image
Rust Hello OpenShift success message

(Nicole Lama, CC BY-SA 4.0)

Congratulations! You have successfully onboarded your first Rust application on OpenShift. If you are interested in contributing to the Rust community, please visit the Rust Programming Language Handbook and Rustaceans.org for more information on becoming an official Rustacean.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK