Skip to content

Commit

Permalink
persist ISR cache between containers
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Jul 30, 2024
1 parent 4243980 commit 5af232f
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,40 @@ COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static

CMD ["node", "server.js"]
RUN <<EOT
# Mount "/app/.next" to a persistent volume, to persist ISR cache between containers
set -eux
mkdir /data
mv .next /data

cat << 'EOF' > entrypoint.sh
set -e
dst=/app/.next
src=/data/.next
dst_id_file="$dst/BUILD_ID"
src_id_file="$src/BUILD_ID"

img_build_id="$(cat "$src_id_file")"
if [ -f "$dst_id_file" ]; then
old_build_id="$(cat "$dst_id_file")"
else
old_build_id="<none>"
fi

if [ "$img_build_id" != "$old_build_id" ]; then
echo "[INIT] Build ID changed, recreating .next files"
echo "[INIT] Existing build ID at $dst_id_file: $old_build_id"
echo "[INIT] Image build ID: $img_build_id"

rm -rf "$dst/*"
cp -rp "$src/*" "$dst"
else
echo "[INIT] Build ID unchanged, reusing existing .next files"
echo "[INIT] Build ID: $img_build_id"
fi

exec node server.js
EOF
EOT

CMD ["entrypoint.sh"]

0 comments on commit 5af232f

Please sign in to comment.