mirror of
https://github.com/rjNemo/docker_examples
synced 2026-06-06 02:26:45 +00:00
add rust
This commit is contained in:
parent
aed6c16d5a
commit
f32cca0b34
6 changed files with 1243 additions and 0 deletions
1
rust/.dockerignore
Normal file
1
rust/.dockerignore
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
/target
|
||||||
1
rust/.gitignore
vendored
Normal file
1
rust/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
/target
|
||||||
1194
rust/Cargo.lock
generated
Normal file
1194
rust/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
10
rust/Cargo.toml
Normal file
10
rust/Cargo.toml
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
[package]
|
||||||
|
name = "example"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
env_logger = "0.9.0"
|
||||||
|
actix-web = "4"
|
||||||
21
rust/Dockerfile
Normal file
21
rust/Dockerfile
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
FROM rust:alpine as builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY . ./
|
||||||
|
|
||||||
|
RUN apk -U upgrade --no-cache && \
|
||||||
|
apk add --no-cache musl-dev
|
||||||
|
|
||||||
|
RUN cargo build --release
|
||||||
|
|
||||||
|
|
||||||
|
FROM alpine
|
||||||
|
|
||||||
|
RUN apk -U upgrade --no-cache
|
||||||
|
|
||||||
|
COPY --from=builder app/target/release/example .
|
||||||
|
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
CMD ./example
|
||||||
16
rust/src/main.rs
Normal file
16
rust/src/main.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
use actix_web::{get, middleware::Logger, App, HttpResponse, HttpServer, Responder};
|
||||||
|
use env_logger::Env;
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
|
env_logger::init_from_env(Env::default().default_filter_or("info"));
|
||||||
|
HttpServer::new(|| App::new().wrap(Logger::default()).service(hello))
|
||||||
|
.bind(("127.0.0.1", 8080))?
|
||||||
|
.run()
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/")]
|
||||||
|
async fn hello() -> impl Responder {
|
||||||
|
HttpResponse::Ok().body("Hello, World!")
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue