Add logs, add Dockerfile
This commit is contained in:
parent
ce31df3a0c
commit
de4795b9a1
3 changed files with 26 additions and 4 deletions
|
|
@ -3,7 +3,7 @@ name = "problem_01"
|
|||
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.10"
|
||||
log = "^0.4"
|
||||
tokio = { version = "1.27.0", features = ["full"] }
|
||||
|
|
|
|||
22
problem_01/Dockerfile
Normal file
22
problem_01/Dockerfile
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
FROM rust:latest as builder
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
COPY . .
|
||||
# Will build and cache the binary and dependent crates in release mode
|
||||
RUN --mount=type=cache,target=/usr/local/cargo,from=rust:latest,source=/usr/local/cargo \
|
||||
--mount=type=cache,target=target \
|
||||
cargo build --release && mv ./target/release/problem_01 ./problem_01
|
||||
|
||||
# Runtime image
|
||||
FROM debian:bullseye-slim
|
||||
|
||||
# Run as "app" user
|
||||
RUN useradd -ms /bin/bash app
|
||||
|
||||
USER app
|
||||
WORKDIR /app
|
||||
|
||||
# Get compiled binaries from builder's cargo install directory
|
||||
COPY --from=builder /usr/src/app/problem_01 /app/problem_01
|
||||
|
||||
# No CMD or ENTRYPOINT, see fly.toml with `cmd` override.
|
||||
|
|
@ -17,13 +17,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
Ok(n) if n == 0 => return,
|
||||
Ok(n) => n,
|
||||
Err(e) => {
|
||||
eprintln!("failed to read from socket; err = {:?}", e);
|
||||
log::error!("failed to read from socket; err = {:?}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(e) = socket.write_all(&buf[0..n]).await {
|
||||
eprintln!("failed to write to socket; err = {:?}", e);
|
||||
log::error!("failed to write to socket; err = {:?}", e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue