Admin: stopka wersji w sidebarze - sha commitu i czas kompilacji obrazu Dockera w stopce usera (rail pokazuje sha + tooltip) - GIT_SHA build-argiem z deploya (.env stosu w deploy.py i hostdeploy.py, compose.yml interpola), czas z date -u przy npm run build w Dockerfile; na devie sha z git HEAD (vite.config); i18n nav.buildInfo pl/en (testy unit BuildInfo)

This commit is contained in:
tisachi
2026-11-06 01:24:02 +01:00
parent e92f82da13
commit fd7c2cc78f
11 changed files with 123 additions and 8 deletions

View File

@@ -3,7 +3,9 @@ WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# stopka wersji w panelu: sha z build-arga deploya + czas kompilacji obrazu (UTC)
ARG GIT_SHA=
RUN VITE_GIT_SHA="$GIT_SHA" VITE_BUILD_TS="$(date -u +%Y-%m-%dT%H:%M:%SZ)" npm run build
FROM nginx:alpine
# template -> /etc/nginx/templates/: entrypoint obrazu robi envsubst ${API_UPSTREAM}

View File

@@ -1,7 +1,10 @@
# Wymaga wczesniej: docker network create fitos-net (patrz README)
services:
admin:
build: .
build:
context: .
args:
GIT_SHA: ${GIT_SHA:-}
container_name: fitos-admin
ports:
- "9000:9000"

View File

