32
loading...
This website collects cookies to deliver better user experience
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
PATH
environment variable. You can avoid this by configuring your current shell running:source $HOME/.cargo/env
rustup default stable
cargo new rust-rocket-app --bin
--bin
option indicates to make a binary program.rust-rocket-app
directory containing two files:$ cd rust-rocket-app
$ tree .
.
├── Cargo.toml
└── src
└── main.rs
1 directory, 2 files
rust-rocket-app
directory, open the Cargo.toml
file and add rocket as a dependency under the [dependencies]
section.[dependencies]
rocket = "0.5.0-rc.1"
src/main.rs
with the code below:#[macro_use] extern crate rocket;
#[get("/")]
fn index() -> &'static str {
"Hello, world!"
}
#[get("/hello/<name>")]
fn hello(name: &str) -> String {
format!("Hello, {}!", name)
}
#[launch]
fn rocket() -> _ {
rocket::build()
.mount("/", routes![index])
.mount("/", routes![hello])
}
/
, returning "Hello, world!" and /hello/<name>
returning "Hello, name!" where "name" is the route parameter. Then it mounts the routes and launches the application.cargo run
$curl localhost:8000/
Hello, world!
$curl localhost:8000/hello/koyeb
Hello, koyeb!
Dockerfile
in your project directory.FROM rust:1 as builder
WORKDIR /app
COPY . .
RUN cargo install --path .
FROM debian:buster-slim as runner
COPY --from=builder /usr/local/cargo/bin/rust-rocket-app /usr/local/bin/rust-rocket-app
ENV ROCKET_ADDRESS=0.0.0.0
EXPOSE 8000
CMD ["rust-rocket-app"]
docker build . -t <DOCKER_HUB_USERNAME>/rust-rocket-app
docker run -p 8000:8000 <DOCKER_HUB_USERNAME>/rust-rocket-app
$curl localhost:8000/
Hello, world!
docker push <DOCKER_HUB_USERNAME>/rust-rocket-app
echo \
'{ \
"auths": { \
"index.docker.io/v1/": { \
"username": "<REPLACE_ME_WITH_DOCKER_HUB_USERNAME>", \
"password": "<REPLACE_ME_WITH_DOCKER_HUB_TOKEN>" \
} \
} \
}' | koyeb secrets create docker-hub-credentials
koyeb app init rust-rocket-app --docker "<REPLACE_ME_WITH_DOCKER_HUB_USERNAME>/rust-rocket-app" --ports 8000:http --routes /:8000 --docker-private-registry-secret docker-hub-credentials
/
route of your Koyeb App URL.$koyeb app get rust-rocket-app
ID NAME DOMAINS UPDATED AT
d58ebed1-48c0-46b7-a2f1-91f3ffdbccf2 rust-rocket-app rust-rocket-app-<YOUR_ORG>.koyeb.app 2021-06-23 09:46:55.411403 +0000 UTC