From 36248308810e0db6486c25c2d192dbba5ae1a9ac Mon Sep 17 00:00:00 2001 From: Antoine Date: Sat, 1 Feb 2020 13:14:29 +0100 Subject: [PATCH] create hello.rs program with some rust code example --- Cargo.toml | 11 +++++++++++ Dockerfile | 15 +++++++++++++++ Makefile | 11 +++++++++++ src/bin/hello.rs | 17 +++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 Cargo.toml create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 src/bin/hello.rs diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..fb48f25 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "hello_world" # the name of the package +version = "0.1.0" # the current version, obeying semver +authors = ["Alice ", "Bob "] +edition = '2018' +#build = "hello.rs" +publish = false + +[dependencies] +rand = "0.7.3" + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..99d982c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM rust:1.40-alpine as builder + +VOLUME /usr/local/cargo/bin/ +WORKDIR /usr/src/myapp +COPY . . +RUN cargo install --root /usr/local --path . + +#FROM debian:buster-slim +# +#RUN apt-get update && apt-get install -y extra-runtime-dependencies +#COPY --from=builder /usr/local/cargo/bin/myapp /usr/local/bin/myapp +#CMD ["hello"] + +#CMD ["/usr/local/cargo/bin/hello"] +CMD sh -c "while true; do sleep 10; done" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4acf26a --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ + + +build: src/bin/*.rs Dockerfile + docker build -t my-rust-app . + +run: build + docker rm -f rust-hello || true + docker run -d -it --rm --name rust-hello my-rust-app + +exec: + docker exec -it rust-hello sh diff --git a/src/bin/hello.rs b/src/bin/hello.rs new file mode 100644 index 0000000..af72b18 --- /dev/null +++ b/src/bin/hello.rs @@ -0,0 +1,17 @@ + + +fn fair_dice_roll() -> i32 { + let x = vec![1, 2, 3, 4, 5, 6, 7, 8] + .iter() + .map(|x| x + 3) + .fold(0, |x, y| x + y); + return x; +} + + +fn main() { + + let res = fair_dice_roll(); + println!("{}", res); +} +