+ {m.settings_about()} +
++ {m.settings_about_version({ version, commit, date: builtAt.slice(0, 10) })} +
+diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.ts index a214446..8f008d2 100644 --- a/apps/web/vite.config.ts +++ b/apps/web/vite.config.ts @@ -2,8 +2,37 @@ import { defineConfig } from 'vite'; import { sveltekit } from '@sveltejs/kit/vite'; import { SvelteKitPWA } from '@vite-pwa/sveltekit'; import { paraglide } from '@inlang/paraglide-sveltekit/vite'; +import { execSync } from 'node:child_process'; +import { readFileSync } from 'node:fs'; +import { fileURLToPath } from 'node:url'; + +// Fase 14.3.1 — build-time version constants. +// Source order: explicit GIT_SHA env (used by `apps/web/Dockerfile` +// during `infra/scripts/deploy-erosi.sh`) > local `git rev-parse` > +// 'dev' fallback when neither path works (e.g. tarball builds). +const rootPkgUrl = new URL('../../package.json', import.meta.url); +const rootPkg = JSON.parse(readFileSync(fileURLToPath(rootPkgUrl), 'utf8')) as { + version?: string; +}; +const APP_VERSION = rootPkg.version ?? '0.0.0'; +let APP_COMMIT: string = process.env.GIT_SHA ?? ''; +if (!APP_COMMIT) { + try { + APP_COMMIT = execSync('git rev-parse --short HEAD', { stdio: ['ignore', 'pipe', 'ignore'] }) + .toString() + .trim(); + } catch { + APP_COMMIT = 'dev'; + } +} +const BUILD_TIME = new Date().toISOString(); export default defineConfig({ + define: { + __APP_VERSION__: JSON.stringify(APP_VERSION), + __APP_COMMIT__: JSON.stringify(APP_COMMIT), + __BUILD_TIME__: JSON.stringify(BUILD_TIME) + }, plugins: [ paraglide({ project: './project.inlang', diff --git a/infra/docker-compose.erosi.yml b/infra/docker-compose.erosi.yml index e60c301..7205044 100644 --- a/infra/docker-compose.erosi.yml +++ b/infra/docker-compose.erosi.yml @@ -178,6 +178,10 @@ services: PUBLIC_KEYCLOAK_REALM: ${PUBLIC_KEYCLOAK_REALM} PUBLIC_KEYCLOAK_CLIENT_ID: ${PUBLIC_KEYCLOAK_CLIENT_ID} PUBLIC_APP_URL: ${PUBLIC_APP_URL} + # Fase 14.3.5 — short git sha of the host's checkout, exported + # by infra/scripts/deploy-erosi.sh before invoking the build. + # Defaults to literal 'dev' if the deployer didn't set GIT_SHA. + GIT_SHA: ${GIT_SHA:-dev} restart: always environment: PUBLIC_SUPABASE_URL: ${PUBLIC_SUPABASE_URL} diff --git a/infra/scripts/deploy-erosi.sh b/infra/scripts/deploy-erosi.sh index 9bce207..ae88da9 100755 --- a/infra/scripts/deploy-erosi.sh +++ b/infra/scripts/deploy-erosi.sh @@ -26,7 +26,13 @@ DEPLOY_HOST="${DEPLOY_HOST:-ambrosio}" DEPLOY_PATH="${DEPLOY_PATH:-/opt/colectivo}" REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)" -echo "==> Deploying to $DEPLOY_HOST:$DEPLOY_PATH" +# Fase 14.3.5 — capture the short git sha on the deploy host (this +# machine) so it can be baked into the built app bundle as +# `__APP_COMMIT__`. We do it here rather than on ambrosio because we +# rsync without `.git`, so the remote can't run `git rev-parse`. +GIT_SHA="$(cd "$REPO_ROOT" && git rev-parse --short HEAD 2>/dev/null || echo dev)" + +echo "==> Deploying to $DEPLOY_HOST:$DEPLOY_PATH (commit $GIT_SHA)" # ── 1. Ensure target dir exists ──────────────────────────────────────────── ssh "$DEPLOY_HOST" "sudo mkdir -p $DEPLOY_PATH && sudo chown \$(id -u):\$(id -g) $DEPLOY_PATH" @@ -104,15 +110,21 @@ fi REMOTE # ── 4. Build + bring up the stack ───────────────────────────────────────── -ssh "$DEPLOY_HOST" bash -s << 'REMOTE' +# We forward GIT_SHA over the ssh env so the remote `docker compose build` +# can substitute it into the Dockerfile build-arg (compose reads it from +# the same shell, not from .env, so a transient export is enough). ssh +# doesn't accept VAR=value args directly, so we prefix `env`. +ssh "$DEPLOY_HOST" env GIT_SHA="$GIT_SHA" bash -s << 'REMOTE' set -euo pipefail cd /opt/colectivo +: "${GIT_SHA:=dev}" -echo "--- Building app image" -docker compose --env-file .env -f infra/docker-compose.erosi.yml build app +echo "--- Building app image (commit $GIT_SHA)" +GIT_SHA="$GIT_SHA" docker compose --env-file .env -f infra/docker-compose.erosi.yml \ + build --build-arg GIT_SHA="$GIT_SHA" app echo "--- Bringing stack up (detached)" -docker compose --env-file .env -f infra/docker-compose.erosi.yml up -d +GIT_SHA="$GIT_SHA" docker compose --env-file .env -f infra/docker-compose.erosi.yml up -d echo "--- Waiting for db to be healthy" for i in $(seq 1 60); do