super-productivity/packages/super-sync-server/Dockerfile
Johannes Millan d32f7037a3 fix(sync): preserve own vector clock counter across full-state op resets
When a full-state op (SYNC_IMPORT/BACKUP_IMPORT) arrived from another
client, mergeRemoteOpClocks reset the local clock to a "minimal" form
but only preserved the current client's counter from the incoming op's
clock. If the current client had issued ops (e.g. GLOBAL_CONFIG) not
reflected in the incoming full-state op's clock, its counter was dropped,
causing subsequent ops to reuse the same counter value. Downstream clients
then saw these ops as EQUAL (duplicate) and skipped them silently.

Fix: take max(mergedClock[clientId], currentClock[clientId]) when
rebuilding the clock after a full-state op reset.

Also add __SP_E2E_BLOCK_WS_DOWNLOAD flag to WsTriggeredDownloadService
to allow E2E tests to block automatic WS-triggered downloads during
concurrent conflict scenarios.

Fix archive conflict test by blocking WS downloads on Client A during
the concurrent edit phase so it doesn't auto-receive B's rename via
WebSocket before archiving (restoring the intended conflict scenario).

Fix LWW singleton test to assert convergence rather than specific winner.
Fix renameTask helper to avoid Playwright/Angular re-render races.
Fix shepherd.js import paths that broke the Angular dev server build.
2026-04-01 15:41:13 +02:00

73 lines
2.8 KiB
Docker

# ---- Builder stage ----
FROM node:24-alpine AS builder
WORKDIR /repo
RUN apk add --no-cache openssl libc6-compat
# Root package + lock (for workspace install)
COPY package.json package-lock.json ./
COPY packages/shared-schema/package.json ./packages/shared-schema/
COPY packages/super-sync-server/package.json ./packages/super-sync-server/
# Install ALL dependencies for the monorepo
# Use npm ci for reproducible builds; requires compatible lockfile
RUN npm ci --ignore-scripts
# Copy source code
COPY packages/shared-schema/ ./packages/shared-schema/
COPY packages/super-sync-server/ ./packages/super-sync-server/
# Build shared-schema
WORKDIR /repo/packages/shared-schema
RUN npm run build
# Pack shared-schema to tgz for installation in production
RUN npm pack
# Build super-sync-server
WORKDIR /repo/packages/super-sync-server
RUN npx prisma generate
RUN rm -rf dist && npm run build
# ---- Runtime stage ----
FROM node:24-alpine AS production
# System deps for Prisma & healthcheck + create user BEFORE copying files
RUN apk add --no-cache openssl libc6-compat wget && \
addgroup -g 1001 -S nodejs && \
adduser -S supersync -u 1001 -G nodejs && \
mkdir -p /app/data && chown supersync:nodejs /app /app/data
WORKDIR /app
# Copy built artifacts from builder (note: tsconfig rootDir is "." so structure is dist/src/ and dist/scripts/)
COPY --from=builder --chown=supersync:nodejs /repo/packages/super-sync-server/dist ./dist
COPY --from=builder --chown=supersync:nodejs /repo/packages/super-sync-server/public ./public
COPY --from=builder --chown=supersync:nodejs /repo/packages/super-sync-server/prisma ./prisma
COPY --from=builder --chown=supersync:nodejs /repo/packages/super-sync-server/scripts ./scripts
COPY --from=builder --chown=supersync:nodejs /repo/packages/super-sync-server/src ./src
COPY --from=builder --chown=supersync:nodejs /repo/packages/super-sync-server/package.json ./package.json
COPY --from=builder --chown=supersync:nodejs /repo/packages/shared-schema/sp-shared-schema-*.tgz ./shared-schema.tgz
# Install dependencies and generate Prisma client in single layer
# Note: prisma CLI installed explicitly for runtime migrate deploy
# IMPORTANT: prisma version must match @prisma/client in package.json
RUN npm install ./shared-schema.tgz --ignore-scripts && \
npm install --ignore-scripts --omit=dev && \
npm install prisma@5.22.0 --ignore-scripts && \
npx prisma generate && \
rm -f shared-schema.tgz && \
npm cache clean --force
USER supersync
EXPOSE 1900
ENV NODE_ENV=production
ENV PORT=1900
ENV DATA_DIR=/app/data
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:${PORT}/health || exit 1
CMD ["sh", "-c", "npx prisma migrate deploy && node dist/src/index.js"]