From e381b9fee85ac20700b963acd6fc56dfe48de0d9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tadeusz=20Miesi=C4=85c?= <tadeusz.miesiac@gmail.com>
Date: Tue, 19 Sep 2023 14:24:47 +0200
Subject: [PATCH] chore(docker setup): docker setup for next.js

---
 .dockerignore     |   5 ++
 .gitignore        |   5 ++
 Dockerfile        |  77 +++++++++++++----------------
 package-lock.json | 121 ----------------------------------------------
 4 files changed, 44 insertions(+), 164 deletions(-)
 create mode 100644 .dockerignore

diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 00000000..2119e44c
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,5 @@
+.git
+.gitignore
+.gitlab-ci.yml
+README.md
+node_modules
diff --git a/.gitignore b/.gitignore
index 3c3629e6..958eeb8e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,6 @@
 node_modules
+.next
+.next/
+
+# testing
+/coverage
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
index 218a7ef9..187573d2 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,47 +1,38 @@
 # ---- Base Node ----
-FROM node:16.17.0-alpine AS base
-# install node
-RUN apk add --no-cache nodejs-current npm tini yarn
-# set working directory
-WORKDIR /code
-# Set tini as entrypoint
-ENTRYPOINT ["/sbin/tini", "--"]
-# copy project file
-COPY package.json package-lock.json yarn.lock next.config.js ./
+ARG BASE_IMAGE=node:16.17.0-alpine
 
-#
-# ---- Dependencies ----
-FROM base AS dependencies
-# install git
-RUN apk add --no-cache git
-# install node packages
-RUN npm install --only=production
-# copy production node_modules aside
-RUN cp -R node_modules prod_node_modules
-# install ALL node_modules, including 'devDependencies'
-RUN npm install
+# ================================================================
+# builder stage
+# ================================================================
+FROM $BASE_IMAGE as builder
+ENV NODE_ENV=test
+ENV NEXT_TELEMETRY_DISABLED=1
+RUN apk add --no-cache bash git
+WORKDIR /app
+COPY ./package.json ./
+COPY ./package-lock.json ./
+RUN CI=true npm ci
+COPY . ./
+RUN NODE_ENV=production npm run build
 
-#
-# ---- Builder ----
-FROM base AS builder
-# copy production node_modules
-COPY --from=dependencies /code/node_modules ./node_modules
-# copy app sources
-COPY . .
-# build app
-RUN npm build
+# ================================================================
+# cypress stage
+# ================================================================
+#FROM cypress/base:14.16.0 as cypress
+#WORKDIR /app
+# copy cypress from the builder image
+#COPY --from=builder /root/.cache /root/.cache/
+#COPY --from=builder /app ./
+#ENV NODE_ENV=test
+#ENV NEXT_TELEMETRY_DISABLED=1
 
-# ---- Release ----
-FROM base AS release
-
-# expose port and define CMD
-EXPOSE 5000
-
-# copy production node_modules
-COPY --from=dependencies /code/prod_node_modules ./node_modules
-
-# copy build files
-COPY --from=builder /code/static ./static
-COPY --from=builder /code/assets ./assets
-COPY --from=builder /code/.next ./.next
-CMD yarn run start -H 0.0.0.0 -p 5000
\ No newline at end of file
+# ================================================================
+# final deploy stage
+# ================================================================
+FROM $BASE_IMAGE
+WORKDIR /app
+COPY --from=builder /app ./
+ENV NODE_ENV=production
+ENV NEXT_TELEMETRY_DISABLED=1
+EXPOSE 3000
+CMD ["npm", "start"]
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index 00cb5e82..7cfb7ae6 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -25,7 +25,6 @@
         "@commitlint/config-conventional": "^17.7.0",
         "@testing-library/jest-dom": "^6.1.3",
         "@testing-library/react": "^14.0.0",
-        "@types/jest": "^29.5.5",
         "@typescript-eslint/eslint-plugin": "^6.7.0",
         "@typescript-eslint/parser": "^6.7.0",
         "cz-conventional-changelog": "^3.3.0",
@@ -1882,21 +1881,6 @@
         "url": "https://github.com/sponsors/isaacs"
       }
     },
