From c4ce230bd69f0a5d45237dca6f4f4678b1ff78aa Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Sun, 14 Apr 2024 13:26:57 +0200 Subject: [PATCH] Add vault --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + docker/build.dockerfile | 5 ++++- scripts/env.sh | 7 +++++++ scripts/healthcheck.py | 11 ----------- scripts/start.sh | 7 +++++++ src/main.rs | 3 +++ 7 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 scripts/env.sh delete mode 100644 scripts/healthcheck.py create mode 100644 scripts/start.sh diff --git a/Cargo.lock b/Cargo.lock index fd6d45c..dba9705 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -346,6 +346,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" @@ -883,6 +889,7 @@ dependencies = [ "axum", "chrono", "deadpool-postgres", + "dotenv", "futures", "lazy_static", "maplit", diff --git a/Cargo.toml b/Cargo.toml index ab3fe19..c2eaa7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,3 +28,4 @@ maplit = "1.0.2" tracing = "0.1.40" tracing-subscriber = { version = "0.3.18", features = ["env-filter"]} tower-http = { version = "0.5.0", features = ["trace"] } +dotenv = "0.15.0" diff --git a/docker/build.dockerfile b/docker/build.dockerfile index bcdd322..89ecc35 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/library_updater /usr/local/bin -ENTRYPOINT ["/usr/local/bin/library_updater"] +ENTRYPOINT ["/start.sh"] diff --git a/scripts/env.sh b/scripts/env.sh new file mode 100644 index 0000000..2ac60a3 --- /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)'\''") | .[]')" \ No newline at end of file diff --git a/scripts/healthcheck.py b/scripts/healthcheck.py deleted file mode 100644 index e21d83a..0000000 --- a/scripts/healthcheck.py +++ /dev/null @@ -1,11 +0,0 @@ -import os - -import httpx - - -response = httpx.get( - "http://localhost:8080/healthcheck", - headers={"Authorization": os.environ["API_KEY"]}, -) -print(f"HEALTHCHECK STATUS: {response.status_code}") -exit(0 if response.status_code == 200 else 1) diff --git a/scripts/start.sh b/scripts/start.sh new file mode 100644 index 0000000..03496c9 --- /dev/null +++ b/scripts/start.sh @@ -0,0 +1,7 @@ +#! /usr/bin/env sh + +cd /app + +/env.sh > ./.env + +exec /usr/local/bin/library_updater \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index ed453a6..8eff0fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ pub mod updater; pub mod utils; use axum::{http::HeaderMap, routing::post, Router}; +use dotenv::dotenv; use sentry::{integrations::debug_images::DebugImagesIntegration, types::Dsn, ClientOptions}; use std::{net::SocketAddr, str::FromStr}; use tower_http::trace::{self, TraceLayer}; @@ -54,6 +55,8 @@ async fn start_app() { #[tokio::main] async fn main() { + dotenv().ok(); + tracing_subscriber::fmt() .with_target(false) .compact()