fix: Dockerfile

This commit is contained in:
Philip 2024-04-20 21:36:04 +02:00
parent 324756035a
commit 5263374549
5 changed files with 177 additions and 169 deletions

View file

@ -1,19 +1,17 @@
# Fetching the latest node-lts image on alpine linux
FROM node:lts-alpine as base
FROM node:18-alpine AS base
# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY .env .env
# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi
@ -27,12 +25,14 @@ COPY . .
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1
ENV NEXT_TELEMETRY_DISABLED 1
RUN yarn build
# If using npm comment out above and use below instead
# RUN npm run build
RUN \
if [ -f yarn.lock ]; then yarn run build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi
# Production image, copy all the files and run next
FROM base AS runner
@ -47,11 +47,14 @@ RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/.next/server ./.next/server
USER nextjs
@ -59,4 +62,6 @@ EXPOSE 3000
ENV PORT 3000
CMD ["node", "server.js"]
# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
CMD HOSTNAME="0.0.0.0" node server.js

View file

@ -1,4 +1,4 @@
const next = require('next');
const million = require("million/compiler");
/** @type {import('next').NextConfig} */
let nextConfig = {
@ -19,4 +19,10 @@ let nextConfig = {
},
};
module.exports = nextConfig;
const millionConfig = {
auto: { rsc: true },
};
nextConfig = million.next(nextConfig, millionConfig);
module.exports = nextConfig;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,159 +1,159 @@
import { skipWaiting, clientsClaim } from 'workbox-core';
import { ExpirationPlugin } from 'workbox-expiration';
import { NetworkOnly, NetworkFirst, CacheFirst, StaleWhileRevalidate } from 'workbox-strategies';
import { registerRoute, setDefaultHandler, setCatchHandler } from 'workbox-routing';
import { matchPrecache, precacheAndRoute, cleanupOutdatedCaches } from 'workbox-precaching';
// import { skipWaiting, clientsClaim } from 'workbox-core';
// import { ExpirationPlugin } from 'workbox-expiration';
// import { NetworkOnly, NetworkFirst, CacheFirst, StaleWhileRevalidate } from 'workbox-strategies';
// import { registerRoute, setDefaultHandler, setCatchHandler } from 'workbox-routing';
// import { matchPrecache, precacheAndRoute, cleanupOutdatedCaches } from 'workbox-precaching';
skipWaiting();
clientsClaim();
// skipWaiting();
// clientsClaim();
// must include following lines when using inject manifest module from workbox
// https://developers.google.com/web/tools/workbox/guides/precache-files/workbox-build#add_an_injection_point
const WB_MANIFEST = self.__WB_MANIFEST;
// Precache fallback route and image
WB_MANIFEST.push({
url: 'en/fallback',
revision: '1234567890',
});
precacheAndRoute(WB_MANIFEST);
// // must include following lines when using inject manifest module from workbox
// // https://developers.google.com/web/tools/workbox/guides/precache-files/workbox-build#add_an_injection_point
// const WB_MANIFEST = self.__WB_MANIFEST;
// // Precache fallback route and image
// WB_MANIFEST.push({
// url: 'en/fallback',
// revision: '1234567890',
// });
// precacheAndRoute(WB_MANIFEST);
cleanupOutdatedCaches();
registerRoute(
'/',
new NetworkFirst({
cacheName: 'start-url',
plugins: [
new ExpirationPlugin({
maxEntries: 1,
maxAgeSeconds: 86400,
purgeOnQuotaError: !0,
}),
],
}),
'GET'
);
registerRoute(
/\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
new StaleWhileRevalidate({
cacheName: 'static-font-assets',
plugins: [
new ExpirationPlugin({
maxEntries: 4,
maxAgeSeconds: 604800,
purgeOnQuotaError: !0,
}),
],
}),
'GET'
);
// disable image cache, so we could observe the placeholder image when offline
registerRoute(
/\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
new NetworkOnly({
cacheName: 'static-image-assets',
plugins: [
new ExpirationPlugin({
maxEntries: 64,
maxAgeSeconds: 86400,
purgeOnQuotaError: !0,
}),
],
}),
'GET'
);
registerRoute(
/\.(?:js)$/i,
new StaleWhileRevalidate({
cacheName: 'static-js-assets',
plugins: [
new ExpirationPlugin({
maxEntries: 32,
maxAgeSeconds: 86400,
purgeOnQuotaError: !0,
}),
],
}),
'GET'
);
registerRoute(
/\.(?:css|scss)$/i,
new StaleWhileRevalidate({
cacheName: 'static-style-assets',
plugins: [
new ExpirationPlugin({
maxEntries: 32,
maxAgeSeconds: 86400,
purgeOnQuotaError: !0,
}),
],
}),
'GET'
);
registerRoute(
/\.(?:json|xml|csv)$/i,
new NetworkFirst({
cacheName: 'static-data-assets',
plugins: [
new ExpirationPlugin({
maxEntries: 32,
maxAgeSeconds: 86400,
purgeOnQuotaError: !0,
}),
],
}),
'GET'
);
registerRoute(
/.*/i,
new NetworkFirst({
cacheName: 'others',
networkTimeoutSeconds: 10,
plugins: [
new ExpirationPlugin({
maxEntries: 32,
maxAgeSeconds: 86400,
purgeOnQuotaError: !0,
}),
],
}),
'GET'
);
// cleanupOutdatedCaches();
// registerRoute(
// '/',
// new NetworkFirst({
// cacheName: 'start-url',
// plugins: [
// new ExpirationPlugin({
// maxEntries: 1,
// maxAgeSeconds: 86400,
// purgeOnQuotaError: !0,
// }),
// ],
// }),
// 'GET'
// );
// registerRoute(
// /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
// new StaleWhileRevalidate({
// cacheName: 'static-font-assets',
// plugins: [
// new ExpirationPlugin({
// maxEntries: 4,
// maxAgeSeconds: 604800,
// purgeOnQuotaError: !0,
// }),
// ],
// }),
// 'GET'
// );
// // disable image cache, so we could observe the placeholder image when offline
// registerRoute(
// /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
// new NetworkOnly({
// cacheName: 'static-image-assets',
// plugins: [
// new ExpirationPlugin({
// maxEntries: 64,
// maxAgeSeconds: 86400,
// purgeOnQuotaError: !0,
// }),
// ],
// }),
// 'GET'
// );
// registerRoute(
// /\.(?:js)$/i,
// new StaleWhileRevalidate({
// cacheName: 'static-js-assets',
// plugins: [
// new ExpirationPlugin({
// maxEntries: 32,
// maxAgeSeconds: 86400,
// purgeOnQuotaError: !0,
// }),
// ],
// }),
// 'GET'
// );
// registerRoute(
// /\.(?:css|scss)$/i,
// new StaleWhileRevalidate({
// cacheName: 'static-style-assets',
// plugins: [
// new ExpirationPlugin({
// maxEntries: 32,
// maxAgeSeconds: 86400,
// purgeOnQuotaError: !0,
// }),
// ],
// }),
// 'GET'
// );
// registerRoute(
// /\.(?:json|xml|csv)$/i,
// new NetworkFirst({
// cacheName: 'static-data-assets',
// plugins: [
// new ExpirationPlugin({
// maxEntries: 32,
// maxAgeSeconds: 86400,
// purgeOnQuotaError: !0,
// }),
// ],
// }),
// 'GET'
// );
// registerRoute(
// /.*/i,
// new NetworkFirst({
// cacheName: 'others',
// networkTimeoutSeconds: 10,
// plugins: [
// new ExpirationPlugin({
// maxEntries: 32,
// maxAgeSeconds: 86400,
// purgeOnQuotaError: !0,
// }),
// ],
// }),
// 'GET'
// );
// following lines gives you control of the offline fallback strategies
// https://developers.google.com/web/tools/workbox/guides/advanced-recipes#comprehensive_fallbacks
// // following lines gives you control of the offline fallback strategies
// // https://developers.google.com/web/tools/workbox/guides/advanced-recipes#comprehensive_fallbacks
// Use a stale-while-revalidate strategy for all other requests.
setDefaultHandler(new StaleWhileRevalidate());
// // Use a stale-while-revalidate strategy for all other requests.
// setDefaultHandler(new StaleWhileRevalidate());
// This "catch" handler is triggered when any of the other routes fail to
// generate a response.
setCatchHandler(({ event }) => {
// The FALLBACK_URL entries must be added to the cache ahead of time, either
// via runtime or precaching. If they are precached, then call
// `matchPrecache(FALLBACK_URL)` (from the `workbox-precaching` package)
// to get the response from the correct cache.
//
// Use event, request, and url to figure out how to respond.
// One approach would be to use request.destination, see
// https://medium.com/dev-channel/service-worker-caching-strategies-based-on-request-types-57411dd7652c
switch (event.request.destination) {
case 'document':
// If using precached URLs:
return matchPrecache('en/fallback');
// return caches.match('/fallback')
break;
case 'image':
// If using precached URLs:
return matchPrecache('/static/images/fallback.png');
// return caches.match('/static/images/fallback.png')
break;
case 'font':
// If using precached URLs:
// return matchPrecache(FALLBACK_FONT_URL);
// return caches.match('/static/fonts/fallback.otf')
// break
default:
// If we don't have a fallback, just return an error response.
return Response.error();
}
});
// // This "catch" handler is triggered when any of the other routes fail to
// // generate a response.
// setCatchHandler(({ event }) => {
// // The FALLBACK_URL entries must be added to the cache ahead of time, either
// // via runtime or precaching. If they are precached, then call
// // `matchPrecache(FALLBACK_URL)` (from the `workbox-precaching` package)
// // to get the response from the correct cache.
// //
// // Use event, request, and url to figure out how to respond.
// // One approach would be to use request.destination, see
// // https://medium.com/dev-channel/service-worker-caching-strategies-based-on-request-types-57411dd7652c
// switch (event.request.destination) {
// case 'document':
// // If using precached URLs:
// return matchPrecache('en/fallback');
// // return caches.match('/fallback')
// break;
// case 'image':
// // If using precached URLs:
// return matchPrecache('/static/images/fallback.png');
// // return caches.match('/static/images/fallback.png')
// break;
// case 'font':
// // If using precached URLs:
// // return matchPrecache(FALLBACK_FONT_URL);
// // return caches.match('/static/fonts/fallback.otf')
// // break
// default:
// // If we don't have a fallback, just return an error response.
// return Response.error();
// }
// });