diff --git a/.dockerignore b/.dockerignore index 48fcd8f..b321656 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,6 +5,7 @@ .nitro .cache dist +.env # Node dependencies node_modules @@ -17,3 +18,6 @@ logs .DS_Store .fleet .idea + +# Rust +target diff --git a/Dockerfile.api b/Dockerfile.api new file mode 100644 index 0000000..009e69f --- /dev/null +++ b/Dockerfile.api @@ -0,0 +1,20 @@ +# Build +FROM rust:1.95 AS builder +WORKDIR /app + +COPY . . +RUN cargo build --release + +# Run +FROM debian:stable-slim + +RUN apt-get update && \ + apt-get install -y --no-install-recommends ca-certificates && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /app +COPY --from=builder /app/target/release/api . + +EXPOSE 8080 + +CMD ["./api"] diff --git a/Dockerfile b/Dockerfile.nuxt similarity index 100% rename from Dockerfile rename to Dockerfile.nuxt diff --git a/api/src/auth.rs b/api/src/auth.rs index 0e4fc19..bce96be 100644 --- a/api/src/auth.rs +++ b/api/src/auth.rs @@ -9,7 +9,7 @@ use http::{StatusCode, request::Parts}; use jsonwebtoken::{DecodingKey, jwk::JwkSet}; use serde::Deserialize; use tokio::sync::RwLock; -use tracing::info; +use tracing::{info, warn}; use crate::AppState; @@ -47,7 +47,10 @@ impl FromRequestParts for User { .jwks_cache .get_key(&state.constants.auth_api_base, header.kid.as_deref()) .await - .map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, "Failed to get key"))? + .map_err(|e| { + warn!("Failed to get key: {:?}", e); + (StatusCode::INTERNAL_SERVER_ERROR, "Failed to get key") + })? .ok_or((StatusCode::UNAUTHORIZED, "Invalid token"))?; let key = DecodingKey::from_jwk(&jwk).map_err(|_| { diff --git a/compose.yml b/compose.yml index 50245af..aac94e9 100644 --- a/compose.yml +++ b/compose.yml @@ -1,9 +1,23 @@ services: - my-app: - build: . + nuxt: + build: + context: . + dockerfile: Dockerfile.nuxt ports: - "3000:3000" env_file: - ./.env volumes: - ./data:/app/.data + network_mode: host + api: + build: + context: . + dockerfile: Dockerfile.api + ports: + - "8080:8080" + env_file: + - ./.env + volumes: + - ./data:/app/.data + network_mode: host