ci(deploy): Auto-Deploy-Runner für Push auf main + reproduzierbarer API-Build
- .gitea/workflows/deploy.yml: deployt bei Push auf main via Host-Runner (git reset --hard origin/main in /opt/build/cockpit, docker compose up -d --build in /opt/stacks/cockpit, Healthcheck auf cockpit-api). - Auto-Migrate: runMigrations() (drizzle-orm Migrator) wird beim API-Start aufgerufen; Schema wird vor dem Listen idempotent aktualisiert. - API-Dockerfile: Workspace-Libs (@cockpit/db, @cockpit/shared) werden jetzt mit Emit kompiliert und main/exports im Image auf dist gebogen. Vorher war das Prod-Image nicht reproduzierbar baubar (Node konnte die TS-Quelle der Libs nicht laden → ERR_MODULE_NOT_FOUND). Dev-Modus und Web-/Vite-Build bleiben unberührt. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
9f3ee13094
commit
3b928d0ad0
5 files changed
+102
-1
No files matched your search
+8
-1
@@ -15,7 +15,14 @@ COPY apps/api ./apps/api
|
||||
COPY packages/db ./packages/db
|
||||
COPY packages/shared ./packages/shared
|
||||
|
||||
RUN pnpm --filter api build
|
||||
# Die Workspace-Libs werden zur Laufzeit (Node) als JS geladen. Ihre tsconfig hat
|
||||
# jedoch noEmit:true und main zeigt auf die TS-Quelle — Node kann das nicht laden.
|
||||
# Daher hier mit Emit kompilieren und main/exports im Image auf die dist-Artefakte
|
||||
# umbiegen (nur im Image; Repo-Quelle, Dev-Modus und Web-/Vite-Build bleiben unberührt).
|
||||
RUN pnpm exec tsc -p packages/shared/tsconfig.json --noEmit false \
|
||||
&& pnpm exec tsc -p packages/db/tsconfig.json --noEmit false \
|
||||
&& pnpm --filter api build \
|
||||
&& node -e "const fs=require('fs');for(const p of ['packages/db','packages/shared']){const f=p+'/package.json';const j=JSON.parse(fs.readFileSync(f,'utf8'));const fix=s=>s.replace('./src/','./dist/').replace(/[.]ts$/,'.js');if(j.main){j.main=fix(j.main);j.types=j.main.replace(/[.]js$/,'.d.ts');}if(j.exports)for(const k in j.exports){if(typeof j.exports[k]==='string')j.exports[k]=fix(j.exports[k]);}fs.writeFileSync(f,JSON.stringify(j,null,2));}"
|
||||
|
||||
# --- runtime ---
|
||||
FROM node:22-alpine AS runtime
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import Fastify from 'fastify';
|
||||
import cookie from '@fastify/cookie';
|
||||
import { fastifyTRPCPlugin, type FastifyTRPCPluginOptions } from '@trpc/server/adapters/fastify';
|
||||
import { runMigrations } from '@cockpit/db';
|
||||
import { loadEnv } from './env.js';
|
||||
import { logger } from './lib/logger.js';
|
||||
import { registerAuthMiddleware } from './auth/middleware.js';
|
||||
@@ -12,6 +13,17 @@ import { createContext } from './trpc.js';
|
||||
|
||||
async function main() {
|
||||
const env = loadEnv();
|
||||
|
||||
// Schema-Migrationen vor dem Start anwenden (idempotent). Schlägt eine
|
||||
// Migration fehl, startet der Server nicht — besser als mit veraltetem Schema.
|
||||
try {
|
||||
await runMigrations(env.DATABASE_URL);
|
||||
logger.info('db migrations applied');
|
||||
} catch (err) {
|
||||
logger.error({ err }, 'db migration failed');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const app = Fastify({
|
||||
logger: {
|
||||
level: env.LOG_LEVEL,
|
||||
|
||||
Reference in new issue
Block a user