Commit Graph

68 Commits

Author SHA1 Message Date
darroyo af323da3d3 feat: add character sales tracking with 12h countdown timer
CI / Build Native (push) Failing after 1m11s
- New page /ventas to track characters selling items
- Default 12h duration per character sale
- Real-time countdown with color-coded badges (green/yellow/red/gray)
- Sound alert toggle when sales expire
- CRUD API: GET/POST/DELETE /api/sales
- Flyway migration V2 for character_sales table
- Private per-user (same user sees only their own characters)
- Expired sales remain visible with 'Expirado' badge until manually deleted
2026-08-18 09:22:41 -04:00
darroyo 8ca11252d7 fix: install Node.js 20 in CI container (required by JS-based actions)
CI / Build Native (push) Successful in 6m37s
2026-08-16 00:15:42 -04:00
darroyo cebd2c0365 fix: filter snapshot prices to only show items used in run
CI / Build Native (push) Failing after 47s
- Add filteredSnapshotCristales/Ores/Venta getters that filter based on modalDetails.items
- Cristales: only show grados that appear in items
- Ores: only show Soul/Spirit Ore based on item tipos
- Venta: only show tipo-grado combos in items
- Backward compatible: old runs with 15 items show full snapshot
2026-08-15 23:24:48 -04:00
darroyo 05db929da1 fix: only save items with cristalesDisponibles > 0
CI / Build Native (push) Failing after 43s
- saveRun(): filter items where cristalesDisponibles > 0 before persisting
- allItems(): show only saved items in modal (no padding with zeros)
2026-08-15 23:19:24 -04:00
darroyo e913b5ceb0 fix(historial): clamp sparkline bar height between 15-90% to prevent overflow
CI / Build Native (push) Failing after 39s
When range=0 (1 run or all same profit), use absolute scale with clamped heightPct
2026-08-15 23:11:45 -04:00
darroyo 4b564d9fae fix(historial): use SS/SPS/BSS abbreviations for shot types
CI / Build Native (push) Failing after 44s
- Replace broken chained replace() with tipoShort() helper
- SS = Soulshot, SPS = Spiritshot, BSS = Blessed Spiritshot
- Add tooltip (:title) on chips for full name on hover
- CSS: add cursor:help, font-weight:600, letter-spacing
2026-08-15 23:05:44 -04:00
darroyo 54fd68aa08 feat(historial): comprehensive enrichment of history page
CI / Build Native (push) Failing after 1m21s
Backend:
- RunSummary: add profitMarginPct, costPerShot, profitPerShot, itemCount, tiposUsados, wasProfitable
- HistoryStats: add avgProfitMarginPct, avgCostPerShot, avgProfitPerShot, totalOreUsed, totalItems, tiposBreakdown
- HistoryService: compute all new fields, parse items for best/worst run

Frontend (historial.html):
- 8 stats cards instead of 5: +Margen promedio, +Total invertido, +Shots, +Costo/shot
- SVG sparkline showing last 10 runs profit trend
- Ganancia por tipo breakdown with horizontal bars
- Table: sortable columns (click headers), new cols: Margen%, Costo/shot, Items chips, delta vs avg
- Sortable by: Fecha, Label, Costo, Venta, Ganancia, Margen
- Modal: badge Profit/Loss, 8 metric cards, snapshot of prices at save time, comparison vs current prices
- Export buttons: CSV (resumen) + JSON (completo con items y snapshot)

Format.js:
- Add fmtPercent() with es-CL locale

CSS:
- Add sparkline, tipos-breakdown, sortable columns, delta badges, metric cards, diff badges, modal-lg
2026-08-15 21:30:01 -04:00
darroyo 209ef9fb05 fix(ci): remove obsolete Node.js setup, use Gitea-compatible syntax
CI / Build Native (push) Failing after 1m7s
- Remove Node.js installation (frontend is now static Qute/Alpine)
- Remove src/frontend/node_modules cache (no longer exists)
- Change github.workflow to gitea.workflow for Gitea Actions compatibility
- Increase container memory from 8g to 10g for native builds
- Add BUILDKIT_INLINE_CACHE=1 for faster Docker builds
2026-08-15 19:52:06 -04:00
darroyo 71d8050515 fix(db): tune H2 URL to actually flush writes to disk on commit
CI / Build Native (push) Successful in 6m50s
Sin estos parametros, H2 mantiene buffers en memoria y los cambios
hechos por change-password (u otras mutaciones) no llegaban al
archivo .mv.db hasta un checkpoint que el SIGKILL del container
se saltaba. Resultado: User aparece persistido en memoria (login
con la nueva pass da 200 OK dentro de la misma corrida), pero al
restart el archivo en disco tiene la password vieja.

