From 1cc2065b2fcab8eee8a8ac0bc695e7390da55114 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tadeusz=20Miesi=C4=85c?= <tadeusz.miesiac@gmail.com>
Date: Tue, 19 Sep 2023 11:29:25 +0200
Subject: [PATCH] chore(docker setup and ci): docker setup nad ci

---
 .gitlab-ci.yml | 44 ++++++++------------------------------------
 .nvmrc         |  1 +
 Dockerfile     | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 56 insertions(+), 36 deletions(-)
 create mode 100644 .nvmrc
 create mode 100644 Dockerfile

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 3fbf0b5e..23cb7ee2 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -16,41 +16,13 @@
 # This specific template is located at:
 # https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml
 
-stages:          # List of stages for jobs, and their order of execution
-  - lint
-  - build
+stages:
+  - prerequisite
   - test
+  - build
   - deploy
-
-lint:commit:
-  stage: lint
-  script:
-    - npm install
-    - echo "${CI_COMMIT_MESSAGE}" | npx commitlint
-
-build-job:       # This job runs in the build stage, which runs first.
-  stage: build
-  script:
-    - echo "Compiling the code..."
-    - echo "Compile complete."
-
-unit-test-job:   # This job runs in the test stage.
-  stage: test    # It only starts when the job in the build stage completes successfully.
-  script:
-    - echo "Running unit tests... This will take about 60 seconds."
-    - sleep 60
-    - echo "Code coverage is 90%"
-
-lint-test-job:   # This job also runs in the test stage.
-  stage: test    # It can run at the same time as unit-test-job (in parallel).
-  script:
-    - echo "Linting code... This will take about 10 seconds."
-    - sleep 10
-    - echo "No lint issues found."
-
-deploy-job:      # This job runs in the deploy stage.
-  stage: deploy  # It only runs when *both* jobs in the test stage complete successfully.
-  environment: production
-  script:
-    - echo "Deploying application..."
-    - echo "Application successfully deployed."
+cache:
+  paths:
+    - ~/.cache
+variables:
+  DOCKER_DRIVER: overlay2
diff --git a/.nvmrc b/.nvmrc
new file mode 100644
index 00000000..19c7bdba
--- /dev/null
+++ b/.nvmrc
@@ -0,0 +1 @@
+16
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 00000000..218a7ef9
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,47 @@
+# ---- 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 ./
+
+#
+# ---- 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 ----
+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
+
+# ---- 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
-- 
GitLab