Przeglądaj źródła

feat: leverage next standalone output for smaller image size

Nicolas Meienberger 2 lat temu
rodzic
commit
84ceb52088

+ 5 - 2
.dockerignore

@@ -5,5 +5,8 @@
 node_modules
 .next
 dist/
-**/dist/
-**/next/
+
+# all docker-compose files
+docker-compose*.yml
+Dockerfile*
+.dockerignore

+ 8 - 8
Dockerfile

@@ -1,4 +1,4 @@
-FROM node:18 AS build
+FROM node:18 AS builder
 
 RUN npm install node-gyp -g
 
@@ -35,13 +35,13 @@ WORKDIR /api
 COPY ./packages/system-api/package*.json /api/
 RUN npm install --omit=dev
 
-WORKDIR /dashboard
-COPY ./packages/dashboard/package*.json /dashboard/
-RUN npm install --omit=dev
-
-COPY --from=build /api/dist /api/dist
+COPY --from=builder /api/dist /api/dist
 
-COPY --from=build /dashboard/.next /dashboard/.next
-COPY ./packages/dashboard /dashboard
+WORKDIR /dashboard
+COPY --from=builder /dashboard/next.config.js ./
+COPY --from=builder /dashboard/public ./public
+COPY --from=builder /dashboard/package.json ./package.json
+COPY --from=builder --chown=node:node /dashboard/.next/standalone ./
+COPY --from=builder --chown=node:node /dashboard/.next/static ./.next/static
 
 WORKDIR /

+ 1 - 1
docker-compose.rc.yml

@@ -85,7 +85,7 @@ services:
 
   dashboard:
     image: meienberger/runtipi:rc-${TIPI_VERSION}
-    command: /bin/sh -c "cd /dashboard && npm run start"
+    command: /bin/sh -c "cd /dashboard && node server.js"
     container_name: dashboard
     networks:
       - tipi_main_network

+ 1 - 1
docker-compose.yml

@@ -85,7 +85,7 @@ services:
 
   dashboard:
     image: meienberger/runtipi:${TIPI_VERSION}
-    command: /bin/sh -c "cd /dashboard && npm run start"
+    command: /bin/sh -c "cd /dashboard && node server.js"
     restart: unless-stopped
     container_name: dashboard
     networks:

+ 1 - 2
packages/dashboard/next.config.js

@@ -1,7 +1,6 @@
 /** @type {import('next').NextConfig} */
-const { INTERNAL_IP, DOMAIN, NGINX_PORT } = process.env;
-
 const nextConfig = {
+  output: 'standalone',
   webpackDevMiddleware: (config) => {
     config.watchOptions = {
       poll: 1000,

+ 2 - 2
packages/dashboard/package.json

@@ -1,6 +1,6 @@
 {
   "name": "dashboard",
-  "version": "0.7.0",
+  "version": "0.7.1",
   "private": true,
   "scripts": {
     "test": "jest --colors",
@@ -22,7 +22,7 @@
     "framer-motion": "^6",
     "graphql": "^15.8.0",
     "graphql-tag": "^2.12.6",
-    "next": "12.1.6",
+    "next": "12.3.1",
     "react": "18.1.0",
     "react-dom": "18.1.0",
     "react-final-form": "^6.5.9",