WRITE_DELAY=0  -- flush cada commit
LOCK_MODE=0   -- no usar lock file (quitamos el .lock.db)
MV_STORE=TRUE -- usar el multi-version store que es mas cooperativo
                 con escrituras frecuentes

Verificado: el archivo .mv.db crece de 94KB a 106KB tras un
change-password, y la nueva password sobrevive un docker rm + run.
2026-08-15 13:54:26 -04:00
darroyo 0ef2991bcd fix(change-password): return updated user via record outcome w/ flush
CI / Build Native (push) Successful in 7m49s
User.getEntityManager().refresh() requiere una tx activa, y el
caller (AuthResource.changePassword) no es @Transactional -> ese
approach tiraba TransactionRequiredException.

En lugar de refrescar en el caller, cambio AuthService.changePassword
para devolver la User ya actualizada en un record
ChangePasswordOutcome, despues de un flush() explicito para que los
cambios lleguen a DB antes de cerrar la tx. Asi el response del
endpoint refleja el estado real de la fila.
2026-08-15 13:30:26 -04:00
darroyo 7b76bde15b fix(change-password): force entity refresh in response to avoid stale mustChangePassword
CI / Build Native (push) Successful in 7m2s
El cambio-password persistia bien a la DB (login con la nueva pass
daba 200 OK), pero la respuesta del endpoint seguia reportando
mustChangePassword: true. Era un problema de Panache/Hibernate cache:
la user entity quedaba cacheada en el persistence context con el
estado pre-cambio, y User.findById() siguiente devolvia esa misma
instancia cacheada.

Fix: despues de findById, forzar refresh desde DB con
User.getEntityManager().refresh(refreshed). Asi el response
refleja el estado actual real de la fila.
2026-08-15 12:02:57 -04:00
darroyo 615b78a847 feat(db): migrate to Flyway for schema persistence
CI / Build Native (push) Successful in 8m10s
'create-drop' borra las tablas en cada shutdown, perdiendo todos
los usuarios (y el cambio de password). Aunque el bind mount
persiste el archivo H2 en /root/docker/manual/lineage2/data/, las
tablas se recreaban vacias en cada restart del container.

Solucion: Flyway para manejar el schema, Hibernate solo valida.

- pom.xml: + quarkus-flyway
- src/main/resources/db/migration/V1__init.sql: schema de users,
  user_state, production_runs + index idx_runs_user_created
- application.properties: database.generation=create-drop -> validate
  + quarkus.flyway.migrate-at-start=true + baseline-on-migrate=true

BootstrapAdmin queda igual: chequea User.count() y crea admin si 0.
Flyway corre antes de Hibernate, asi que las tablas existen cuando
StartupEvent dispara.
2026-08-15 11:40:16 -04:00
darroyo 2ceb7ca7ea fix(frontend): reorder await api.me() before setUser in changePassword
CI / Build Native (push) Successful in 6m22s
En el fix anterior, await api.me() estaba DESPUES de setUser(u). Eso
significaba que React podria re-renderizar AuthenticatedApp entre el
setUser y el await, disparando el usePersistedState.load() que llama
api.getState() mientras la cookie todavia no estaba aplicada al
cookie store del browser. El await api.me() quedaba corriendo mientras
el 401 ya habia sido reportado.

Invertir el orden: await api.me() PRIMERO (confirma que la cookie
quedo realmente aplicada), despues setUser(u). Asi React re-renderiza
con la cookie ya activa para los fetches internos.
2026-08-15 11:24:36 -04:00
darroyo b161710952 fix(frontend): post-change-password cookie timing + defensive 401 fallback
CI / Build Native (push) Successful in 7m45s
Dos cambios para destrabar el flujo post-change-password:

1. AuthContext.changePassword: despues de setUser(u), hacer un round-trip
   a api.me() para confirmar que la nueva cookie ya es utilizable. Sin
   este paso, React monta AuthenticatedApp tan rapido que el primer
   fetch desde usePersistedState.load() corre antes de que el browser
   haya propagado el Set-Cookie (race condition reportado en Chrome).

2. usePersistedState.load: en 401, caer en makeDefaultAppState() en lugar
   de setStateInternal(null). Antes dejaba al usuario varado en un
   <LoadingScreen>Cargando tu estado...</LoadingScreen> para siempre. Ahora
   ve la app vacia con SaveIndicator, y al primer cambio real el
   auto-save sube el estado al server.
2026-08-15 03:27:31 -04:00
darroyo ec5ac6735c chore: revert debug logging after the auth issue was diagnosed
CI / Build Native (push) Successful in 6m24s
Found the actual issue was a stale Docker image in the LXC (the CI
runner was stuck for ~30h starting at task 323 on Aug 14). The newly
pulled image with all prior fixes (no @Authenticated, records w/
@RegisterForReflection, create-drop for tables) has been verified
end-to-end: login returns 200, /me returns 200 with the user,
change-password returns 200 after password validation.

