diff --git a/Cargo.lock b/Cargo.lock index a118c82..2c38bc0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -199,6 +199,7 @@ dependencies = [ "axum-prometheus", "base64", "bytes", + "dotenv", "futures", "once_cell", "reqwest", @@ -375,6 +376,12 @@ dependencies = [ "subtle", ] +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "encoding_rs" version = "0.8.33" diff --git a/Cargo.toml b/Cargo.toml index 4702132..ec8a934 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,3 +28,4 @@ axum-prometheus = "0.5.0" base64 = "0.21.5" sentry = { version = "0.32.0", features = ["debug-images"] } +dotenv = "0.15.0" diff --git a/docker/build-dev.dockerfile b/docker/build-dev.dockerfile deleted file mode 100644 index eac8a64..0000000 --- a/docker/build-dev.dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -FROM rust:bullseye AS builder - -WORKDIR /app - -COPY . . - -RUN cargo build --bin books_downloader - - -FROM debian:bullseye-slim - -RUN apt-get update \ - && apt-get install -y openssl ca-certificates \ - && rm -rf /var/lib/apt/lists/* - -RUN update-ca-certificates - -WORKDIR /app - -COPY --from=builder /app/target/debug/books_downloader /usr/local/bin -ENTRYPOINT ["/usr/local/bin/books_downloader"] diff --git a/docker/build.dockerfile b/docker/build.dockerfile index d556fea..579b1a7 100644 --- a/docker/build.dockerfile +++ b/docker/build.dockerfile @@ -15,7 +15,10 @@ RUN apt-get update \ RUN update-ca-certificates +COPY ./scripts/*.sh / +RUN chmod +x /*.sh + WORKDIR /app COPY --from=builder /app/target/release/books_downloader /usr/local/bin -ENTRYPOINT ["/usr/local/bin/books_downloader"] +CMD ["/start.sh"] diff --git a/scripts/env.sh b/scripts/env.sh new file mode 100644 index 0000000..e75e632 --- /dev/null +++ b/scripts/env.sh @@ -0,0 +1,7 @@ +#! /usr/bin/env sh + +response=`curl -X 'GET' "https://$VAULT_HOST/v1/$VAULT_SECRET_PATH" -s \ + -H 'accept: application/json' \ + -H "X-Vault-Token: $VAULT_TOKEN"` + +echo "$(echo "$response" | jq -r '.data.data | to_entries | map("\(.key)='\''\(.value)'\''") | .[]')" diff --git a/scripts/start.sh b/scripts/start.sh new file mode 100644 index 0000000..3a3ef11 --- /dev/null +++ b/scripts/start.sh @@ -0,0 +1,5 @@ +cd /app + +/env.sh > ./.env + +exec /usr/local/bin/books_downloader diff --git a/src/main.rs b/src/main.rs index 48a6d28..261d892 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,8 @@ pub mod config; pub mod services; pub mod views; +use dotenv::dotenv; + use sentry::{integrations::debug_images::DebugImagesIntegration, types::Dsn, ClientOptions}; use std::{net::SocketAddr, str::FromStr}; use tracing::info; @@ -10,6 +12,8 @@ use crate::views::get_router; #[tokio::main] async fn main() { + dotenv().ok(); + tracing_subscriber::fmt() .with_target(false) .compact()