feat(deploy): app stack + manual Portainer deploy workflow
Build and Push Images / Build jorgecuadros-web (push) Successful in 2m2s
Build and Push Images / Build jorgecuadros-api (push) Successful in 3m36s

Add the missing api/web deployment path on top of the existing image build CI.

- deploy/jorgecuadros-app.stack.yml: PROD app stack (api + web) pulling the
  git.mancinas.io registry images. Does not ship mysql/minio (separate stacks);
  API reaches them via DATABASE_URL / S3_ENDPOINT. API pinned to the
  jorgecuadros_db node for stable ingest/backup volumes; web is stateless.
- deploy/jorgecuadros-app.env.example: documented stack env template.
- .gitea/workflows/deploy.yml: manual (workflow_dispatch) deploy to Portainer
  via cssnr/portainer-stack-deploy-action. Inputs: image tag + scope
  (app = web+api, full = db+minio+app, applied db->minio->app).

Make the web API origin runtime-configurable instead of build-baked: the root
layout injects window.__API_ORIGIN__ from the API_ORIGIN env (force-dynamic) and
lib/api.ts resolves it at runtime, so one built image serves any deployment.

Also: dev.sh to run both dev servers (frees stale ports first) and move local
dev to ports web 4500 / api 4501.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-23 20:07:48 -07:00
co-authored by Claude Opus 4.8
parent afe2411c86
commit 70911e7e62
7 changed files with 352 additions and 3 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "next dev -p 4500",
"build": "next build",
"start": "next start",
"lint": "next lint"
+19
View File
@@ -7,10 +7,29 @@ export const metadata = {
"Plataforma interna unificada de clientes, servicios y seguros.",
};
// The browser talks to the API cross-origin, so it needs the API URL at
// runtime. NEXT_PUBLIC_* would bake it at build time (one URL per image); we
// want the URL to come from the deploy .env instead. So read it here on the
// server per request and inject it as window.__API_ORIGIN__ (see lib/api.ts).
// force-dynamic guarantees process.env is read at request time, never baked
// into a static prerender.
export const dynamic = "force-dynamic";
export default function RootLayout({ children }: { children: ReactNode }) {
const apiOrigin =
process.env.API_ORIGIN ??
process.env.NEXT_PUBLIC_API_ORIGIN ??
"http://localhost:3001";
return (
<html lang="es">
<head>
{/* Must run before the app bundle so lib/api.ts sees it at import. */}
<script
dangerouslySetInnerHTML={{
__html: `window.__API_ORIGIN__=${JSON.stringify(apiOrigin)};`,
}}
/>
{/* Google Fonts via <link> so an offline build still runs with the
system fallback stacks defined in globals.css. */}
<link rel="preconnect" href="https://fonts.googleapis.com" />
+18 -2
View File
@@ -55,8 +55,24 @@ import type {
UserRow,
} from "./types";
export const API_ORIGIN =
process.env.NEXT_PUBLIC_API_ORIGIN ?? "http://localhost:3001";
// Resolve the API origin at runtime, not build time. In the browser it comes
// from window.__API_ORIGIN__, injected server-side by the root layout from the
// deploy .env (API_ORIGIN) — so one built image serves any deployment. On the
// server (SSR) read process.env directly. NEXT_PUBLIC_API_ORIGIN stays as the
// dev/build fallback.
function resolveApiOrigin(): string {
if (typeof window !== "undefined") {
const injected = (window as { __API_ORIGIN__?: string }).__API_ORIGIN__;
if (injected) return injected;
}
return (
process.env.API_ORIGIN ??
process.env.NEXT_PUBLIC_API_ORIGIN ??
"http://localhost:3001"
);
}
export const API_ORIGIN = resolveApiOrigin();
export class ApiError extends Error {
status: number;