So we can drop the LOG statements and the SQL debug log without
regressing anything.
2026-08-15 02:39:23 -04:00
darroyo e53a8107cb noop: trigger CI
CI / Build Native (push) Failing after 1m18s
2026-08-15 02:05:00 -04:00
darroyo 5a83470587 debug(auth): trace de login en AuthService + SQL log en app props
CI / Build Native (push) Failing after 1m19s
Para diagnosticar por qué el login devuelve 401 con la password
correcta del bootstrap admin. Imprime:
- username/pw.length al entrar
- si la busqueda del user en la DB da null
- hash.len y hash.prefix para confirmar que el user esta bien
  almacenado
- bcrypt.matches(true/false)

Tambien activamos quarkus.hibernate-orm.log.sql=true y
quarkus.log.category.'com.l2.shots.auth'.level=DEBUG.
2026-08-15 01:59:08 -04:00
darroyo 995ed39dbc debug: enable SQL logging + auth category logging
CI / Build Native (push) Successful in 6m23s
Para diagnosticar por qué el login devuelve 401 con la password
correcta del bootstrap admin. Vamos a ver qué queries corre
Hibernate y qué pasa en el authenticate.
2026-08-15 01:46:22 -04:00
darroyo 7041fc206b fix(auth): drop @Authenticated/@RolesAllowed on cookie-based endpoints
CI / Build Native (push) Successful in 6m14s
Quarkus security solo lee JWT del header 'Authorization: Bearer ...'
por defecto. Esta app entrega el JWT en una cookie HttpOnly
('auth-token'), entonces @Authenticated/@RolesAllowed rebotaban con
401 antes de que el endpoint pudiera validar manualmente.

Reemplazos:
- @Authenticated en /change-password: sacada. El endpoint ya hace
  jwtCookieAuth.extractToken() y devuelve 401 manual si falla.
- @Authenticated en /check: sacada. Endpoint ahora extrae y valida
  el JWT a mano.
- @Authenticated en /me: never estuvo, OK.
- @RolesAllowed('admin') en /admin/reset-password y /admin/users:
  reemplazada por chequeo manual jwt.getGroups().contains('admin'),
  devolviendo 403 si no es admin.

Sigue funcionando el MustChangePasswordFilter porque sigue siendo
un ContainerRequestFilter con @Priority(AUTHENTICATION+100) y no
requiere auth previa para correr: simplemente aborta con 403 si
mustChangePassword=true salvo allowlist (change-password, logout).

Removida inyeccion no usada de currentJwt (JsonWebToken) que solo
estaba para @RolesAllowed.
2026-08-15 01:26:46 -04:00
darroyo cc09fe8943 fix(dtos): annotate records with @RegisterForReflection for native Jackson
CI / Build Native (push) Successful in 6m18s
Las clases record NO se serializan bien en Quarkus 3.20.1 native-image
aunque Jackson 2.17+ las soporta en JVM. GraalVM strip-ea la metadata
<Erecord> del bytecode mas los accessors auto-generados, y Jackson no
puede detectar que la clase es un record -> cae al BeanSerializer
clasico -> 'no properties discovered to create BeanSerializer'.

@RegisterForReflection le indica a Quarkus: incluí esta clase en la
metadata de reflexion del native-image, asi Jackson la ve completa.

Aplicado a los 16 DTOs (records + nested records):
- auth: AuthMeResponse, AdminUserSummary, Credentials,
        ChangePasswordRequest, AdminResetPasswordRequest, ErrorBody,
        MustChangeBody
- history: RunSummary, RunDetails, RunItem, RunSnapshot, RunIn,
           HistoryStats
- state: AppState + Insumos + FormulaDto (nested)
2026-08-15 01:10:47 -04:00
darroyo 017c58a2b2 refactor(dtos): convert all DTOs to Java records for native-mode Jackson
CI / Build Native (push) Successful in 6m23s
En Quarkus native-image, Jackson no introspecta public fields de clases
con normales (deja de refleccionar field metadata). Salia error:

  No serializer found for class com.l2.shots.auth.AuthMeResponse and
  no properties discovered to create BeanSerializer

Los records tienen auto-accessors (id(), username(), etc) que Jackson
serializa nativamente, sin necesidad de reflection o
@RegisterForReflection.

Convertidos:
- auth: AuthMeResponse, AdminUserSummary, Credentials,
         ChangePasswordRequest, AdminResetPasswordRequest, ErrorBody,
         MustChangeBody
- history: RunSummary, RunDetails, RunItem, RunSnapshot, RunIn,
           HistoryStats
- state: AppState (con Insumos y FormulaDto anidados)

