From 9537c0342c3aa3de11c0a950a6a072551035cdfb Mon Sep 17 00:00:00 2001 From: ordinarthur <@arthurbarre.js@gmail.com> Date: Thu, 12 Mar 2026 15:37:59 +0100 Subject: [PATCH] re-deploy --- Dockerfile | 29 ++++++++++------------------- docker-compose.prod.yml | 11 ++++++++--- server.mjs | 3 +++ 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5736a8a..91a774f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,31 +1,22 @@ -FROM node:22-alpine AS base +# ── Install dependencies ───────────────────────────────────────────────────── +FROM node:22-alpine AS deps RUN corepack enable && corepack prepare pnpm@latest --activate WORKDIR /app - -# ── Dependencies ───────────────────────────────────────────────────────────── -FROM base AS deps COPY package.json pnpm-lock.yaml ./ COPY prisma ./prisma/ RUN pnpm install --frozen-lockfile -# ── Build static site ──────────────────────────────────────────────────────── -FROM base AS build +# ── Production ─────────────────────────────────────────────────────────────── +FROM node:22-alpine +RUN corepack enable && corepack prepare pnpm@latest --activate +WORKDIR /app +ENV NODE_ENV=production + COPY --from=deps /app/node_modules ./node_modules COPY . . RUN pnpm prisma generate -# Astro build needs DATABASE_URL at build time (passed as build arg by Coolify) -ARG DATABASE_URL -RUN pnpm build - -# ── Production ─────────────────────────────────────────────────────────────── -FROM base AS production -ENV NODE_ENV=production -COPY --from=deps /app/node_modules ./node_modules -COPY . . -COPY --from=build /app/dist ./dist -COPY --from=build /app/node_modules/.prisma ./node_modules/.prisma EXPOSE 3000 -# Migrate DB + seed if needed + start server -CMD ["sh", "-c", "pnpm prisma migrate deploy && node server.mjs"] +# Astro SSG needs the DB at build time → build happens at startup after Postgres is ready +CMD ["sh", "-c", "pnpm prisma migrate deploy && pnpm build && node server.mjs"] diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 8eff8da..b8043ff 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -3,8 +3,6 @@ services: build: context: . dockerfile: Dockerfile - args: - - DATABASE_URL=${DATABASE_URL} volumes: - static:/app/dist environment: @@ -20,6 +18,12 @@ services: depends_on: postgres: condition: service_healthy + healthcheck: + test: ["CMD", "sh", "-c", "[ -f /app/dist/index.html ] && wget -qO- http://localhost:3000/api/health || exit 1"] + interval: 10s + timeout: 5s + retries: 30 + start_period: 60s restart: unless-stopped labels: - traefik.enable=true @@ -51,7 +55,8 @@ services: - static:/usr/share/nginx/html:ro - ./docker/nginx.conf:/etc/nginx/conf.d/default.conf:ro depends_on: - - fastify + fastify: + condition: service_healthy restart: unless-stopped labels: - traefik.enable=true diff --git a/server.mjs b/server.mjs index 2dcb0ae..c326695 100644 --- a/server.mjs +++ b/server.mjs @@ -93,6 +93,9 @@ app.get('/sitemap.xml', async (_, reply) => { ) }) +// ── Health check ──────────────────────────────────────────────────────────── +app.get('/api/health', async () => ({ status: 'ok' })) + // ── Checkout Stripe ───────────────────────────────────────────────────────── app.post('/api/checkout', async (request, reply) => { const { product, email } = request.body ?? {}