-    "node_modules/@next/swc-darwin-arm64": {
-      "version": "13.4.19",
-      "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.4.19.tgz",
-      "integrity": "sha512-vv1qrjXeGbuF2mOkhkdxMDtv9np7W4mcBtaDnHU+yJG+bBwa6rYsYSCI/9Xm5+TuF5SbZbrWO6G1NfTh1TMjvQ==",
-      "cpu": [
-        "arm64"
-      ],
-      "optional": true,
-      "os": [
-        "darwin"
-      ],
-      "engines": {
-        "node": ">= 10"
-      }
-    },
     "node_modules/@next/swc-darwin-x64": {
       "version": "13.4.19",
       "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-13.4.19.tgz",
@@ -1912,111 +1896,6 @@
         "node": ">= 10"
       }
     },
-    "node_modules/@next/swc-linux-arm64-gnu": {
-      "version": "13.4.19",
-      "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.4.19.tgz",
-      "integrity": "sha512-vdlnIlaAEh6H+G6HrKZB9c2zJKnpPVKnA6LBwjwT2BTjxI7e0Hx30+FoWCgi50e+YO49p6oPOtesP9mXDRiiUg==",
-      "cpu": [
-        "arm64"
-      ],
-      "optional": true,
-      "os": [
-        "linux"
-      ],
-      "engines": {
-        "node": ">= 10"
-      }
-    },
-    "node_modules/@next/swc-linux-arm64-musl": {
-      "version": "13.4.19",
-      "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.4.19.tgz",
-      "integrity": "sha512-aU0HkH2XPgxqrbNRBFb3si9Ahu/CpaR5RPmN2s9GiM9qJCiBBlZtRTiEca+DC+xRPyCThTtWYgxjWHgU7ZkyvA==",
-      "cpu": [
-        "arm64"
-      ],
-      "optional": true,
-      "os": [
-        "linux"
-      ],
-      "engines": {
-        "node": ">= 10"
-      }
-    },
-    "node_modules/@next/swc-linux-x64-gnu": {
-      "version": "13.4.19",
-      "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.4.19.tgz",
-      "integrity": "sha512-htwOEagMa/CXNykFFeAHHvMJeqZfNQEoQvHfsA4wgg5QqGNqD5soeCer4oGlCol6NGUxknrQO6VEustcv+Md+g==",
-      "cpu": [
-        "x64"
-      ],
-      "optional": true,
-      "os": [
-        "linux"
-      ],
-      "engines": {
-        "node": ">= 10"
-      }
-    },
-    "node_modules/@next/swc-linux-x64-musl": {
-      "version": "13.4.19",
-      "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.4.19.tgz",
-      "integrity": "sha512-4Gj4vvtbK1JH8ApWTT214b3GwUh9EKKQjY41hH/t+u55Knxi/0wesMzwQRhppK6Ddalhu0TEttbiJ+wRcoEj5Q==",
-      "cpu": [
-        "x64"
-      ],
-      "optional": true,
-      "os": [
-        "linux"
-      ],
-      "engines": {
-        "node": ">= 10"
-      }
-    },
-    "node_modules/@next/swc-win32-arm64-msvc": {
-      "version": "13.4.19",
-      "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.4.19.tgz",
-      "integrity": "sha512-bUfDevQK4NsIAHXs3/JNgnvEY+LRyneDN788W2NYiRIIzmILjba7LaQTfihuFawZDhRtkYCv3JDC3B4TwnmRJw==",
-      "cpu": [
-        "arm64"
-      ],
-      "optional": true,
-      "os": [
-        "win32"
-      ],
-      "engines": {
-        "node": ">= 10"
-      }
-    },
-    "node_modules/@next/swc-win32-ia32-msvc": {
-      "version": "13.4.19",
-      "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.4.19.tgz",
-      "integrity": "sha512-Y5kikILFAr81LYIFaw6j/NrOtmiM4Sf3GtOc0pn50ez2GCkr+oejYuKGcwAwq3jiTKuzF6OF4iT2INPoxRycEA==",
-      "cpu": [
-        "ia32"
-      ],
-      "optional": true,
-      "os": [
-        "win32"
-      ],
-      "engines": {
-        "node": ">= 10"
-      }
-    },
-    "node_modules/@next/swc-win32-x64-msvc": {
-      "version": "13.4.19",
-      "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.4.19.tgz",
-      "integrity": "sha512-YzA78jBDXMYiINdPdJJwGgPNT3YqBNNGhsthsDoWHL9p24tEJn9ViQf/ZqTbwSpX/RrkPupLfuuTH2sf73JBAw==",
-      "cpu": [
-        "x64"
-      ],
-      "optional": true,
-      "os": [
-        "win32"
-      ],
-      "engines": {
-        "node": ">= 10"
-      }
-    },
     "node_modules/@nodelib/fs.scandir": {
       "version": "2.1.5",
       "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
-- 
GitLab