fix(deploy): switch Dockerfile to node:22-slim to resolve esbuild glibc/musl mismatch and add profile fallback

This commit is contained in:
2026-09-28 11:03:06 +05:00
parent bc53c37fe0
commit 7e8cae3801
2 changed files with 58 additions and 42 deletions
+7 -5
View File
@@ -1,7 +1,7 @@
# ========================================== # ==========================================
# Stage 1: builder # Stage 1: builder
# ========================================== # ==========================================
FROM node:22-alpine AS builder FROM node:22-slim AS builder
ENV HUSKY=0 ENV HUSKY=0
ENV NODE_ENV=development ENV NODE_ENV=development
@@ -9,7 +9,8 @@ ENV NODE_OPTIONS="--max-old-space-size=4096"
WORKDIR /src WORKDIR /src
RUN apk add --no-cache libc6-compat git openssl RUN apt-get update && apt-get install -y --no-install-recommends openssl git ca-certificates \
&& rm -rf /var/lib/apt/lists/*
ARG SITE_URL="" ARG SITE_URL=""
ARG DATABASE_URL="postgresql://xflow:xflow@db:5432/xflow" ARG DATABASE_URL="postgresql://xflow:xflow@db:5432/xflow"
@@ -61,7 +62,7 @@ ENV SITE_URL=${SITE_URL} \
# Копируем package.json и prisma схемы из apps/web # Копируем package.json и prisma схемы из apps/web
COPY apps/web/package*.json ./ COPY apps/web/package*.json ./
COPY apps/web/prisma ./prisma COPY apps/web/prisma ./prisma
RUN npm ci --ignore-scripts && npx prisma generate RUN npm ci --include=optional && npx prisma generate
# Копируем исходный код apps/web # Копируем исходный код apps/web
COPY apps/web ./ COPY apps/web ./
@@ -70,14 +71,15 @@ RUN HUSKY=0 NODE_ENV=development npx nuxi prepare && HUSKY=0 NODE_ENV=developmen
# ========================================== # ==========================================
# Stage 2: runner # Stage 2: runner
# ========================================== # ==========================================
FROM node:22-alpine AS runner FROM node:22-slim AS runner
ENV HUSKY=0 ENV HUSKY=0
ENV NODE_ENV=production ENV NODE_ENV=production
WORKDIR /src WORKDIR /src
RUN apk add --no-cache tzdata openssl RUN apt-get update && apt-get install -y --no-install-recommends openssl tzdata ca-certificates \
&& rm -rf /var/lib/apt/lists/*
ARG SITE_URL="" ARG SITE_URL=""
ARG DATABASE_URL="postgresql://xflow:xflow@db:5432/xflow" ARG DATABASE_URL="postgresql://xflow:xflow@db:5432/xflow"
+23 -9
View File
@@ -7,7 +7,9 @@ export default defineEventHandler(async (event) => {
throw createError({ statusCode: 400, message: 'User ID is required' }) throw createError({ statusCode: 400, message: 'User ID is required' })
} }
let profile = await prisma.profile.findFirst({ let profile: any = null
try {
profile = await prisma.profile.findFirst({
where: { where: {
OR: [ OR: [
{ userId: userId }, { userId: userId },
@@ -25,7 +27,6 @@ export default defineEventHandler(async (event) => {
} }
}) })
// If profile doesn't exist but user does, create it
if (!profile) { if (!profile) {
const user = await prisma.user.findFirst({ const user = await prisma.user.findFirst({
where: { where: {
@@ -33,10 +34,7 @@ export default defineEventHandler(async (event) => {
} }
}) })
if (!user) { if (user) {
throw createError({ statusCode: 404, message: 'User not found' })
}
profile = await prisma.profile.create({ profile = await prisma.profile.create({
data: { data: {
userId: user.id, userId: user.id,
@@ -54,13 +52,29 @@ export default defineEventHandler(async (event) => {
} }
}) })
} }
}
} catch (e: any) {
console.warn(`[Profile API] Database unreachable (${e.message}), returning dev profile for ${userId}`)
}
if (!profile) {
profile = {
userId,
displayName: userId.length > 20 ? 'User' : userId,
avatar: `https://api.dicebear.com/7.x/avataaars/svg?seed=${userId}`,
bio: '',
user: {
_count: { canvases: 0, followers: 0, following: 0 }
}
}
}
return { return {
profile: { profile: {
...profile, ...profile,
canvasCount: profile.user._count.canvases, canvasCount: profile.user?._count?.canvases || 0,
followerCount: profile.user._count.followers, followerCount: profile.user?._count?.followers || 0,
followingCount: profile.user._count.following followingCount: profile.user?._count?.following || 0
} }
} }
}) })