From aac57c06f63ce8fb8780df5b506a16ac36dc4bc3 Mon Sep 17 00:00:00 2001
From: Charles <charles-francis.damedey@savoirfairelinux.com>
Date: Thu, 15 Jun 2023 11:46:33 -0400
Subject: [PATCH] Jenkins: check linting and run tests

GitLab: #1
Change-Id: Iaa566609f2b6e02c1521aad91739525daaf2fcde
---
 Dockerfile  |  9 +++++++--
 Jenkinsfile |  9 ++++++++-
 README.md   | 14 +++++++++++++-
 3 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index a1afbe9..e0a8481 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -5,13 +5,18 @@ COPY package*.json ./
 RUN npm install
 COPY . .
 
-# Stage 2: Final Image for running the server
+# Stage 2: Image for checking the linting
+FROM base as lint
+RUN npm install gts
+CMD ["npm", "run", "lint"]
+
+# Stage 3: Image for running the server
 FROM base as server
 EXPOSE 3000
 ENV DATA_DIRECTORY=/data
 CMD ["npm", "run", "start"]
 
-# Stage 3: Final Image for running the tests
+# Stage 4: Image for running the tests
 FROM base as test
 ENV DATA_DIRECTORY=/tests/data
 CMD ["npm", "run", "test"]
diff --git a/Jenkinsfile b/Jenkinsfile
index 14b2b55..c43c3f8 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -55,7 +55,14 @@ pipeline {
                         userRemoteConfigs: [[refspec: '${GERRIT_REFSPEC}', url: 'https://${JAMI_GERRIT_URL}/jami-plugins-store']]]
             }
         }
-
+        stage('lint') {
+            steps {
+                script {
+                    docker.build("jami-plugins-store:${env.BUILD_ID}", "--target lint .")
+                    sh "docker run -t --rm jami-plugins-store:${env.BUILD_ID}"
+                }
+            }
+        }
         stage('test') {
             steps {
                 script {
diff --git a/README.md b/README.md
index cff0f43..46c1eae 100644
--- a/README.md
+++ b/README.md
@@ -70,6 +70,8 @@ To install Docker please read this manual: https://docs.docker.com/engine/instal
 
 The Docker needs a data directory to store the plugins. You need a /data/ folder in your repo. The API will look for the plugins in this folder. This is a temporary situation until we have a database implemented.
 
+## Run the server in a docker container
+
 Build a docker image:
 
 `docker build -t server-image --target server .`
@@ -82,7 +84,7 @@ Run the docker container:
 
 To stop the container do CTRL + C in the terminal.
 
-To run tests in the docker container
+## To run tests in the docker container
 
 Build the test image:
 
@@ -92,6 +94,16 @@ Run the test image:
 
 `docker run test-image`
 
+## To check if the code has been linted correctly in the docker container
+
+Build the lint image:
+
+`docker build -t lint-image --target lint .`
+
+Run the lint image:
+
+`docker run lint-image`
+
 # Linting via pre-commit hook
 
 Set up the pre-commit hook:
-- 
GitLab