In project 2, the purpose is to build a functional Web Microservice in Rust based on Kubernetes or other similar platforms (Kubernetes Deployments provide a higher-level abstraction for managing the deployment and scaling of applications in a cluster, making it easier to automate and manage the process). I create a simple actix Microservice for movie buffs which can be used for randomly choosing a good classic movie at leisure based on the list of the world top 10 best movies.
This actix Microservice has multiple routes:
A. type: "/" that returns a message : "Hello, random best movies around the world!"
B. type: "/movie" that returns a random best movie in the list of the world top 10 best movies
C. type: "/version" that returns the version of the service
A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated python virtual environments for them.
- Type:
python3 -m venv env
andsource env/bin/activate
- Type:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
and thensource "$HOME/.cargo/env"
- Type:
cargo new (project name)
(my Eg:cargo new src
) - Create main.rs and lib.rs for the src project
- Cargo build: it is a command in the Rust programming language that is used to compile a Rust project. It compiles the project's source code and its dependencies, and produces an executable binary file. The
cargo build
command can be run from the root directory of the project. - Set up Cargo.toml to determine the dependencies and build configuration of the project.
- Set up Dockerfile for APP webdocker
- Create a Makefile: it is a special file that lists a set of rules for compiling a project. These rules include targets, which can be an action make needs to take or the files/objects make will need to build, and the commands that need to be run in order to build that target.
- After creating main.rs and lib.rs, in terminal, directly type:
cargo run
(Press CTRL+C to quit)
-
Usage of an example (Test the URL): https://helenyjx-ubiquitous-guide-v957g7j5xjqfvgx-8080.preview.app.github.dev/movie
-
A. type: "/" that returns a message : "Hello, random best movies around the world!"
- B. type: "/movie" that returns a random best movie in the list of the world top 10 best movies
- C. type: "/version" that returns the version of the service
- Go to github and then copy the http link for cloning my repo of the project 2
- Go to AWS Cloud9, then click "Create environment"
- In the terminal, copy the clone link and type :
git clone https://github.com/nogibjj/Jiaxin-P2-Microservice-Rust.git
- Install Rust again
- Go to AWS Amazon Elastic Container Registry, click "get start"
- Then follow below steps to create a private repository
- Then go to "images", click "View push commands" to copy the code, then run each of them one by one at AWS Cloud9 later.
- Tips: Sometimes you maybe occur an error when doing docker build, just type:
curl -s https://gist.githubusercontent.com/wongcyrus/a4e726b961260395efa7811cab0b4516/raw/6a045f51acb2338bb2149024a28621db2abfcaab/resize.sh | bash /dev/stdin 60
to fix it
- Copy above code in terminal at AWS Cloud9
- Go to AWS APP Runner
- Click "create service" to set up configuration by following below steps:
- Then begin to depoly the project after click "Deploy", make sure the event status are "Succeeded" at Deployment logs, otherwise you need to fix the errors according to the report from the event log.