Use vault

This commit is contained in:
2024-04-14 11:57:19 +02:00
parent 68fae38488
commit 0b4b918f6b
7 changed files with 28 additions and 22 deletions

7
Cargo.lock generated
View File

@@ -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"

View File

@@ -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"

View File

@@ -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"]

View File

@@ -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"]

7
scripts/env.sh Normal file
View File

@@ -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)'\''") | .[]')"

5
scripts/start.sh Normal file
View File

@@ -0,0 +1,5 @@
cd /app
/env.sh > ./.env
exec /usr/local/bin/books_downloader

View File

@@ -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()