From 55f7b3f75acd3f65c9a3c8b516f62bca85142221 Mon Sep 17 00:00:00 2001 From: Kunthawat Greethong Date: Mon, 4 May 2026 21:35:21 +0700 Subject: [PATCH] Use official emdash with sed-based post-build patch Instead of cloning emdash-patch repo, clone official emdash and apply 4-line sed patch to built virtual_astro_middleware.mjs. This avoids workspace:* dependency issues that were breaking the backend. The sed patch fixes apiSuccess() wrapper mismatch for media browser and image upload in the visual editor toolbar. --- Dockerfile | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index acaf77e..509ace2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,22 +4,22 @@ RUN apk add --no-cache python3 make g++ sqlite git WORKDIR /app -# Clone full emdash monorepo (with patch applied) -RUN git clone --depth=1 https://git.moreminimore.com/kunthawat/emdash-patch-imageupload.git emdash +# 1. Clone official emdash repo +RUN git clone --depth=1 https://github.com/emdash-cms/emdash.git emdash -# Clone blog template source +# 2. Clone blog template source RUN git clone --depth=1 https://git.moreminimore.com/kunthawat/emdash-blog-template.git blog-template WORKDIR /app/emdash -# Add blog template as workspace package and install all deps +# Add blog template as workspace package RUN cp -r /app/blog-template packages/blog-template + RUN corepack enable && corepack prepare pnpm@9.0.0 --activate -# Enable hoisting so packages are accessible at top-level node_modules RUN echo "node-linker=hoisted" >> .npmrc RUN pnpm install -# Build all packages including the blog template +# Build all packages RUN cd packages/core && pnpm build RUN cd packages/auth && pnpm build RUN cd packages/blocks && pnpm install && pnpm build @@ -28,7 +28,7 @@ RUN cd packages/plugins/audit-log && pnpm build RUN cd packages/gutenberg-to-portable-text && pnpm install && pnpm build RUN cd packages/blog-template && rm -rf dist && pnpm build -# Final stage - run from emdash workspace so symlinks resolve correctly +# Final stage FROM deps WORKDIR /app/emdash @@ -41,7 +41,16 @@ COPY --from=0 /app/emdash/packages/blog-template/dist ./dist EXPOSE 4321 -# Copy and adapt entrypoint to work from /app/emdash +# Apply patch AFTER build - sed-based replacement in virtual_astro_middleware.mjs +COPY --from=0 /app/emdash/packages/core/src/visual-editing/toolbar.ts /tmp-toolbar.ts +RUN cd /app/emdash && \ + sed -i 's/var items = data\.items || \[\];/var items = (data.data \&\& data.data.items) || data.items || [];/' ./dist/server/virtual_astro_middleware.mjs && \ + sed -i 's/if (!data\.item) throw new Error("Upload failed");/if (!data.data || !data.data.item) throw new Error("Upload failed: no item returned");/' ./dist/server/virtual_astro_middleware.mjs && \ + sed -i 's/var item = data\.item;/var item = data.data.item;/' ./dist/server/virtual_astro_middleware.mjs && \ + sed -i 's/selectMediaItem(item, annotation, element, imgEl);/return selectMediaItem(item, annotation, element, imgEl);/' ./dist/server/virtual_astro_middleware.mjs && \ + echo "Patches applied" + +# Copy and adapt entrypoint COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh && \ sed -i 's|cd /app|cd /app/emdash|g' /entrypoint.sh && \ @@ -52,10 +61,10 @@ RUN chmod +x /entrypoint.sh && \ COPY --from=0 /app/emdash/packages/blog-template/seed ./seed RUN mkdir -p /app/emdash/uploads -# Copy audit-log plugin to node_modules (it's imported by virtual_astro_middleware.mjs) +# Copy audit-log plugin COPY --from=0 /app/emdash/packages/plugins/audit-log ./node_modules/@emdash-cms/plugin-audit-log -# Copy gutenberg-to-portable-text (nested in core's node_modules, needed by search) +# Copy gutenberg-to-portable-text COPY --from=0 /app/emdash/packages/core/node_modules/@emdash-cms/gutenberg-to-portable-text ./node_modules/@emdash-cms/gutenberg-to-portable-text ENTRYPOINT ["/entrypoint.sh"]