feat: Update environment variables and Docker configurations for production setup

This commit is contained in:
AlexeerCT
2025-12-31 10:37:23 -06:00
parent 17c7a5ecd1
commit 97b3ea52bc
8 changed files with 56 additions and 20 deletions

View File

@@ -32,6 +32,7 @@ CORE_DB_PASSWORD=postgres
# ----- Frontend -----
NODE_ENV=development
VITE_API_URL=http://localhost:8000/api
INTERNAL_API_URL=http://backend:8000/api
VITE_KEYCLOAK_REALM=master
VITE_KEYCLOAK_URL=http://localhost:8080
VITE_KEYCLOAK_CLIENT_ID=anexo76-frontend

View File

@@ -136,7 +136,13 @@ python -c "from core.database import init_db; init_db()"
```
docker build -t dev.aduanasoft.com/anexo76/backend:latest -f ./backend/Dockerfile ./backend
docker build -t dev.aduanasoft.com/anexo76/frontend:latest -f ./frontend/Dockerfile.prod ./frontend
docker build \
--build-arg VITE_API_URL=https://anexo76-dev.aduanasoft.com/api/ \
--build-arg VITE_KEYCLOAK_URL=https://anexo76-dev.aduanasoft.com/kcauth/ \
--build-arg INTERNAL_API_URL=http://backend:3467/api/ \
-t dev.aduanasoft.com/anexo76/frontend:latest \
-f ./frontend/Dockerfile.prod \
./frontend
```
Publica en el registro (ajusta el registry si corresponde):

View File

@@ -1,6 +1,7 @@
# Core Framework
fastapi==0.119.0
uvicorn[standard]==0.37.0
gunicorn==23.0.0
pydantic==2.12.3
pydantic[email]==2.12.3
pydantic-settings==2.11.0

View File

