Spaces:
Running
Running
perf: move pnpm install before next.config.js patches to preserve cache
Browse filesAny change to the patch RUN command previously busted the pnpm install
cache layer, forcing a full reinstall (~3-4 min) on every push. Moving
install first means patch changes only invalidate the patch + build layers.
Also consolidates the two patch RUN commands into one to reduce layer count.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Dockerfile +19 -24
Dockerfile
CHANGED
|
@@ -45,44 +45,39 @@ RUN npm install -g pnpm@10.6.1
|
|
| 45 |
# Pinned to v2.11.3 β last release before Temporal became a hard requirement.
|
| 46 |
RUN git clone --depth=1 --branch v2.11.3 https://github.com/gitroomhq/postiz-app.git .
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
# 1. basePath/assetPrefix=/app β Postiz UI at /app; HuggingPost dashboard owns /
|
| 51 |
# 2. productionBrowserSourceMaps: false β smaller build output
|
| 52 |
# 3. Sentry sourcemap plugin disabled β no network calls during build
|
| 53 |
-
# 4. swcMinify: false β Terser (pure JS) instead of native SWC binary
|
| 54 |
-
# avoids extra RSS outside the V8 heap
|
| 55 |
# 5. experimental.cpus=1 + workerThreads=false β single-thread webpack
|
|
|
|
| 56 |
RUN sed -i "s|const nextConfig = {|const nextConfig = {\n basePath: '/app',\n assetPrefix: '/app',\n trailingSlash: true,\n swcMinify: false,|" apps/frontend/next.config.js \
|
| 57 |
&& sed -i "s|productionBrowserSourceMaps: true|productionBrowserSourceMaps: false|" apps/frontend/next.config.js \
|
| 58 |
&& sed -i "s|disable: false,|disable: true,|" apps/frontend/next.config.js \
|
| 59 |
&& sed -i "s|experimental: {|experimental: {\n cpus: 1,\n workerThreads: false,|" apps/frontend/next.config.js \
|
|
|
|
|
|
|
|
|
|
| 60 |
&& grep -q "basePath: '/app'" apps/frontend/next.config.js \
|
| 61 |
&& grep -q "trailingSlash: true" apps/frontend/next.config.js \
|
| 62 |
&& grep -q "productionBrowserSourceMaps: false" apps/frontend/next.config.js \
|
| 63 |
&& grep -q "swcMinify: false" apps/frontend/next.config.js \
|
| 64 |
&& grep -q "cpus: 1" apps/frontend/next.config.js \
|
| 65 |
|| (echo "PATCH FAILED β next.config.js shape changed upstream"; exit 1)
|
| 66 |
-
# Patch: disable Next.js image optimisation.
|
| 67 |
-
# With basePath="/app", the _next/image optimizer fetches static files from
|
| 68 |
-
# Next.js's internal URL without the basePath prefix, causing 400 errors.
|
| 69 |
-
# unoptimized:true makes <Image> render as plain <img> tags; the browser
|
| 70 |
-
# fetches /app/auth/avatars/β¦ which routes correctly through nginx.
|
| 71 |
-
# If Postiz already has an images:{} block, inject unoptimized inside it;
|
| 72 |
-
# otherwise add a new images block at the top of nextConfig.
|
| 73 |
-
RUN grep -q 'images:' apps/frontend/next.config.js \
|
| 74 |
-
&& sed -i 's|images: {|images: {\n unoptimized: true,|' apps/frontend/next.config.js \
|
| 75 |
-
|| sed -i "s|const nextConfig = {|const nextConfig = {\n images: { unoptimized: true },|" apps/frontend/next.config.js
|
| 76 |
-
|
| 77 |
-
ENV SENTRY_DSN="" \
|
| 78 |
-
SENTRY_AUTH_TOKEN="" \
|
| 79 |
-
SENTRY_ORG="" \
|
| 80 |
-
SENTRY_PROJECT="" \
|
| 81 |
-
NEXT_PUBLIC_SENTRY_DSN="" \
|
| 82 |
-
NEXT_TELEMETRY_DISABLED=1 \
|
| 83 |
-
NEXT_PRIVATE_SKIP_SIZE_MINIMIZATION=true
|
| 84 |
-
|
| 85 |
-
RUN pnpm install --frozen-lockfile=false
|
| 86 |
|
| 87 |
# Build server-side apps. Sequential + 3 GB heap each.
|
| 88 |
# Frontend is NOT built here β see start.sh.
|
|
|
|
| 45 |
# Pinned to v2.11.3 β last release before Temporal became a hard requirement.
|
| 46 |
RUN git clone --depth=1 --branch v2.11.3 https://github.com/gitroomhq/postiz-app.git .
|
| 47 |
|
| 48 |
+
ENV SENTRY_DSN="" \
|
| 49 |
+
SENTRY_AUTH_TOKEN="" \
|
| 50 |
+
SENTRY_ORG="" \
|
| 51 |
+
SENTRY_PROJECT="" \
|
| 52 |
+
NEXT_PUBLIC_SENTRY_DSN="" \
|
| 53 |
+
NEXT_TELEMETRY_DISABLED=1 \
|
| 54 |
+
NEXT_PRIVATE_SKIP_SIZE_MINIMIZATION=true
|
| 55 |
+
|
| 56 |
+
# Install deps BEFORE patching so the install layer is cached independently.
|
| 57 |
+
# Patches are sed commands on JS files β they don't affect node_modules.
|
| 58 |
+
# Changing patches won't bust the pnpm install cache layer.
|
| 59 |
+
RUN pnpm install --frozen-lockfile=false
|
| 60 |
+
|
| 61 |
+
# Patch Next.js config (after install β see above).
|
| 62 |
# 1. basePath/assetPrefix=/app β Postiz UI at /app; HuggingPost dashboard owns /
|
| 63 |
# 2. productionBrowserSourceMaps: false β smaller build output
|
| 64 |
# 3. Sentry sourcemap plugin disabled β no network calls during build
|
| 65 |
+
# 4. swcMinify: false β Terser (pure JS) instead of native SWC binary
|
|
|
|
| 66 |
# 5. experimental.cpus=1 + workerThreads=false β single-thread webpack
|
| 67 |
+
# 6. images.unoptimized: true β skip _next/image optimizer (fails with basePath)
|
| 68 |
RUN sed -i "s|const nextConfig = {|const nextConfig = {\n basePath: '/app',\n assetPrefix: '/app',\n trailingSlash: true,\n swcMinify: false,|" apps/frontend/next.config.js \
|
| 69 |
&& sed -i "s|productionBrowserSourceMaps: true|productionBrowserSourceMaps: false|" apps/frontend/next.config.js \
|
| 70 |
&& sed -i "s|disable: false,|disable: true,|" apps/frontend/next.config.js \
|
| 71 |
&& sed -i "s|experimental: {|experimental: {\n cpus: 1,\n workerThreads: false,|" apps/frontend/next.config.js \
|
| 72 |
+
&& (grep -q 'images:' apps/frontend/next.config.js \
|
| 73 |
+
&& sed -i 's|images: {|images: {\n unoptimized: true,|' apps/frontend/next.config.js \
|
| 74 |
+
|| sed -i "s|const nextConfig = {|const nextConfig = {\n images: { unoptimized: true },|" apps/frontend/next.config.js) \
|
| 75 |
&& grep -q "basePath: '/app'" apps/frontend/next.config.js \
|
| 76 |
&& grep -q "trailingSlash: true" apps/frontend/next.config.js \
|
| 77 |
&& grep -q "productionBrowserSourceMaps: false" apps/frontend/next.config.js \
|
| 78 |
&& grep -q "swcMinify: false" apps/frontend/next.config.js \
|
| 79 |
&& grep -q "cpus: 1" apps/frontend/next.config.js \
|
| 80 |
|| (echo "PATCH FAILED β next.config.js shape changed upstream"; exit 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
# Build server-side apps. Sequential + 3 GB heap each.
|
| 83 |
# Frontend is NOT built here β see start.sh.
|