From 91243954125896beff1f4b0d322e01cbfbcfa3ec Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Sun, 21 Apr 2024 23:25:49 +0200 Subject: [PATCH] docker deploy --- .dockerignore | 1 + .run/Dockerfile.run.xml | 53 +++++++++++++++++++++++++++++++++++++++++ Dockerfile | 44 ++++++++++++++++++++++++++++++++++ src/main.rs | 1 + 4 files changed, 99 insertions(+) create mode 100644 .dockerignore create mode 100644 .run/Dockerfile.run.xml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..eb5a316 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +target diff --git a/.run/Dockerfile.run.xml b/.run/Dockerfile.run.xml new file mode 100644 index 0000000..aa9e016 --- /dev/null +++ b/.run/Dockerfile.run.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2601768 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,44 @@ +FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef +WORKDIR /app + +FROM chef AS planner +COPY /src ./src +COPY /Cargo.toml . +COPY /Cargo.lock . +RUN cargo chef prepare --recipe-path recipe.json + +FROM chef AS builder +COPY --from=planner /app/recipe.json recipe.json +# Build dependencies - this is the caching Docker layer! +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/home/root/app/target \ + cargo chef cook --release --locked --recipe-path recipe.json +# Build application +COPY /src ./src +COPY /Cargo.toml . +COPY /Cargo.lock . +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/home/root/app/target \ + cargo build --release --locked + +# We do not need the Rust toolchain to run the binary! +FROM debian:bookworm AS runtime +WORKDIR /app +ARG PROGNAME +RUN apt-get update && apt-get install -y libssl-dev coreutils +# Create a script to run the command and sleep for one hour after the command is done +RUN echo "#!/bin/bash \n \ + echo \"Running command: '$PROGNAME'\" \n \ + # Run your command \n \ + $PROGNAME \n \ + echo \"Done with normal command. Sleeping for one hour\" \n \ + # Sleep for one hour \n \ + sleep 3600 \n \ + echo \"Done with sleep. Exiting\" \ + " > /app/entrypoint.sh + +# Make the script executable +RUN chmod +x /app/entrypoint.sh +COPY --from=builder /app/target/release/$PROGNAME /usr/local/bin/$PROGNAME + +CMD ["/app/entrypoint.sh"] diff --git a/src/main.rs b/src/main.rs index befc1be..c1c7f0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,6 +34,7 @@ async fn run() -> Result<()> { .env() .file("./settings.toml") .file(shellexpand::tilde("~/twba/config.toml").to_string()) + .file(std::env::var("TWBA_CONFIG").unwrap_or_else(|_| "~/twba/config.toml".to_string())) .load() .map_err(|e| { error!("Failed to load config: {:?}", e);