@@ -23,6 +23,7 @@ import { Button, ThemeToggle, LanguageToggle } from './ui';
import { Topbar } from '../topbar';
import { Brandmark } from './Brandmark';
import { Avatar } from './Avatar';
import { buildInfo } from '../lib/build-info';
import { cn } from '../lib/utils';
interface NavItem {
@@ -188,6 +189,7 @@ export default function Layout() {
});
const isTrainer = useIsTrainer();
const build = buildInfo();
const fullName =
[user?.firstName, user?.lastName].filter(Boolean).join(' ') || user?.email || '?';
const roles = [
@@ -220,6 +222,13 @@ export default function Layout() {
{t('nav.logout')}
</Button>
</div>
<div
aria-hidden="true"
title={build.full}
className="mt-2.5 truncate text-center text-[10px] font-medium text-dim/55"
>
{build.full}
</div>
</div>
);
@@ -238,6 +247,13 @@ export default function Layout() {
>
<LogOut className="h-5 w-5" />
</button>
<div
aria-hidden="true"
title={build.full}
className="w-full truncate text-center text-[9px] font-semibold text-dim/55"
>
{build.sha}
</div>
</div>
);

View File

@@ -42,7 +42,9 @@
"collapseMenu": "Collapse menu",
"roleAdmin": "Admin",
"roleTrainer": "Trainer",
"roleMember": "Member"
"roleMember": "Member",
"buildInfo": "build {{sha}} · {{time}}",
"buildDev": "dev"
},
"topbar": {
"openMenu": "Open menu",

View File

@@ -42,7 +42,9 @@
"collapseMenu": "Zwiń menu",
"roleAdmin": "Admin",
"roleTrainer": "Trener",
"roleMember": "Ćwiczący"
"roleMember": "Ćwiczący",
"buildInfo": "wersja {{sha}} · {{time}}",
"buildDev": "dev"
},
"topbar": {
"openMenu": "Otwórz menu",

View File

@@ -0,0 +1,22 @@
import i18n from '../i18n';
import { fmtDateTime } from './format';
export interface BuildInfoParts {
sha: string;
time: string;
full: string;
}
/**
* Wersja wydruku stopki panelu: sha z budowy obrazu (VITE_GIT_SHA) i czas
* kompilacji dockera (VITE_BUILD_TS, UTC). Vite nadaje je w buildu Dockerfile;
* `vite dev` uzupełnia sha lokalnym HEAD (vite.config.ts), dlatego czas bywa
* „dev".
*/
export function buildInfo(): BuildInfoParts {
const rawSha = String(import.meta.env.VITE_GIT_SHA ?? '').trim();
const ts = String(import.meta.env.VITE_BUILD_TS ?? '').trim();
const sha = rawSha.slice(0, 7) || 'dev';
const time = /^\d{4}-\d{2}-\d{2}T/.test(ts) ? fmtDateTime(ts) : i18n.t('nav.buildDev');
return { sha, time, full: i18n.t('nav.buildInfo', { sha, time }) };
}

View File

@@ -0,0 +1,30 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { buildInfo } from '../src/lib/build-info';
// bez zmiennych buildu (dev) — oba pola dostają fallback "dev"
describe('buildInfo', () => {
afterEach(() => {
vi.unstubAllEnvs();
});
it('zwraca dev gdy brak sha i czasu kompilacji', () => {
const info = buildInfo();
expect(info.sha).toBe('dev');
expect(info.time).toBe('dev');
expect(info.full).toBe('wersja dev · dev');
});
it('skraca sha do 7 znaków i formatuje czas kompilacji', () => {
vi.stubEnv('VITE_GIT_SHA', 'abcdef0123456789abcdef0123456789abcdef01');
vi.stubEnv('VITE_BUILD_TS', '2026-11-05T22:00:00Z');
const info = buildInfo();
expect(info.sha).toBe('abcdef0');
expect(info.time).not.toBe('dev');
expect(info.full).toContain('abcdef0');
});
it('traktuje niecytowany czas jako dev', () => {
vi.stubEnv('VITE_BUILD_TS', 'not-a-timestamp');
expect(buildInfo().time).toBe('dev');
});
});

View File

@@ -1,7 +1,20 @@
import { execSync } from 'node:child_process';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import tailwindcss from '@tailwindcss/vite';
// Stopka wersji w panelu: w buildu Dockerfile sha nadchodzi build-argiem
// (VITE_GIT_SHA); na devie lokalnego hosta uzupełniamy go bieżącym HEAD.
if (!process.env.VITE_GIT_SHA) {
try {
process.env.VITE_GIT_SHA = execSync('git rev-parse --short HEAD', {
encoding: 'utf8',
}).trim();
} catch {
// brak gita obok repo — stopka pokaże fallback "dev"
}
}
export default defineConfig({
plugins: [react(), tailwindcss()],
server: {

View File

@@ -78,7 +78,11 @@ services:
restart: unless-stopped
admin:
build: ../../admin
build:
context: ../../admin
args:
# sha deployowanego refa -> stopka wersji w panelu (VITE_GIT_SHA w buildzie)
GIT_SHA: ${GIT_SHA:-}
container_name: fitos-admin-${DEPLOY_ENV}
ports:
- "${ADMIN_HOST_PORT:?set ADMIN_HOST_PORT in .env}:9000"

View File

@@ -275,9 +275,13 @@ def write_release(remote: Remote, remote_dir: str, ref: str, sha: str) -> None:
ok("RELEASE zapisany")
def write_stack_env(remote: Remote, remote_dir: str, cfg: dict[str, str], env_name: str) -> None:
def write_stack_env(
remote: Remote, remote_dir: str, cfg: dict[str, str], env_name: str, sha: str
) -> None:
lines = [
f"DEPLOY_ENV={env_name}",
# compose.yml -> build args admina -> stopka wersji w panelu (VITE_GIT_SHA)
f"GIT_SHA={sha}",
f"JWT_ACCESS_SECRET={cfg['JWT_ACCESS_SECRET']}",
f"JWT_REFRESH_SECRET={cfg['JWT_REFRESH_SECRET']}",
f"FITOS_FIRST_ADMIN_EMAIL={cfg.get('FITOS_FIRST_ADMIN_EMAIL') or 'admin@fitos.local'}",
@@ -425,7 +429,7 @@ def main() -> None:
try:
sync_tree(remote, tar_path, remote_dir, args.env)
write_release(remote, remote_dir, args.ref, sha)
write_stack_env(remote, remote_dir, cfg, args.env)
write_stack_env(remote, remote_dir, cfg, args.env, sha)
if not args.no_build:
stack_build(remote, remote_dir)
# dopiero teraz zwalniamy porty: kontenery starego projektu -> nowe

View File

@@ -9,7 +9,8 @@ Kroki: git fetch -> kontrola `[skip deploy]` w head-commicie -> bramka
destrukcyjnych migracji (diff stary SHA z RELEASE -> nowy SHA) -> pg_dump
przed startem stosu -> git archive + swap drzewa stosu (STACK_DIR, domyslnie
/var/lib/fitos-stack/fitos-staging; .new/.old, .env i RELEASE NIE sa
nadpisywane) -> docker compose build -> up -d ->
nadpisywane, w .env podmieniany jest wylacznie GIT_SHA -> build-arg admina) ->
docker compose build -> up -d ->
/health -> smoke web + smoke login/refresh. Cala sekwencja build/up/health/
smoke max 3 proby; po 3 nieudanych status FAILED, bez zadnego cofania.
@@ -247,6 +248,21 @@ def predeploy_dump(ctx: Ctx, sha: str) -> None:
rotate_keep(ctx.backups_dir, "predeploy-*.sql", ctx.backup_keep)
def stamp_git_sha(env_path: Path, sha: str) -> None:
"""GIT_SHA w .env stosu: compose.yml interpolicies go jako build-arg admina
(VITE_GIT_SHA -> stopka wersji w panelu). Reszta .env (sekrety) nietknięta."""
if not env_path.is_file():
return
lines = env_path.read_text(encoding="utf-8").splitlines()
for i, line in enumerate(lines):
if line.strip().startswith("GIT_SHA="):
lines[i] = f"GIT_SHA={sha}"
env_path.write_text("\n".join(lines) + "\n", encoding="utf-8")
return
lines.append(f"GIT_SHA={sha}")
env_path.write_text("\n".join(lines) + "\n", encoding="utf-8")
def sync_tree(ctx: Ctx, sha: str) -> None:
"""git archive -> .new, przeniesienie .env/RELEASE ze starego drzewa, swap (.old)."""
archive = ctx.agent_home / f"fitos-src-{sha[:12]}.tar.gz"
@@ -267,6 +283,7 @@ def sync_tree(ctx: Ctx, sha: str) -> None:
src = ctx.stack_dir / keep
if src.is_file():
shutil.copy2(src, new_dir / keep)
stamp_git_sha(new_dir / ".env", sha)
if old_dir.exists():
shutil.rmtree(old_dir)
if ctx.stack_dir.exists():