On December 7, 2023, Google released the following video on using Rust for Cloud Run applications. This is an excellent getting started video. I have been working directly with the Google Cloud Run team since the beta release. I thought I would write an article taking their video, and JK Gunnink’s repository and article and take it to the next level.

This article is Part 2 of a three-part article. The first part implements container multi-stage builds. The second part updates the application to use the latest version of the Cargo package Hyper. The third part extends the application with new features.

Note: I am very experienced with Google Cloud and Docker, but I am a beginner with the Rust language.

Objectives

  • Update the version of the hyper Cargo package used to build the Cloud Run application. The article uses Hyper version 0.14. The latest version is 1.0.1.

Endpoint Summary

  • / – Return the Hello, Rustless! message.

Clone the repository

I will start by cloning JK Gunnink’s repository.

Next, we need to update the dependencies to support hyper version 1.

Original Cargo.toml

Modified Cargo.toml

The modified version adds two dependencies:

  • hyper-body-util
  • hyper-util

HTTP Body (hyper-body-util) is a trait representing asynchronous operations on an HTTP body. The cargo information page is here.

Hyper Utilities (hyper-util) is a collection of utilities to do common things with hyper. The cargo information page is here.

Those dependencies are required to use hyper version 1.

Use improved multi-stage Dockerfile

This step is not required. This step does provide for a significant reduction in container image size.

Copy the Dockerfile that I modified in part 1 of this article series.

Replace the source code in the file src/main.rs with this content:

The new source code provides the same features as the original but is updated to fit the new features in hyper version 1.

Build the container

Run the container

Test the container

Excellent, the new source code works correctly.

Build and Deploy to Cloud Run

Go to the Cloud Run Service URL. In my case it is https://rustless-e2v2ixiywa-uc.a.run.app/

Summary

This article shows how to update the repository source code to use the new version of hyper. Hyper version 1 made many changes that required a rewrite of the application.

More Information

Photography Credit

I write free articles about technology. Recently, I learned about Pexels.com which provides free images. The image in this article is courtesy of Pixabay at Pexels. Note: This is the same image used in JK Gunnink’s article.