Callers actualizados para usar accessors en vez de field access:
- AuthService.listUsersForAdmin -> AdminUserSummary.from
- AuthService.saveRun -> RunSummary.from / RunDetails.of
- AuthResource.register/login -> creds.username() / creds.password()
- HistoryResource.saveRun -> input.items() etc

Notas:
- RunDetails NO puede extender RunSummary en records (JLS no permite
  extends entre records). Va como record independiente con todos los
  campos. El JSON que produce matchea la interface RunDetails del
  frontend (que extendia RunSummary).
- HistoryStats ahora se construye de una sola vez al final de
  computeStats en lugar de ir mutando campos.
- MustChangeBody quedo con un constructor no-canonico no-arg para
  mantener el call site original (new MustChangeBody()).
2026-08-15 00:46:19 -04:00
darroyo 89a224ee0c fix(bootstrap): use create-drop so tables exist on fresh H2
CI / Build Native (push) Successful in 6m16s
El schema-gen con database.generation=update NO corre en Quarkus native
(3.20.1) ni forzando quarkus.hibernate-orm.schema-management.run-on-startup=true.
El primer 'Table USERS not found' sigue saliendo en BootstrapAdmin.onStart.

Cambio a 'create-drop':
- En startup: crea las tablas que falten (no dropa las existentes).
- En shutdown limpio: drop -> POR CADA docker stop SE PIERDEN LOS USERS.

Para persistencia real a futuro: integrar Flyway con migrations y pasar
database.generation=validate. Para esta entrega, dejamos create-drop
que al menos arranca la app + bootstrap admin en un H2 fresco, y los
restarts sin SIGTERM (docker kill, caida de energia) preservan datos.

Saca tambien el run-on-startup=true que no estaba surtiendo efecto.
2026-08-15 00:15:24 -04:00
darroyo 07588979e4 fix(bootstrap): force EMF init + enable schema-gen on startup
CI / Build Native (push) Successful in 6m24s
El error 'Table USERS not found' en BootstrapAdmin.User.count() se daba
porque en Quarkus native-image, con database.generation=update, el
schema-gen NO corre en startup del container por defecto (corre solo en
dev mode). Resultado: en un H2 fresco, el primer SELECT COUNT(*) del
bootstrap pierde contra una DB sin tablas.

Dos cambios:
1. application.properties: agregar
   quarkus.hibernate-orm.schema-management.run-on-startup=true
   para forzar el schema-gen en startup en prod/native.
2. BootstrapAdmin:
   - @Transactional + EntityManager (em) inyectados
   - em.createNativeQuery('SELECT 1') al inicio de onStart() para
     asegurar que el EMF esté listo y la session esté abierta antes
     del count(). Belt-and-suspenders.
2026-08-15 00:04:17 -04:00
darroyo 7ed41ac825 fix(docker): add diagnostic logging to entrypoint to debug permission issue
CI / Build Native (push) Successful in 6m53s
El chown sigue sin funcionar despues del primer fix. Agregamos logs
para ver:
- con que uid arranca el entrypoint
- ls -la /work/data antes y despues del chown
- si chown falla, lo logueamos en lugar de tragarnos el error

Tambien asegura que /work y /work/application tengan owner 1001:1001
y mode 0755, por si la imagen viene con owner root (que seria el
sintoma de que el build no usaria USER directive).
2026-08-14 23:39:14 -04:00
darroyo 0bcd66ba32 fix(docker): entrypoint chowns /work/data so H2 can create on fresh volume
CI / Build Native (push) Successful in 6m25s
Cuando el volumen named 'shot-crafter-data' es nuevo, Docker lo monta
con owner root:root. La aplicacion corre como UID 1001 y no puede
escribir -> H2 falla al crear shots.mv.db -> BootstrapAdmin no crea
el admin -> no se puede login.

Quitar 'USER 1001' del Dockerfile, agregar entrypoint.sh que:
1. chown -R 1001:1001 /work/data (la app va a poder escribir)
2. chmod 0755 /work
3. setpriv --reuid=1001 --regid=1001 --init-groups -- /work/application
   (drop a no-root antes del exec)

Resultado: el contenedor arranca como root el primer instante, hace
el fix de permisos una sola vez, y desde ese momento la app corre
como 1001. Docker defaults USER a root cuando no hay directiva USER.
2026-08-14 22:58:28 -04:00
darroyo 6a7f01289b fix(auth): move SecureRandom out of static field for native-image compat
CI / Build Native (push) Successful in 7m25s
GraalVM native-image rejects static fields of type Random/SecureRandom
(their internal state is captured at build time and can't be replayed
deterministically). Move the instance into generatePassword() as a
local variable - it is only used once at startup anyway.
2026-08-14 22:16:36 -04:00
darroyo a171943f98 feat(auth): admin UI for user management + change-password frontend
CI / Build Native (push) Failing after 3m4s
Backend additions:
- User.lastLoginAt column (updated on each successful login)
- AdminUserSummary DTO (id, username, createdAt, lastLoginAt, isAdmin, mustChangePassword)
- GET /api/auth/admin/users (RolesAllowed("admin")) -> array of summaries
- AuthService.listUsersForAdmin() + AuthService.authenticate() now @Transactional and bumps lastLoginAt

