From 3b7255096228855938032e276a3d336320cc69b8 Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Sun, 21 Apr 2024 18:42:36 +0200 Subject: [PATCH] docker deployment --- .dockerignore | 2 +- .run/Dockerfile.run.xml | 53 ++++++++++++++++++++ Dockerfile | 105 +++++++++++++++------------------------- src/main.rs | 1 + 4 files changed, 93 insertions(+), 68 deletions(-) create mode 100644 .run/Dockerfile.run.xml diff --git a/.dockerignore b/.dockerignore index c41cc9e..eb5a316 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1 @@ -/target \ No newline at end of file +target diff --git a/.run/Dockerfile.run.xml b/.run/Dockerfile.run.xml new file mode 100644 index 0000000..7305bf3 --- /dev/null +++ b/.run/Dockerfile.run.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + diff --git a/Dockerfile b/Dockerfile index 336f641..2601768 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,73 +1,44 @@ -# syntax=docker/dockerfile:1 - -# Comments are provided throughout this file to help you get started. -# If you need more help, visit the Dockerfile reference guide at -# https://docs.docker.com/engine/reference/builder/ - -################################################################################ -# Create a stage for building the application. - -ARG RUST_VERSION=1.73.0 -ARG APP_NAME=uploader -FROM rust:${RUST_VERSION}-slim-bullseye AS build -ARG APP_NAME +FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef WORKDIR /app -RUN apt-get update -RUN apt-get install -y pkg-config -RUN apt-get install -y libssl-dev -RUN apt-get install -y libudev-dev -RUN apt-get install -y git -# Build the application. -# Leverage a cache mount to /usr/local/cargo/registry/ -# for downloaded dependencies and a cache mount to /app/target/ for -# compiled dependencies which will speed up subsequent builds. -# Leverage a bind mount to the src directory to avoid having to copy the -# source code into the container. Once built, copy the executable to an -# output directory before the cache mounted /app/target is unmounted. -RUN --mount=type=bind,source=src,target=src \ - --mount=type=bind,source=Cargo.toml,target=Cargo.toml \ - --mount=type=bind,source=Cargo.lock,target=Cargo.lock \ - --mount=type=bind,source=.cargo/config.toml,target=.cargo/config.toml \ - --mount=type=cache,target=/app/target/ \ - --mount=type=cache,target=/usr/local/cargo/registry/ \ -# --mount=type=bind,source=migrations,target=migrations \ - < /app/entrypoint.sh -# Copy the executable from the "build" stage. -COPY --from=build /bin/server /bin/ +# Make the script executable +RUN chmod +x /app/entrypoint.sh +COPY --from=builder /app/target/release/$PROGNAME /usr/local/bin/$PROGNAME -# What the container should run when it is started. -CMD ["/bin/server"] \ No newline at end of file +CMD ["/app/entrypoint.sh"] diff --git a/src/main.rs b/src/main.rs index ab793ec..299a54e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ lazy_static! { ) .file("./settings.toml") .file(shellexpand::tilde("~/twba/config.toml").into_owned()) + .file(std::env::var("TWBA_CONFIG").unwrap_or_else(|_| "~/twba/config.toml".to_string())) .load() .map_err(|e| UploaderError::LoadConfig(e.into())) .expect("Failed to load config");