diff --git a/Cargo.lock b/Cargo.lock index 6c82e09..aa466d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -337,6 +337,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "217698eaf96b4a3f0bc4f3662aaa55bdf913cd54d7204591faa790070c6d0853" +[[package]] +name = "crossbeam-channel" +version = "0.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98b0cc327b5bc766e7fda9c9260cc0fa81b43a8e240440422dff70788e3f9ef1" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-queue" version = "0.3.14" @@ -1855,6 +1864,7 @@ dependencies = [ "anyhow", "tokio", "tracing", + "tracing-appender", "tracing-subscriber", ] @@ -2197,6 +2207,12 @@ dependencies = [ "cc", ] +[[package]] +name = "symlink" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7973cce6668464ea31f176d85b13c7ab3bba2cb3b77a2ed26abd7801688010a" + [[package]] name = "syn" version = "2.0.119" @@ -2421,6 +2437,19 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-appender" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "050686193eb999b4bb3bc2acfa891a13da00f79734704c4b8b4ef1a10b368a3c" +dependencies = [ + "crossbeam-channel", + "symlink", + "thiserror", + "time", + "tracing-subscriber", +] + [[package]] name = "tracing-attributes" version = "0.1.31" diff --git a/Cargo.toml b/Cargo.toml index ffcf151..eebf6bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,6 +53,7 @@ tokio = { version = "1", features = ["macros", "rt-multi-thread", "net", "signal tower-http = { version = "0.6", features = ["trace", "cors"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] } +tracing-appender = "0.2" [profile.release] lto = "thin" diff --git a/crates/service-kit/Cargo.toml b/crates/service-kit/Cargo.toml index ce6f876..8ff806c 100644 --- a/crates/service-kit/Cargo.toml +++ b/crates/service-kit/Cargo.toml @@ -11,3 +11,4 @@ anyhow.workspace = true tokio.workspace = true tracing.workspace = true tracing-subscriber.workspace = true +tracing-appender.workspace = true diff --git a/crates/service-kit/src/lib.rs b/crates/service-kit/src/lib.rs index 0d2adca..94ef200 100644 --- a/crates/service-kit/src/lib.rs +++ b/crates/service-kit/src/lib.rs @@ -3,21 +3,51 @@ //! Environment: //! * `BIND_ADDR` listen address (each service has its own default) //! * `LOG_FORMAT` `text` (default) or `json`; `RUST_LOG` sets the level +//! * `LOG_DIR` also write the log there, as JSON, one file a day +//! (`.YYYY-MM-DD.log`), keeping `LOG_KEEP_DAYS` (default 30) files +//! * `LOG_NAME` the file name prefix (default: the service's name) use std::net::SocketAddr; use std::time::Duration; use anyhow::Context; -/// Initializes `tracing` from `RUST_LOG` and `LOG_FORMAT`. -pub fn init_logging() { - use tracing_subscriber::EnvFilter; +/// Days of log files kept in `LOG_DIR` by default. +const LOG_KEEP_DAYS: usize = 30; + +/// Initializes `tracing` from `RUST_LOG` and `LOG_FORMAT`, and the log files +/// in `LOG_DIR` (named after `LOG_NAME`, else `name`), so the log outlives the +/// container. +pub fn init_logging(name: &str) { + use tracing_subscriber::layer::SubscriberExt; + use tracing_subscriber::util::SubscriberInitExt; + use tracing_subscriber::{EnvFilter, Layer, fmt}; + let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info,tower_http=info")); - let builder = tracing_subscriber::fmt().with_env_filter(filter); - if std::env::var("LOG_FORMAT").is_ok_and(|f| f.eq_ignore_ascii_case("json")) { - builder.json().init(); - } else { - builder.init(); + let json = std::env::var("LOG_FORMAT").is_ok_and(|f| f.eq_ignore_ascii_case("json")); + let stdout = if json { fmt::layer().json().boxed() } else { fmt::layer().boxed() }; + let mut problem = None; + let file = std::env::var("LOG_DIR").ok().filter(|d| !d.trim().is_empty()).and_then(|dir| { + let prefix = + std::env::var("LOG_NAME").ok().filter(|n| !n.trim().is_empty()).unwrap_or_else(|| name.to_string()); + let keep = std::env::var("LOG_KEEP_DAYS").ok().and_then(|d| d.parse().ok()).unwrap_or(LOG_KEEP_DAYS); + let appender = tracing_appender::rolling::Builder::new() + .rotation(tracing_appender::rolling::Rotation::DAILY) + .filename_prefix(prefix) + .filename_suffix("log") + .max_log_files(keep.max(1)) + .build(&dir); + match appender { + Ok(appender) => Some(fmt::layer().json().with_ansi(false).with_writer(appender).boxed()), + Err(e) => { + problem = Some(format!("cannot write the log files in {dir}: {e}")); + None + } + } + }); + tracing_subscriber::registry().with(filter).with(stdout).with(file).init(); + if let Some(problem) = problem { + tracing::warn!("{problem}; logging to stdout only"); } } diff --git a/deploy/README.md b/deploy/README.md index ae4ad03..77601a2 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -82,7 +82,8 @@ A Google OAuth kliensnél a `https://sorsfonalak.hu` címet fel kell venni az en ## Üzemeltetés -- Naplók: `docker compose logs -f backend worker worker-ai` +- Naplók élőben: `docker compose logs -f backend worker worker-ai` (ez a konténer újraindításáig/cseréjéig él). +- Naplók utólag: a backend és a két worker JSON-sorokat ír a `logs` volume-ba is, naponta új fájlba (`backend.2026-11-20.log`, `worker…`, `worker-ai…`), 30 napig megőrizve (`LOG_DIR`, `LOG_KEEP_DAYS`, `LOG_NAME`). A fájlok helye a szerveren: `docker volume inspect -f '{{.Mountpoint}}' sorsfonalak_logs`, például `grep -h '"level":"ERROR"' /var/lib/docker/volumes/sorsfonalak_logs/_data/backend.*.log | tail`. A Docker 30 másodpercenkénti `/healthz` ellenőrzése nem kerül a naplóba. - A worker két konténerben fut, ugyanabból az image-ből: a `worker` küldi az e-maileket és takarít (`WORKER_TASKS=email,cleanup`, ide kerülnek a további háttérfeladatok is), a `worker-ai` írja az elemzéseket és a válaszokat (`WORKER_TASKS=analyses`, gyors és lassú sáv). A sávok mérete a szerver `.env` fájljában állítható (`QUICK_CONCURRENCY`, `ANALYSIS_CONCURRENCY`). - Visszaállás korábbi verzióra: `.env`-ben `TAG=`, utána `docker compose up -d` - Mentés: naponta egy `pg_dump` a `/opt/sorsfonalak/backups` mappába, 14 napig megmarad. A mentéseket érdemes a szerverről is elvinni (DigitalOcean backup, vagy `rsync` otthonra). diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml index 67a8084..9a7b0bf 100644 --- a/deploy/docker-compose.yml +++ b/deploy/docker-compose.yml @@ -103,6 +103,9 @@ services: FREE_PERSON_SLOTS: ${FREE_PERSON_SLOTS:-0} # invite: new accounts need an invitation (admin page "Meghívók"); open: anyone. SIGNUP_MODE: ${SIGNUP_MODE:-invite} + # The log also goes to the logs volume, one file a day, kept 30 days + # (deploy/README.md: Logs). + LOG_DIR: /logs # STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET (docs/fizetes.md): with them # packages can be bought (a test key: by admins only). env_file: @@ -114,6 +117,8 @@ services: horoscope-api: condition: service_healthy read_only: true + volumes: + - logs:/logs logging: *logging restart: unless-stopped @@ -128,6 +133,7 @@ services: SES_REGION: ${SES_REGION:-eu-central-1} MAIL_FROM: ${MAIL_FROM:-Sorsfonalak } PUBLIC_BASE_URL: https://${DOMAIN} + LOG_DIR: /logs env_file: - path: .env.secrets required: false @@ -135,6 +141,8 @@ services: postgres: condition: service_healthy read_only: true + volumes: + - logs:/logs logging: *logging restart: unless-stopped @@ -148,6 +156,8 @@ services: QUICK_CONCURRENCY: ${QUICK_CONCURRENCY:-2} ANALYSIS_CONCURRENCY: ${ANALYSIS_CONCURRENCY:-4} PUBLIC_BASE_URL: https://${DOMAIN} + LOG_DIR: /logs + LOG_NAME: worker-ai env_file: - path: .env.secrets required: false @@ -155,6 +165,8 @@ services: postgres: condition: service_healthy read_only: true + volumes: + - logs:/logs logging: *logging restart: unless-stopped @@ -177,5 +189,7 @@ services: volumes: pgdata: + # Backend and worker logs (backend.YYYY-MM-DD.log, worker…, worker-ai…). + logs: caddy-data: caddy-config: diff --git a/services/backend/Dockerfile b/services/backend/Dockerfile index 0414444..9e26397 100644 --- a/services/backend/Dockerfile +++ b/services/backend/Dockerfile @@ -16,10 +16,13 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \ --mount=type=cache,target=/app/target,sharing=locked \ cargo build --release --locked -p backend \ && cp target/release/backend /backend +# The log directory (LOG_DIR); a volume mounted here takes over its owner. +RUN mkdir /logs # --- 2. runtime: the binary only (TLS roots are compiled in via webpki-roots) --- FROM scratch COPY --from=build /backend /backend +COPY --from=build --chown=65532:65532 /logs /logs ENV BIND_ADDR=0.0.0.0:8081 \ LOG_FORMAT=json \ RUST_LOG=info diff --git a/services/backend/src/main.rs b/services/backend/src/main.rs index c0989bc..88b6281 100644 --- a/services/backend/src/main.rs +++ b/services/backend/src/main.rs @@ -66,7 +66,7 @@ async fn main() -> anyhow::Result<()> { if std::env::args().nth(1).as_deref() == Some("healthcheck") { return service_kit::healthcheck(addr); } - service_kit::init_logging(); + service_kit::init_logging("backend"); let config = Config::from_env()?; let pool = db::connect(&config.database_url).await.context("connecting to the database")?; db::migrate(&pool).await.context("running database migrations")?; diff --git a/services/backend/src/routes/mod.rs b/services/backend/src/routes/mod.rs index aa43fdd..7d90b75 100644 --- a/services/backend/src/routes/mod.rs +++ b/services/backend/src/routes/mod.rs @@ -60,7 +60,6 @@ where pub fn router(state: Arc) -> Router { Router::new() - .route("/healthz", get(health)) .route("/v1/config", get(public_config)) .route("/v1/packages", get(payments::catalog)) // login @@ -146,6 +145,8 @@ pub fn router(state: Arc) -> Router { .make_span_with(DefaultMakeSpan::new().level(Level::INFO)) .on_response(DefaultOnResponse::new().level(Level::INFO)), ) + // After the layers: the Docker health check (every 30 s) stays out of the log. + .route("/healthz", get(health)) .with_state(state) } diff --git a/services/frontend/src/app/Landing.tsx b/services/frontend/src/app/Landing.tsx index ff1a726..6fbba09 100644 --- a/services/frontend/src/app/Landing.tsx +++ b/services/frontend/src/app/Landing.tsx @@ -86,8 +86,8 @@ export function Landing({ inviteOnly }: { inviteOnly: boolean }) { belőle. Megmutatjuk, mit hoz az éved, és mennyire illetek össze azzal, akit szeretsz.