Frontend (Phase 1):
- User type extended with mustChangePassword + isAdmin
- api.changePassword() / api.adminResetPassword() / api.adminListUsers()
- AuthContext exposes changePassword
- ChangePasswordPage.tsx (full-page, current + new + confirm, errors inline)
- App.tsx routes LoginPage -> ChangePasswordPage -> AuthenticatedApp

Frontend (Phase 2):
- TabBar supports optional 'usuarios' tab (shown only if user.isAdmin)
- UsersAdminPage.tsx: lista todos los usuarios con badges de rol y estado,
  botón "Resetear contraseña" con modal inline que llama adminResetPassword
- Header de AuthenticatedApp muestra un badge 'admin' al lado del username

Both mvn compile and npm tsc + vite build pass clean.
2026-08-14 20:07:12 -04:00
darroyo 1d6fc08a25 feat(auth): bootstrap admin on first boot + forced password change + admin reset
CI / Build Native (push) Has been cancelled
Backend changes (no frontend yet):

Schema (User entity)
- + mustChange_password (boolean NOT NULL, default false)
- + is_admin (boolean NOT NULL, default false)
Hibernate update mode adds both columns automatically.

BootstrapAdmin (new, ApplicationScoped, @Observes StartupEvent)
- runs only when User.count() == 0 and app.bootstrap.admin.enabled=true
- generates a 20-char random password (alphabet without 0/o/O/1/l/I)
- persists the user with isAdmin=true, mustChangePassword=true
- prints a banner to stdout AND to the JBoss logger so docker logs
  picks it up:
    BOOTSTRAP-ADMIN-USERNAME admin
    BOOTSTRAP-ADMIN-PASSWORD <random>
    BOOTSTRAP-ADMIN-CHANGE   This password MUST be changed on first login ...
- idempotent: skips if any user already exists

MustChangePasswordFilter (new, @Provider ContainerRequestFilter)
- runs after JWT auth (Priorities.AUTHENTICATION + 100)
- for authenticated requests with mustChangePassword=true, returns
  403 with {error, mustChangePassword:true} unless the path is
  /api/auth/change-password or /api/auth/logout

Change-password endpoint (POST /api/auth/change-password)
- @Authenticated, body {currentPassword, newPassword}
- verifies currentPassword via bcrypt, validates newPassword>=8 chars,
  updates hash and sets mustChangePassword=false
- returns updated AuthMeResponse and re-issues the auth cookie

Admin reset endpoint (POST /api/auth/admin/reset-password)
- @RolesAllowed("admin")
- body {username, newPassword}
- sets target's passwordHash and mustChangePassword=true (forces change
  on next login)
- security: only users in the JWT 'admin' group can hit it; isAdmin
  is stored on the user record so a stale token can't promote itself

JWT groups now include 'admin' for isAdmin users; previously everyone
was just 'user'.

Config (application.properties)
- app.bootstrap.admin.enabled=true
- app.bootstrap.admin.username=admin
2026-08-14 20:04:44 -04:00
darroyo fb021b165b ci: point Docker registry at internal Gitea (10.5.0.195:3000)
CI / Build Native (push) Successful in 6m17s
Cut the dependency on the public hostname gitea.danielarroyo.cl and
push straight to the LAN Gitea instance. Internal Gitea is plain HTTP,
so the docker daemon on the LXC needs 'insecure-registries' set, and
the gitea-runner-lxc has to be re-registered against the new URL
(separate manual steps; not in this repo).

- ci.yml: docker login, both docker tag, both push_with_retry, and
  docker logout now target 10.5.0.195:3000
- compose.yaml: image URL switched to 10.5.0.195:3000

The CI workflow itself, the Dockerfile, and the build command are
unchanged - only the registry target moved.
2026-08-14 18:29:08 -04:00
darroyo 2833e76914 fix(docker): switch runtime base to ubuntu:22.04 (glibc 2.35)
CI / Build Native (push) Has been cancelled
The native binary is built against glibc 2.35 (Ubuntu jammy in CI) but
quarkus-micro-image:2.0 ships glibc 2.34 (UBI 9), hence the
'GLIBC_2.35 not found' at runtime. Switching to ubuntu:22.04 as the
runtime base matches glibc exactly and lets us stop fighting with
musl / static binaries.