@@ -87,18 +87,19 @@ services:
KC_DB_USERNAME: postgres
KC_DB_PASSWORD: ${POSTGRES_KEYCLOAK_PASSWORD:-postgres}
KC_DB_SCHEMA: public
KC_HOSTNAME: localhost
KC_HOSTNAME: anexo76-dev.aduanasoft.com
KC_HTTP_ENABLED: "true"
KC_HOSTNAME_STRICT: "false"
KC_HOSTNAME_STRICT_HTTPS: "false"
KC_PROXY: edge
KC_PROXY_HEADERS: "xforwarded"
KC_HEALTH_ENABLED: "true"
KC_METRICS_ENABLED: "true"
KC_HOSTNAME_PATH: /kcauth
KC_LOG_LEVEL: INFO
KC_LOG_LEVEL: INFO
JAVA_OPTS_APPEND: "-Xms256m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true"
command:
- start-dev
- start
- --db=postgres
- --db-url-host=postgres-keycloak
- --http-relative-path=/kcauth
@@ -165,16 +166,26 @@ services:
condition: service_healthy
keycloak:
condition: service_healthy
volumes:
- ./backend:/app
- backend_cache:/app/__pycache__
volumes:
- ./scripts/backend-entrypoint.sh:/entrypoint.sh:ro
networks:
- backend-net
- frontend-net
restart: unless-stopped
entrypoint: ["/entrypoint.sh"]
command: ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--reload", "--log-level", "info"]
command:
[
"gunicorn",
"main:app",
"-k",
"uvicorn.workers.UvicornWorker",
"-w",
"${WEB_CONCURRENCY:-4}",
"-b",
"0.0.0.0:8000",
"--log-level",
"info"
]
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:8000/api/health || exit 1"]
interval: 15s
@@ -195,13 +206,7 @@ services:
# Frontend - SvelteKit
frontend:
build:
context: ./frontend
dockerfile: Dockerfile.prod
args:
- BUILDKIT_INLINE_CACHE=1
- VITE_API_URL=https://anexo76-dev.aduanasoft.com/api/
- VITE_KEYCLOAK_URL=https://anexo76-dev.aduanasoft.com/kcauth/
image: dev.aduanasoft.com/anexo76/frontend:latest
container_name: anexo76-frontend
environment:
- NODE_ENV=${NODE_ENV:-development}
@@ -213,7 +218,7 @@ services:
- KEYCLOAK_URL=${KEYCLOAK_URL:-http://keycloak:8080/kcauth}
- KEYCLOAK_REALM=${KEYCLOAK_REALM:-master}
- KEYCLOAK_CLIENT_ID=${KEYCLOAK_CLIENT_ID:-anexo76-backend}
- KEYCLOAK_CLIENT_SECRET=${KEYCLOAK_CLIENT_SECRET:-zRU5NuvUFtBSOuh7Kdc372AItoWGLgz9}
- KEYCLOAK_CLIENT_SECRET=${KEYCLOAK_CLIENT_SECRET:-dev-secret}
ports:
- "5111:5173"
depends_on:
@@ -226,7 +231,7 @@ services:
- frontend-net
- auth-net
restart: unless-stopped
command: ["node", "build"]
command: ["pnpm", "start"]
healthcheck:
test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://localhost:5173/ || exit 1"]
interval: 15s

View File

@@ -19,6 +19,12 @@ RUN pnpm install --frozen-lockfile
ARG VITE_API_URL
ENV VITE_API_URL=${VITE_API_URL}
ARG VITE_KEYCLOAK_URL
ENV VITE_KEYCLOAK_URL=${VITE_KEYCLOAK_URL}
ARG INTERNAL_API_URL
ENV INTERNAL_API_URL=${INTERNAL_API_URL}
# Copiar el resto del código
COPY . .
@@ -55,5 +61,9 @@ ENV NODE_ENV=production
ENV PORT=5173
ENV HOST=0.0.0.0
# IMPORTANTE: Estas variables se pueden sobrescribir en docker-compose
# pero necesitamos valores por defecto para el build
ENV INTERNAL_API_URL=http://backend:8000/api/
# Ejecutar aplicación con Node.js
CMD ["node", "build"]
CMD ["pnpm", "start"]

View File

@@ -8,6 +8,7 @@
"i18n:compile": "paraglide-js compile --project ./project.inlang --outdir ./src/lib/paraglide",
"build": "vite build",
"preview": "vite preview",
"start": "node build/index.js",
"prepare": "svelte-kit sync || echo ''",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",

View File

@@ -10,12 +10,19 @@ import { redirect, type Cookies } from '@sveltejs/kit';
* Automáticamente reemplaza localhost/127.0.0.1 con 'backend' para Docker
*/
export function getServerApiUrl(): string {
// Primero intentar con INTERNAL_API_URL (para llamadas server-side en Docker)
let apiUrl = process.env.INTERNAL_API_URL;
// Si no está definida, usar VITE_API_URL del entorno runtime (no import.meta.env)
if (!apiUrl) {
apiUrl = process.env.VITE_API_URL;
}
// Como último recurso, usar el valor de build-time
if (!apiUrl) {
apiUrl = import.meta.env.VITE_API_URL;
// Reemplazar 'localhost' con 'backend' para llamadas desde el servidor (SSR)
apiUrl = apiUrl?.replace('localhost', 'backend').replace('127.0.0.1', 'backend');
apiUrl = apiUrl?.replace('localhost', 'backend').replace('127.0.0.1', 'backend').replace('anexo76-dev.aduanasoft.com', 'backend');
}
// Normalizar la URL: asegurar que termine con '/'

View File

@@ -6,7 +6,12 @@ const config = {
// Consult https://svelte.dev/docs/kit/integrations
// for more information about preprocessors
preprocess: vitePreprocess(),
kit: { adapter: adapter() }
kit: {
adapter: adapter(),
csrf: {
checkOrigin: false
}
}
};
export default config;