- Részletes elemzések a legfejlettebb AI-modellekkel: egy tapasztalt asztrológushoz közelítő mélység, töredék - áron. + Részletes, személyre szóló elemzések a legfejlettebb AI-modellekkel: percek alatt, egy személyes konzultáció + árának töredékéért.

@@ -142,7 +142,7 @@ export function Landing({ inviteOnly }: { inviteOnly: boolean }) {
Miért más?

- Egy asztrológus mélysége, töredék áron + Alapos elemzés, töredék áron

    @@ -163,10 +163,10 @@ export function Landing({ inviteOnly }: { inviteOnly: boolean }) { -

    Asztrológusi mélység

    +

    Az egész képletet olvassa

    A bolygókat jegyükben, házukban, fényszögeikben és uralkodóik láncolatában olvassa, a holdcsomópontokkal és - az év tranzitjaival együtt, ahogy egy tapasztalt asztrológus is tenné. + az év tranzitjaival együtt: nem egy-egy fényállást, hanem az összefüggéseket.

  • diff --git a/services/frontend/src/app/belepes/page.tsx b/services/frontend/src/app/belepes/page.tsx index 612be1a..9294ded 100644 --- a/services/frontend/src/app/belepes/page.tsx +++ b/services/frontend/src/app/belepes/page.tsx @@ -96,8 +96,8 @@ export default async function LoginPage({ searchParams }: { searchParams: Promis Születési képlet, szinasztria és közösség – egy helyen.

    - Részletes elemzések a legfejlettebb AI-modellekkel: egy tapasztalt asztrológushoz közelítő mélység, töredék - áron. + Részletes, személyre szóló elemzések a legfejlettebb AI-modellekkel: percek alatt, egy személyes konzultáció + árának töredékéért.

diff --git a/services/frontend/src/app/globals.css b/services/frontend/src/app/globals.css index d2ba276..bf2aefd 100644 --- a/services/frontend/src/app/globals.css +++ b/services/frontend/src/app/globals.css @@ -64,6 +64,28 @@ p { margin: 0; } .nav a { color: var(--ink-2); text-decoration: none; padding: 10px 12px; border-radius: 8px; min-height: 44px; display: inline-flex; align-items: center; } .nav a:hover, .nav a[aria-current="page"] { color: var(--gold); background: rgba(217, 180, 106, 0.08); } .who { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; } +.user-menu { position: relative; } +.who-name { + display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 10px; cursor: pointer; + border: 1px solid var(--line-2); border-radius: 999px; background: none; color: var(--ink-2); font: inherit; font-size: 14px; +} +.who-name:hover, .who-name[aria-expanded="true"] { color: var(--gold); border-color: #5a6790; } +.who-chevron { width: 14px; height: 14px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; } +.who-name[aria-expanded="true"] .who-chevron { transform: rotate(180deg); } +.user-menu-list { + position: absolute; right: 0; top: calc(100% + 8px); z-index: 30; min-width: 200px; padding: 6px; + display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px; + box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45); +} +.user-menu-item { + display: flex; align-items: center; min-height: 40px; padding: 0 12px; border: 0; border-radius: 8px; background: none; + color: var(--ink); font: inherit; font-size: 14px; text-align: left; text-decoration: none; cursor: pointer; +} +.user-menu-item:hover, .user-menu-item:focus-visible { background: rgba(255, 255, 255, 0.05); color: var(--gold); } +.user-menu-item[aria-current="page"] { color: var(--gold); } +.user-menu-logout { border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; margin-top: 4px; padding-top: 2px; color: var(--muted); } +.who-name-text { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.who-icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; } .pkg-pill { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid rgba(217, 180, 106, 0.5); color: var(--gold); text-decoration: none; font-size: 13px; white-space: nowrap; @@ -334,7 +356,8 @@ td.num { font-variant-numeric: tabular-nums; white-space: nowrap; } h1 { font-size: 32px; } .site-header { padding: 10px 16px; gap: 12px; } .nav { order: 3; flex-basis: 100%; } - .who-name { display: none; } + .who-name-text { max-width: 120px; } + .who { margin-left: auto; } .card { padding: 18px; } .auth-aside { padding: 28px 20px; min-height: 0; } .wheel { width: 60%; } @@ -741,8 +764,6 @@ a.pair-row:hover strong { color: var(--gold); } .share-cta .btn { align-self: flex-start; } /* Promo codes: redeeming (header, packages page, /bevaltas) and the admin page */ -.redeem-link { color: var(--ink-2); font-size: 13px; text-decoration: none; white-space: nowrap; } -.redeem-link:hover { color: var(--gold); text-decoration: underline; text-underline-offset: 3px; } .redeem { display: flex; flex-direction: column; gap: 8px; } .redeem-row { display: flex; gap: 8px; flex-wrap: wrap; } .redeem-input { flex: 1 1 220px; width: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 1.5px; text-transform: uppercase; } diff --git a/services/frontend/src/app/page.tsx b/services/frontend/src/app/page.tsx index e514d32..5b1e5fe 100644 --- a/services/frontend/src/app/page.tsx +++ b/services/frontend/src/app/page.tsx @@ -24,7 +24,7 @@ export async function generateMetadata(): Promise { return { title: { absolute: "Sorsfonalak – születési képlet, éves előrejelzés, kapcsolati összevetés" }, description: - "Percre pontos születési képlet és személyre szóló elemzés a legfejlettebb AI-modellekkel: egy tapasztalt asztrológushoz közelítő mélység, töredék áron. Éves előrejelzés, kapcsolati összevetés és kártyajóslás.", + "Percre pontos születési képlet és személyre szóló elemzés a legfejlettebb AI-modellekkel, percek alatt és töredék áron. Éves előrejelzés, kapcsolati összevetés és kártyajóslás.", alternates: { canonical: `${base}/` }, openGraph: { type: "website", siteName: "Sorsfonalak", locale: "hu_HU", url: `${base}/`, title, description, images: [image] }, twitter: { card: "summary_large_image", title, description, images: [image.url] }, diff --git a/services/frontend/src/components/AiNote.tsx b/services/frontend/src/components/AiNote.tsx index 6b9f5cc..8862696 100644 --- a/services/frontend/src/components/AiNote.tsx +++ b/services/frontend/src/components/AiNote.tsx @@ -1,16 +1,17 @@ /** Shown where people decide: the analyses are written by top AI models (never named: a business secret). */ export const AI_SHORT = - "A legfejlettebb AI-modellek írják: egy tapasztalt asztrológus írásos elemzéséhez közelítő mélység, töredék áron."; + "A legfejlettebb AI-modellek írják a képleted pontos adataiból: alapos, személyre szabott elemzés percek alatt, egy személyes konzultáció árának töredékéért."; /** A highlighted note on the analysis quality. */ export function AiNote() { return (
Az elemzésekről -

Profi mélység, töredék áron

+

Alapos elemzés, töredék áron

- Az elemzéseket a legfejlettebb AI-modellek írják, a képleted pontos pozícióiból. Részletességben és - árnyaltságban megközelítik egy tapasztalt asztrológus írásos elemzését, annak az árnak a töredékéért. + Az elemzéseket a legfejlettebb AI-modellek írják, a képleted csillagászati pontosságú adataiból. Részletes, + személyre szabott szöveget kapsz percek alatt, egy személyes konzultáció árának töredékéért, és amit nem értesz, + arra rá is kérdezhetsz.

); diff --git a/services/frontend/src/components/LogoutButton.tsx b/services/frontend/src/components/LogoutButton.tsx index f81ca62..518032a 100644 --- a/services/frontend/src/components/LogoutButton.tsx +++ b/services/frontend/src/components/LogoutButton.tsx @@ -5,7 +5,7 @@ import { useState } from "react"; import { api } from "@/lib/api"; -export function LogoutButton() { +export function LogoutButton({ className = "btn btn-sm", role }: { className?: string; role?: "menuitem" }) { const router = useRouter(); const [busy, setBusy] = useState(false); async function logout() { @@ -20,7 +20,7 @@ export function LogoutButton() { router.refresh(); } return ( - ); diff --git a/services/frontend/src/components/SiteHeader.tsx b/services/frontend/src/components/SiteHeader.tsx index 260d251..70867f4 100644 --- a/services/frontend/src/components/SiteHeader.tsx +++ b/services/frontend/src/components/SiteHeader.tsx @@ -2,8 +2,8 @@ import Link from "next/link"; import type { Me } from "@/lib/types"; -import { LogoutButton } from "./LogoutButton"; import { NavLinks } from "./NavLinks"; +import { UserMenu } from "./UserMenu"; /** The mark: the orbit, the thread (an S, with the crossbar an f) and a star on the rim. */ export function LogoMark({ className = "logo-mark" }: { className?: string }) { @@ -91,8 +91,6 @@ export function SiteHeader({ me }: { me: Me }) { { href: "/osszevetesek", label: "Összevetések" }, { href: "/kartyajoslas", label: "Kártyajóslás" }, { href: "/csomagok", label: "Csomagok" }, - ...(me.invoice_count > 0 ? [{ href: "/szamlak", label: "Számláim" }] : []), - { href: "/profil", label: "Profil" }, ]; if (me.user.roles.includes("admin")) links.push({ href: "/admin", label: "Admin" }); return ( @@ -101,11 +99,7 @@ export function SiteHeader({ me }: { me: Me }) {
- - Kód beváltása - - {me.user.display_name || me.user.email} - + 0} />
); diff --git a/services/frontend/src/components/UserMenu.tsx b/services/frontend/src/components/UserMenu.tsx new file mode 100644 index 0000000..0f4ce92 --- /dev/null +++ b/services/frontend/src/components/UserMenu.tsx @@ -0,0 +1,82 @@ +"use client"; + +import Link from "next/link"; +import { usePathname } from "next/navigation"; +import { useEffect, useId, useRef, useState } from "react"; + +import { LogoutButton } from "./LogoutButton"; + +/** + * The account menu under the user's name (top right): profile, invoices, + * redeeming a code, logging out. Closes on a click outside, Escape, or + * moving to another page. + */ +export function UserMenu({ name, invoices }: { name: string; invoices: boolean }) { + const [open, setOpen] = useState(false); + const box = useRef(null); + const button = useRef(null); + const menuId = useId(); + const pathname = usePathname(); + + useEffect(() => setOpen(false), [pathname]); + useEffect(() => { + if (!open) return; + const outside = (e: PointerEvent) => { + if (box.current && !box.current.contains(e.target as Node)) setOpen(false); + }; + document.addEventListener("pointerdown", outside); + return () => document.removeEventListener("pointerdown", outside); + }, [open]); + + function keydown(e: React.KeyboardEvent) { + if (e.key === "Escape" && open) { + setOpen(false); + button.current?.focus(); + } + } + + const items = [ + { href: "/profil", label: "Profil" }, + ...(invoices ? [{ href: "/szamlak", label: "Számláim" }] : []), + { href: "/bevaltas", label: "Kód beváltása" }, + ]; + + return ( +
+ + {open && ( + + )} +
+ ); +} diff --git a/services/horoscope-api/src/main.rs b/services/horoscope-api/src/main.rs index ecd6fb2..740bdf3 100644 --- a/services/horoscope-api/src/main.rs +++ b/services/horoscope-api/src/main.rs @@ -54,7 +54,7 @@ async fn main() -> anyhow::Result<()> { if std::env::args().nth(1).as_deref() == Some("healthcheck") { return service_kit::healthcheck(addr); } - service_kit::init_logging(); + service_kit::init_logging("horoscope-api"); let state = Arc::new(tokio::task::spawn_blocking(load_state).await??); let app = routes::router(state); let listener = tokio::net::TcpListener::bind(addr).await.with_context(|| format!("binding {addr}"))?; diff --git a/services/horoscope-api/src/routes.rs b/services/horoscope-api/src/routes.rs index 5072685..47ee34b 100644 --- a/services/horoscope-api/src/routes.rs +++ b/services/horoscope-api/src/routes.rs @@ -22,7 +22,6 @@ type AppResult = Result, ApiError>; pub fn router(state: Arc) -> Router { Router::new() - .route("/healthz", get(health)) .route("/v1/info", get(info)) .route("/v1/countries", get(countries)) .route("/v1/places", get(places)) @@ -36,6 +35,8 @@ pub fn router(state: Arc) -> Router { .make_span_with(DefaultMakeSpan::new().level(Level::INFO)) .on_response(DefaultOnResponse::new().level(Level::INFO)), ) + // After the layers: the Docker health check (every 30 s) stays out of the log. + .route("/healthz", get(health)) .with_state(state) } diff --git a/services/worker/Dockerfile b/services/worker/Dockerfile index 59c93d8..26d2951 100644 --- a/services/worker/Dockerfile +++ b/services/worker/Dockerfile @@ -16,10 +16,13 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \ --mount=type=cache,target=/app/target,sharing=locked \ cargo build --release --locked -p worker \ && cp target/release/worker /worker +# The log directory (LOG_DIR); a volume mounted here takes over its owner. +RUN mkdir /logs # --- 2. runtime: the binary only (TLS roots are compiled in via webpki-roots) --- FROM scratch COPY --from=build /worker /worker +COPY --from=build --chown=65532:65532 /logs /logs ENV BIND_ADDR=0.0.0.0:8082 \ LOG_FORMAT=json \ RUST_LOG=info diff --git a/services/worker/src/main.rs b/services/worker/src/main.rs index 506febe..bddbaeb 100644 --- a/services/worker/src/main.rs +++ b/services/worker/src/main.rs @@ -84,12 +84,12 @@ async fn main() -> anyhow::Result<()> { match std::env::args().nth(1).as_deref() { Some("healthcheck") => return service_kit::healthcheck(addr), Some("compare-models") => { - service_kit::init_logging(); + service_kit::init_logging("worker"); return compare::main(std::env::args().skip(2).collect()).await; } _ => {} } - service_kit::init_logging(); + service_kit::init_logging("worker"); let config = Config::from_env()?; let pool = db::connect(&config.database_url).await.context("connecting to the database")?; db::migrate(&pool).await.context("running database migrations")?;