Dockerfile:
- FROM ubuntu:22.04 (was quarkus-micro-image:2.0)
- install curl + ca-certificates via apt (apt + bash are present, so
  chmod/echo securerandom run in-line again)
- single-stage: no more curl-builder multi-stage
- useradd UID 1001 (matches the in-container USER)

CI:
- drop binary-type=STATIC and --libc=musl (binary is dynamic again)
- drop the rm -f target/*-runner (cache invalidate)
- 'Stage binary for Docker' is now just 'cp'
- verify step is informational only

Image is ~5 MB larger than quarkus-micro-image but the runtime now
matches the build glibc, so the container starts cleanly.
2026-08-14 15:45:05 -04:00
darroyo 6e3db41ba4 fix(ci): force musl linking for the static native binary
CI / Build Native (push) Failing after 6m13s
binary-type=STATIC alone picks glibc on Ubuntu jammy hosts, hence
the GLIBC_2.35 error at runtime. Explicitly force musl:

- -Dquarkus.native.libc=musl
- -Dquarkus.native.additional-build-args=--libc=musl
- delete target/*-runner first so we don't reuse a previously-built
  glibc-based binary that the Quarkus plugin cache might return

Verify step now exits 1 if the binary isn't statically linked, so
the next CI run tells us definitively whether we shipped static.
2026-08-14 14:53:39 -04:00
darroyo 1ad8e17473 fix(ci): drop 'file' from verify step (not installed in maven base image)
CI / Build Native (push) Successful in 46m9s
The 'file' package isn't installed in maven:3.9.6-eclipse-temurin-21, so
'file target/...-runner' returned 127 and failed the verify step.
Use only 'ldd'; on a static binary ldd exits non-zero with 'not a
dynamic executable', which we suppress with '|| echo'.
2026-08-14 13:58:43 -04:00
darroyo 0ce8d401d8 fix(ci): build static natively with musl on the build host (drop container-build)
CI / Build Native (push) Failing after 6m7s
container-build=true runs the native-image inside a Mandrel container,
but in the act runner the workspace mount doesn't resolve
(/workspace/... is a container path, not a host path), so the Mandrel
container can't see shot-crafter-calculator-1.0.0-runner.jar.

Fix: install musl + musl-tools in the CI container, build locally.
Quarkus 3.x's binary-type=STATIC will then produce a genuinely static
binary linked against musl, which has no dependency on the host's
glibc and runs cleanly on quarkus-micro-image:2.0 (UBI 9, glibc 2.34).
2026-08-14 13:40:59 -04:00
darroyo e095547142 fix(ci): build inside a Mandrel container to get a truly-static binary
CI / Build Native (push) Failing after 2m2s
The local native-image (GraalVM on Ubuntu jammy) produces a binary
linked against the runner's glibc 2.35. quarkus-micro-image:2.0 ships
glibc 2.34, hence the 'GLIBC_2.35 not found' runtime error.

binary-type=STATIC alone is not enough without musl on the build host.
-Dquarkus.native.container-build=true runs the native build inside the
Mandrel builder image, which ships musl and produces a genuinely static
binary that has no host-libc dependency.

Also adds a verification step that runs file and ldd on the runner
binary so the next CI log shows whether we actually shipped static.
2026-08-14 09:05:28 -04:00
darroyo 07e62dd481 fix(ci): drop --max-concurrent-uploads (not a valid docker push flag)
CI / Build Native (push) Successful in 17m58s
That flag only exists for docker buildx / docker buildx imagetools.
docker push in this version rejects it as unknown. Revert to plain
docker push with the retry loop.
2026-08-13 22:04:34 -04:00
darroyo 425011d9c8 fix(ci): make docker push retry more aggressive against Gitea registry
CI / Build Native (push) Failing after 9m10s
The Gitea registry sometimes returns 'net/http: timeout awaiting
response headers' on blob uploads. The existing retry loop (3x15s)
isn't enough.

- Bump retries 3 -> 5
- Backoff 15s -> 30s
- --max-concurrent-uploads=1 to avoid hammering a small registry

Total worst-case wait: ~4 minutes (4 retries * 30s + 5 pushes ~ 30s).
2026-08-13 21:46:02 -04:00
darroyo 3c189ae9c4 fix(docker): stage curl libs under /usr/lib64, not /lib64
CI / Build Native (push) Failing after 24m54s
ldd reports library paths as /lib64/... (the legacy short path).
quarkus-micro-image:2.0 has /lib64 as a symlink to /usr/lib64, so
COPY --from=curl-builder /out/ / collides when trying to write into
/lib64 (cannot copy to non-directory).

The fix: in the curl-builder stage, translate /lib64 -> /usr/lib64
(and /lib -> /usr/lib) before installing each library, so the final
image gets libs under /usr/lib64 and doesn't touch the /lib64 symlink.
2026-08-13 21:09:56 -04:00
darroyo 378b46cbd8 fix(docker): don't ignore build-output/, the COPY needs it in the build context
CI / Build Native (push) Failing after 6m47s
Earlier cleanup added build-output to .dockerignore, but the runtime
stage does COPY build-output/*-runner /work/application, so the
directory must be present in the build context.
2026-08-13 20:47:53 -04:00
darroyo 6421a91148 ci: revert to Docker image build + registry push (no deploy)
CI / Build Native (push) Failing after 14m36s
Drop the LXC deploy step. Pipeline now stops at publishing the image
to the Gitea registry; deployment is handled out of band.

Restored:
- Dockerfile (multi-stage: curl-builder + quarkus-micro-image:2.0,
  generic via build-output/*-runner wildcard, COPY --chown=1001:1001)
- compose.yaml (one-shot install of the published image)
- .dockerignore (excludes build-output/)

CI workflow:
- Installs docker-buildx (needed for COPY --chown)
- Uses docker buildx build
- chmod 775 and echo securerandom happen in the 'Stage binary for Docker'
  step; the final image has no RUN commands
- Tags :latest and :<short-sha>, pushes with retry

No deploy step. Pull the image with docker compose / run it manually.
2026-08-13 20:25:43 -04:00
darroyo a2fb5cc521 ci: deploy native binary directly to LXC via SSH (drop Docker/registry)
CI / Build Native (push) Failing after 12m4s
Switch the runtime from a Docker image to a systemd service running the
native binary on the LXC host. The CI still uses Docker for the build
environment (maven:3.9.6-eclipse-temurin-21), but stops at producing the
static native binary.

Pipeline changes:
- Drop docker.io, docker-buildx, docker buildx, docker push, registry.
- Drop Dockerfile, compose.yaml, .dockerignore (no longer needed).
- Build native binary in CI container, SCP to LXC, run deploy script.
- Deploy script stops the service, swaps the binary, starts it, hits
  /q/health/live to verify.

LXC one-time setup (manual, run on the host):
- useradd runner (UID 1001)
- mkdir /opt/shot-crafter-calculator/{data,keys,deploy}
- copy RSA JWT keys into keys/
- install /etc/systemd/system/shot-crafter-calculator.service
- install /usr/local/bin/deploy-shot-crafter-calculator.sh
- useradd deployer + ssh keypair for the CI
- store DEPLOY_SSH_KEY secret in Gitea

Bootstrap the first deploy manually with scp + ssh before relying on CI.
2026-08-13 20:05:17 -04:00
darroyo ac349c1b34 fix(docker): drop RUN commands - quarkus-micro-image:2.0 has no shell
CI / Build Native (push) Failing after 15m1s
Removed the RUN chmod/chown/echo steps from the Dockerfile. The Quarkus
micro image 2.0 ships without /bin/sh and /usr/bin/sh, so any RUN
instruction fails. The chmod and securerandom.source append now happen
in the CI 'Stage binary for Docker' step, and COPY --chown=1001:1001
takes ownership of the binary in the image.

COPY --chown requires BuildKit, so:
- Install docker-buildx in the CI
- Switch docker build -> docker buildx build

The final image stays minimal (no shell, no microdnf, no extra packages).
2026-08-13 17:13:54 -04:00
darroyo 11c58aa614 fix(docker): set SHELL to /usr/bin/sh for quarkus-micro-image:2.0
CI / Build Native (push) Failing after 15m24s
The Quarkus micro image 2.0 no longer ships /bin/sh (only /usr/bin/sh).
Docker's default shell is /bin/sh, so RUN commands fail with
'exec /bin/sh: no such file or directory'. Set SHELL explicitly to
/usr/bin/sh to keep the small final image while letting Docker run
RUN commands.
2026-08-13 16:39:04 -04:00
darroyo af92363f18 fix(docker): mkdir /out/etc/pki and /out/etc before cp
CI / Build Native (push) Failing after 8m48s
cp -rP /etc/pki/ca-trust /out/etc/pki/ requires /out/etc/pki to exist.
Consolidated mkdir -p to create both /out/etc/pki and /out/etc.
2026-08-13 16:24:02 -04:00
darroyo 9e81097f53 fix(docker): use install -D to create leading dirs for curl
CI / Build Native (push) Failing after 16m26s
The previous install -m 0755 /usr/bin/curl /out/usr/bin/curl failed because
/out/usr/bin/ did not exist. install -D creates the leading dirs.
2026-08-13 15:45:58 -04:00
darroyo ef8d95b7da fix(docker): use multi-stage build to install curl (quarkus-micro-image:2.0 ships no microdnf)
CI / Build Native (push) Failing after 14m50s
The 2.0 rebuild of quarkus-micro-image removed microdnf to slim the image,
so the inline 'microdnf install curl-minimal' step now fails with
'command not found'.

Build curl-minimal in a ubi9/ubi-minimal builder stage, then copy only the
curl binary + its runtime shared libs + CA bundle into the final
quarkus-micro-image layer. Final image stays slim and the docker-compose
healthcheck keeps working.
2026-08-13 14:59:21 -04:00
darroyo 227c4e2e6e fix(ci): build static native binary (musl) to fix glibc version mismatch
CI / Build Native (push) Failing after 14m45s
Container `maven:3.9.6-eclipse-temurin-21` is Ubuntu 22.04 jammy
with glibc 2.35. Container `quarkus-micro-image:2.0` is UBI 9
minimal with glibc 2.34. Native-image links against the build
host's glibc, so the resulting binary needs GLIBC_2.34+ symbols
that the UBI 9 runtime doesn't provide:

  ./application: /lib64/libc.so.6: version `GLIBC_2.34' not found
  ./application: /lib64/libc.so.6: version `GLIBC_2.33' not found
  ./application: /lib64/libc.so.6: version `GLIBC_2.32' not found

Set quarkus.native.binary-type=STATIC so GraalVM embeds musl into
the binary and removes the glibc dependency. The static binary
runs on any Linux distribution, including UBI minimal. Trade-off:
~50MB -> ~80MB image size.
2026-08-13 14:29:51 -04:00
darroyo d101d6df0f feat: add HTTP healthcheck endpoint via quarkus-smallrye-health
CI / Build Native (push) Failing after 16m25s
- pom.xml: add quarkus-smallrye-health dependency.
  Exposes /q/health/live and /q/health/ready endpoints (liveness
  and readiness probes for Quarkus apps).
- Dockerfile: install curl-minimal in the microdnf layer so the
  container has a real HTTP client. quarkus-micro-image is based
  on UBI 9 minimal and doesn't ship with curl by default.
- compose.yaml: healthcheck now hits GET /q/health/live with
  curl -f instead of the previous kill -0 1 (which only proved
  the process was alive, not that the HTTP server was responding).

The next CI run will rebuild the native binary with the health
extension baked in; old images pulled from :latest will keep
working since this is additive.
2026-08-13 13:01:20 -04:00
darroyo 12d382d253 feat: add compose.yaml for one-line install
CI / Build Native (push) Has been cancelled
docker compose pull
  docker compose up -d
  docker compose logs -f

  - Single service `shot-crafter` pulling from
    gitea.danielarroyo.cl/proyectos/shot-crafter-calculator:latest
  - Named volume `shot-crafter-data` mounted at /work/data
    so the H2 DB persists across `down`/`up` cycles
  - env vars inline (overridable via -e or .env): DB URL,
    HTTP port/host, cookie name + secure flag
  - healthcheck using `kill -0 1` (the native binary is PID 1,
    POSIX-portable, no extra binaries needed)
  - restart: unless-stopped so it survives Docker daemon restarts

Ver .env.example para la lista completa de variables operacionales.
2026-08-13 12:48:03 -04:00
darroyo 9646236fa8 feat: externalize config via env vars
CI / Build Native (push) Successful in 20m1s
- Add .env.example with all configurable variables documented
  (DB URL, HTTP port/host, cookie, JWT issuer/keys, log level)
- Remove hardcoded -Dquarkus.http.host from Dockerfile ENTRYPOINT
  (application.properties already sets the default; env vars
  can now override it at runtime without conflicting with -D flags)

All env vars follow Quarkus's auto-binding convention:
property.key → PROPERTY_KEY (uppercase)

Most useful for production:
- QUARKUS_DATASOURCE_JDBC_URL: DB file path
- QUARKUS_HTTP_PORT: HTTP port
- QUARKUS_HTTP_HOST: bind interface
- APP_AUTH_COOKIE_SECURE: enable Secure flag behind HTTPS
- MP_JWT_VERIFY_PUBLICKEY_LOCATION: externalize RSA keys
2026-08-13 09:27:53 -04:00
darroyo ee1363535c fix(ci): add retry loop to docker push (handles Gitea registry timeout)
CI / Build Native (push) Successful in 18m38s
The Gitea Container Registry responded with 'net/http: timeout
awaiting response headers' midway through the push. The image
uploads ~50MB of layers, and the registry can be slow under load.

Add a push_with_retry() shell function that retries each push up
to 3 times with 15s backoff. Most importantly, it retries for
both the 'latest' and the SHA tag, so a partial failure doesn't
leave the registry in a half-pushed state.

Uses POSIX sh-compatible while loop (no bashisms like {1..3}).
2026-08-12 21:12:22 -04:00